Using Documents as Data Source

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 →

GroupDocs.Assembly for Node.js via Java can use a table from another document as a data source. The following classes are used:

ClassPurpose
DocumentTableA single table loaded from a spreadsheet worksheet, a word processing table or a presentation table.
DocumentTableOptionsOptions for loading a table: whether the first row contains column names, and the row and column index limits.
DocumentTableSetAll 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:

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

const options = new groupdocs.DocumentTableOptions();
options.setFirstRowContainsColumnNames(true);

// Load the first table (worksheet) of the document.
const table = new groupdocs.DocumentTable('Contracts Data.xlsx', 0, options);

const assembler = new groupdocs.DocumentAssembler();
assembler.assembleDocument('template.docx', 'report.docx',
    new groupdocs.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.
  • For spreadsheets, a column type is detected from cell values (for example, double when all cells are numeric). For other documents, columns are java.lang.String by default. See Changing Automatically Detected Types of DocumentTable Columns.
  • setMinRowIndex, setMaxRowIndex, setMinColumnIndex and setMaxColumnIndex of DocumentTableOptions limit the loaded range.
  • DocumentTable and DocumentTableSet also have constructors that accept a Java InputStream instead of a file path.

Articles in this section