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

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

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

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the source directory.
string sourceDir = RunExamples.Get_SourceDirectory();
string outputDir = RunExamples.Get_OutputDirectory();
// Load workbook object
Workbook workbook = new Workbook(sourceDir + "SampleTableWithQueryTable.xls");
Worksheet worksheet = workbook.Worksheets[0];
ListObject table = worksheet.ListObjects[0];
// Check the data source type if it is query table
if (table.DataSourceType == TableDataSourceType.QueryTable)
{
table.ShowTotals = true;
}
// Save the file
workbook.Save(outputDir + "SampleTableWithQueryTable_out.xls");

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

源文件

输出文件