1. GroupDocs Documentation
  2. /
  3. GroupDocs.Assembly Product Family
  4. /
  5. GroupDocs.Assembly for Java
  6. /
  7. Developer Guide
  8. /
  9. Advanced Usage
  10. /
  11. Loading Multiple DocumentTable Objects from a Single File as a Single Operation

Loading Multiple DocumentTable Objects from a Single File as a Single Operation

Note
The code uses some of the objects defined in The Business Layer.

Loading Multiple DocumentTable Objects

API provides the ability to load multiple DocumentTable objects from a single file as a single operation. Following classes and interfaces of the GroupDocs.Assembly.Data namespace have been added:

  • DocumentTableSet
  • DocumentTableCollection
  • IDocumentTableLoadHandler
  • DocumentTableLoadArgs.

Moreover, following properties of the GroupDocs.Assembly.Data.DocumentTable class have been added:

  • Name
  • IndexInDocument

Download

Data Source Document

Template

Loading DocumentTableSet using Default Options

// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-Java
// Load all document tables using default options.
DocumentTableSet tableSet = new DocumentTableSet(CommonUtilities.wordDataFile + dataSource);
// Check loading.
assert tableSet.getTables().getCount() == 3;
assert tableSet.getTables().get(0).getName().equals("Table1");
assert tableSet.getTables().get(1).getName().equals("Table2");
assert tableSet.getTables().get(2).getName().equals("Table3");

Loading DocumentTableSet using Custom Options

// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-Java
// Load document tables using custom options.
DocumentTableSet tableSet = new DocumentTableSet(CommonUtilities.getDataPath(srcDocument), new CustomDocumentTableLoadHandler());
// Ensure that the second table is not loaded.
assert tableSet.getTables().getCount() == 2;
assert tableSet.getTables().get(0).getName().equals("Table1");
assert tableSet.getTables().get(1).getName().equals("Table3");
// Ensure that default options are used to load the first table (that is, default column names are used).
assert tableSet.getTables().get(0).getColumns().getCount() == 2;
assert tableSet.getTables().get(0).getColumns().get(0).getName().equals("Column1");
assert tableSet.getTables().get(0).getColumns().get(1).getName().equals("Column2");
// Ensure that custom options are used to load the third table (that is, column names are extracted).
assert tableSet.getTables().get(1).getColumns().getCount() == 2;
assert tableSet.getTables().get(1).getColumns().get(0).getName().equals("Name");
assert tableSet.getTables().get(1).getColumns().get(1).getName().equals("Address");

Using DocumentTableSet as Data Source

// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-Java
// Set table column names to be extracted from the document.
DocumentTableSet tableSet = new DocumentTableSet(CommonUtilities.getDataPath(srcDocument), new ColumnNameExtractingDocumentTableLoadHandler());
// Set table names for conveniency.
tableSet.getTables().get(0).setName("Planets");
tableSet.getTables().get(1).setName("Persons");
tableSet.getTables().get(2).setName("Companies");
// Pass DocumentTableSet as a data source.
DocumentAssembler assembler = new DocumentAssembler();
assembler.assembleDocument(CommonUtilities.getDataPath(slideDoc), CommonUtilities.getOutPath("/Presentation Reports/out.pptx"),new DataSourceInfo(tableSet));

CustomDocumentTableLoadHandler

// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-Java
public class CustomDocumentTableLoadHandler implements IDocumentTableLoadHandler
{
public void handle(DocumentTableLoadArgs args)
{
switch (args.getTableIndex())
{
case 0:
// Do nothing. The table is to be loaded with default options.
break;
case 1:
// Discard loading of the table completely.
args.isLoaded(false);
break;
case 2:
// Load the table with custom options.
args.setOptions(new DocumentTableOptions());
args.getOptions().setFirstRowContainsColumnNames(true);
break;
default:
throw new IllegalStateException();
}
}
}

ColumnNameExtractingDocumentTableLoadHandler

// For complete examples and data files, please go to https://github.com/groupdocs-assembly/GroupDocs.Assembly-for-Java
public class ColumnNameExtractingDocumentTableLoadHandler implements IDocumentTableLoadHandler
{
public void handle(DocumentTableLoadArgs args)
{
args.setOptions(new DocumentTableOptions());
args.getOptions().setFirstRowContainsColumnNames(true);
}
}
Close
Loading

Analyzing your prompt, please hold on...

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