Changing Automatically Detected Types of DocumentTable Columns

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Assembly MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-assembly -- dnx GroupDocs.Assembly.Mcp --yes
Folders, licensing and more →

Changing Automatically Detected Types

The type of a DocumentTable column is detected automatically when the table is loaded:

  • For spreadsheet documents, the type is detected from cell values (for example, double when all cells of a column are numeric).
  • For other documents (word processing and presentation), the type of a column is always java.lang.String by default.

DocumentTableColumn.getType() returns the column type as a Java Class, and DocumentTableColumn.setType() changes it. For example, changing the type of a column with numeric text to double enables arithmetic operations and aggregates, such as sum, on values of the column in templates.

In JavaScript, obtain Java Class objects through the java package. For primitive types, use the TYPE field of the wrapper class, for example java.import('java.lang.Double').TYPE for double.

Download

Data Source Document

Template

The template contains a table with a data row and a total row. The data row cells contain:

<<foreach [in Managers]>><<[Manager]>>
<<[Total_Contract_Price]>><</foreach>>

The total row contains:

<<[Managers.sum(m => m.Total_Contract_Price)]>>

Changing Document Table Column Type

const java = require('java');
const groupdocs = require('@groupdocs/groupdocs.assembly');

// Set table column names to be extracted from the document.
const options = new groupdocs.DocumentTableOptions();
options.setFirstRowContainsColumnNames(true);

const table = new groupdocs.DocumentTable('Managers Data.docx', 1, options);

// NOTE: For non-spreadsheet documents, the type of a document table column is always string by default.
const column = table.getColumns().get('Total_Contract_Price');
console.log(column.getType().getName());   // java.lang.String

// Change the column's type to double, thus enabling arithmetic operations
// on values of the column, such as summing in templates.
column.setType(java.import('java.lang.Double').TYPE);
console.log(column.getType().getName());   // double

// Pass DocumentTable as a data source.
const assembler = new groupdocs.DocumentAssembler();
assembler.assembleDocument('Changing Document Table Column Type.pptx', 'out.pptx',
    new groupdocs.DataSourceInfo(table, 'Managers'));

process.exit(0);

The report lists five managers with their total contract prices, followed by the total of 5700000.0.

Note
In evaluation mode, text read from PPTX templates is truncated, which can make template tags invalid. Apply a license to process presentations without this limitation, or use a template of another format. See Evaluation Limitations and Licensing.

See Also