Node.js経由のC++を使用してExcelワークシートに行を挿入または削除する

Contents
[ ]

Aspose.Cells for Node.js via C++は、行の挿入と削除のための二つのメソッドCells.insertRows(number, number, boolean)Cells.deleteRows(number, number)を提供します。これらのメソッドは、パフォーマンス最適化されており、非常に迅速に処理を行います。

行の挿入または削除の際は、ループ内でCells.insertRow(number)Cells.deleteRow(number)メソッドを使用するのではなく、常にCells.insertRows(number, number, boolean)Cells.deleteRows(number, number)メソッドを使用することを推奨します。

Aspose.CellsはMicrosoft Excelと同様に動作します。行または列が追加されると、ワークシートの内容は下方向や右方向にシフトされます。行または列が削除されると、ワークシートの内容は上方向や左方向にシフトされます。行が追加または削除された場合、他のワークシートやセル内の参照が更新されます。

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

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Instantiate a Workbook object.
// Load a template file.
const workbook = new AsposeCells.Workbook(path.join(dataDir, "book1.xlsx"));

// Get the first worksheet in the book.
const sheet = workbook.getWorksheets().get(0);

// Insert 10 rows at row index 2 (insertion starts at 3rd row)
sheet.getCells().insertRows(2, 10);

// Delete 5 rows now. (8th row - 12th row)
sheet.getCells().deleteRows(7, 5);

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