Node.jsをC++経由で使用して、テーブルと範囲を操作する

紹介

Microsoft Excelでテーブルを作成し、その機能を使用せずにテーブルのデータを保持したい場合があります。代わりに、テーブルのように見えるものが欲しい場合があります。フォーマットを失わずにテーブル内のデータを保持するには、テーブルを通常のデータの範囲に変換します。
Aspose.Cellsは、テーブルやリストオブジェクトのMicrosoft Excelのこの機能をサポートしています。

Microsoft Excel の使用

表をフォーマットを保持したまま範囲に素早く変換するには、範囲に変換 機能を使用します。Microsoft Excel 2007/2010では:

  1. 表内のどこかをクリックして、アクティブなセルが表の列内にあることを確認します。
  2. デザイン タブの ツール グループで、範囲に変換 をクリックします。

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, "table_ranges.xlsx");

// Open an existing file that contains a table/list object in it
const wb = new AsposeCells.Workbook(filePath);

// Convert the first table/list object (from the first worksheet) to normal range
wb.getWorksheets().get(0).getListObjects().get(0).convertToRange();

// Save the file
wb.save(path.join(dataDir, "output.xlsx"));

オプションで範囲にテーブルを変換

Aspose.Cellsは、TableToRangeOptions クラスを介してテーブルを範囲に変換する際に追加のオプションを提供します。TableToRangeOptions クラスは、テーブル行の最後のインデックスを設定できる getLastRow() プロパティを提供します。指定した行インデックスまでテーブルの書式設定が保持され、その後の書式設定が削除されます。

以下のサンプルコードは、TableToRangeOptions クラスの使用例を示しています。

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, "table_ranges.xlsx");
// Open an existing file that contains a table/list object in it
const workbook = new AsposeCells.Workbook(filePath);

const options = new AsposeCells.TableToRangeOptions();
options.setLastRow(5);

// Convert the first table/list object (from the first worksheet) to normal range
workbook.getWorksheets().get(0).getListObjects().get(0).convertToRange(options);

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