使用查询表数据源读写表

使用查询表数据源读写表

使用 Aspose.Cells for Python via Java,您可以读写一个以 QueryTable 作为数据源的表。 XLS 文件也支持此功能。下面的代码片段通过首先读取表格然后修改它以添加总计行来演示读写这样的表格。

source_directory = "Examples/SampleFiles/SourceDirectory/"
output_directory = "Examples/SampleFiles/OutputDirectory/"
# Load workbook object
workbook = Workbook(source_directory + "SampleTableWithQueryTable.xls")
worksheet = workbook.getWorksheets().get(0)
# Access first list object or table
listObj = worksheet.getListObjects().get(0)
# Check the data source type if it is query table
if (listObj.getDataSourceType() == TableDataSourceType.QUERY_TABLE):
listObj.setShowTotals(True)
# Save the excel file.
workbook.save(output_directory + "SampleTableWithQueryTable_out.xls")

附上源文件和输出 excel 文件以供参考。

源文件

输出文件