1. GroupDocs Documentation
  2. /
  3. GroupDocs.Assembly Product Family
  4. /
  5. GroupDocs.Assembly for .NET
  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

Define Relations Between Document Table Instances

API provides ability to define relations between DocumentTable instances loaded from a single document. The following classes of the GroupDocs.Assembly.Data namespace have been added:

Moreover, the Relations property of the GroupDocs.Assembly.Data.DocumentTableSet class has been added.

Data Source Document

Template

Using Document Table Relations

Note
The code uses some of the objects defined in: The Business Layer
//For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
//setting up output document
const string outDocument = "Word Reports/document relations output.docx";
//set up path for the related tables data source
string relatedTablesDataSource = CommonUtilities.GetDataSourceDocument("Excel DataSource/" + relatedTables);
//set up path for the template file
string templateFile = CommonUtilities.GetSourceDocument("Word Templates/" + docTableRelations);
// Set table column names to be extracted from the document.
DocumentTableSet tableSet = new DocumentTableSet(relatedTablesDataSource, new ColumnNameExtractingDocumentTableLoadHandler());
// Define relations between tables.
// NOTE: For Spreadsheet documents, table names are extracted from sheet names.
tableSet.Relations.Add(
tableSet.Tables["CLIENT"].Columns["ID"],
tableSet.Tables["CONTRACT"].Columns["CLIENT_ID"]);
tableSet.Relations.Add(
tableSet.Tables["MANAGER"].Columns["ID"],
tableSet.Tables["CONTRACT"].Columns["MANAGER_ID"]);
// Pass DocumentTableSet as a data source.
DocumentAssembler assembler = new DocumentAssembler();
assembler.AssembleDocument(templateFile, CommonUtilities.SetDestinationDocument(outDocument), new DataSourceInfo(tableSet));

ColumnNameExtractingDocumentTableLoadHandler

//For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-.NET
public class ColumnNameExtractingDocumentTableLoadHandler : IDocumentTableLoadHandler
{
public void Handle(DocumentTableLoadArgs args)
{
args.Options = new DocumentTableOptions();
args.Options.FirstRowContainsColumnNames = true;
}
}
Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.