Read and Write Table with Query Table Data Source
Read and Write Table with Query Table Data Source
With Aspose.Cells, you can read and write a table which has a QueryTable as Datasource. The support for this feature also exists for XLS files. The following code snippet demonstrates reading and writing such a table by first reading the table and then modifying it to add the totals row.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the output directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Load workbook object | |
Workbook workbook = new Workbook(sourceDir + "SampleTableWithQueryTable.xls"); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
ListObject table = worksheet.getListObjects().get(0); | |
// Check the data source type if it is query table | |
if (table.getDataSourceType() == TableDataSourceType.QUERY_TABLE) | |
{ | |
table.setShowTotals(true); | |
} | |
// Save the file | |
workbook.save(outputDir + "SampleTableWithQueryTable_out.xls"); |
The source and output excel files are attached for reference.