GroupDocs.Assembly for Node.js via Java can use a table from another document as a data source. The following classes are used:
Class
Purpose
DocumentTable
A single table loaded from a spreadsheet worksheet, a word processing table or a presentation table.
DocumentTableOptions
Options for loading a table: whether the first row contains column names, and the row and column index limits.
DocumentTableSet
All tables of a document loaded as a single operation, with optional relations between them.
A DocumentTable is passed to the engine like any other data source and is treated as a list of rows in templates:
constgroupdocs=require('@groupdocs/groupdocs.assembly');constoptions=newgroupdocs.DocumentTableOptions();options.setFirstRowContainsColumnNames(true);// Load the first table (worksheet) of the document.
consttable=newgroupdocs.DocumentTable('Contracts Data.xlsx',0,options);constassembler=newgroupdocs.DocumentAssembler();assembler.assembleDocument('template.docx','report.docx',newgroupdocs.DataSourceInfo(table,'contracts'));process.exit(0);
Key points:
The second constructor argument is the zero-based index of the table in the document (for spreadsheets, the index of the worksheet).
When setFirstRowContainsColumnNames(true) is not set, the first row is treated as data and default column names are used: A, B, C, … for spreadsheets and Column1, Column2, … for other documents.
Spaces in column names are replaced with underscores, for example Contract Price becomes Contract_Price.