1. GroupDocs Documentation
  2. /
  3. GroupDocs.Assembly Product Family
  4. /
  5. GroupDocs.Assembly for Node.js
  6. /
  7. Developer Guide
  8. /
  9. Advanced Usage
  10. /
  11. Defining Relations Between DocumentTable Instances Loaded from a Single Document

Defining Relations Between DocumentTable Instances Loaded from a Single Document

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 →

Relations can be defined between DocumentTable instances loaded from a single document into a DocumentTableSet. DocumentTableSet.getRelations() returns a DocumentTableRelationCollection; its add(parentColumn, childColumn) method creates a DocumentTableRelation between a column of a parent table and a column of a child table.

Once a relation is defined, a template can navigate from a child row to the related parent row by the parent table name (for example, Manager.Name), and from a parent row to its child rows.

Download

Data Source Document

The workbook contains three worksheets:

WorksheetColumns
MANAGERID, NAME
CLIENTID, NAME
CONTRACTID, CLIENT_ID, MANAGER_ID, PRICE

Template

The template contains a three-column table. The cells of its data row contain:

<<foreach [in Contract]>><<[Manager.Name]>>
<<[Client.Name]>>
<<[Price]>><</foreach>>

Using Document Table Relations

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

// Extract column names from the first row of every table.
const columnNameExtractingDocumentTableLoadHandler = java.newProxy('com.groupdocs.assembly.IDocumentTableLoadHandler', {
    handle: function (args) {
        args.setOptions(new groupdocs.DocumentTableOptions());
        args.getOptions().setFirstRowContainsColumnNames(true);
    }
});

const tableSet = new groupdocs.DocumentTableSet('Related Tables Data.xlsx',
    columnNameExtractingDocumentTableLoadHandler);

// Define relations between tables.
// NOTE: For spreadsheet documents, table names are extracted from worksheet names.
const tables = tableSet.getTables();
tableSet.getRelations().add(
    tables.get('CLIENT').getColumns().get('ID'),
    tables.get('CONTRACT').getColumns().get('CLIENT_ID'));
tableSet.getRelations().add(
    tables.get('MANAGER').getColumns().get('ID'),
    tables.get('CONTRACT').getColumns().get('MANAGER_ID'));

// Pass DocumentTableSet as a data source.
const assembler = new groupdocs.DocumentAssembler();
assembler.assembleDocument('Using Document Table Relations.docx', 'out.docx',
    new groupdocs.DataSourceInfo(tableSet));

process.exit(0);

The report lists every contract with its manager name, client name and price, for example:

ManagerClientContract Price
John SmithA Company1200000.0
John SmithB Ltd.750000.0
Tony AndersonE Corp.650000.0

Table and column names in template expressions are case-insensitive, so Contract, Manager.Name and Price match the CONTRACT table and its NAME and PRICE columns.

See Also