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

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

借助Aspose.Cells for Python via .NET,您可以读取和写入带有QueryTable作为数据源的表格。这一支持同样适用于XLS文件。以下代码片段演示了如何读取并写入此类表格,首先读取表格,然后修改以添加总计行。

from aspose.cells import Workbook
from aspose.cells.tables import TableDataSourceType
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the source directory.
sourceDir = RunExamples.Get_SourceDirectory()
outputDir = RunExamples.Get_OutputDirectory()
# Load workbook object
workbook = Workbook(sourceDir + "SampleTableWithQueryTable.xls")
worksheet = workbook.worksheets[0]
table = worksheet.list_objects[0]
# Check the data source type if it is query table
if table.data_source_type == TableDataSourceType.QUERY_TABLE:
table.show_totals = True
# Save the file
workbook.save(outputDir + "SampleTableWithQueryTable_out.xls")

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

源文件

输出文件