Node.js経由でC++を使ってワークシートのクエリテーブルを読み書きする方法

Contents
[ ]

ワークシートのクエリテーブルの読み書き

最初のワークシートの最初のQueryTableを読み取り、両方のプロパティを出力します。その後、QueryTable.preserveFormattingをtrueに設定します。

このコードで使用される元のExcelファイルとコードによって生成された出力Excelファイルは、以下のリンクからダウンロードできます。

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "Sample_queries.xlsx");
// Create workbook from source excel file
const workbook = new AsposeCells.Workbook(filePath);

// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);

// Access first Query Table
const qt = worksheet.getQueryTables().get(0);

// Print Query Table Data
console.log("Adjust Column Width: " + qt.getAdjustColumnWidth());
console.log("Preserve Formatting: " + qt.getPreserveFormatting());

// Now set Preserve Formatting to true
qt.setPreserveFormatting(true);

// Save the workbook
workbook.save(path.join(dataDir, "Output_out.xlsx"));

コンソール出力

上記のサンプルコードのコンソール出力は次の通りです

Adjust Column Width: True

Preserve Formatting: False

クエリテーブルの結果範囲を取得

Aspose.Cellsには、クエリテーブルの結果範囲のアドレスを読み取るオプションがあります。次のコードは、クエリテーブルの結果範囲のアドレスを読み取る機能を示しています。サンプルファイルはこちらからダウンロードできます。

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "Sample_queries.xlsx");

// Create workbook from source excel file
const wb = new AsposeCells.Workbook(filePath);

// Display the address(range) of result range of query table
console.log(wb.getWorksheets().get(0).getQueryTables().get(0).getResultRange().getAddress());