Changing Automatically Detected Types of DocumentTable Columns
Changing Automatically Detected Types of DocumentTable Columns
Leave feedback
On this page
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.
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
constjava=require('java');constgroupdocs=require('@groupdocs/groupdocs.assembly');// Set table column names to be extracted from the document.
constoptions=newgroupdocs.DocumentTableOptions();options.setFirstRowContainsColumnNames(true);consttable=newgroupdocs.DocumentTable('Managers Data.docx',1,options);// NOTE: For non-spreadsheet documents, the type of a document table column is always string by default.
constcolumn=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.
constassembler=newgroupdocs.DocumentAssembler();assembler.assembleDocument('Changing Document Table Column Type.pptx','out.pptx',newgroupdocs.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.