读取和写入带有查询表数据源的表格

读取和写入带有查询表数据源的表格

使用Aspose.Cells,您可以读取和写入具有QueryTable作为数据源的表格。 此功能也适用于XLS文件。 以下代码片段演示了首先读取表格,然后修改表格以添加总行。

// 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");

源和输出的Excel文件已附上供参考。

源文件

输出文件