クエリ テーブル データ ソースを使用したテーブルの読み取りと書き込み

クエリ テーブル データ ソースを使用したテーブルの読み取りと書き込み

Aspose.Cells を使用すると、QueryTable を Datasource として持つテーブルを読み書きできます。この機能のサポートは、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 ファイルが添付されています。

ソースファイル

出力ファイル