行内の最大列インデックスと列内の最大行インデックスの取得

可能な使用シナリオ

行や列の一部のデータを操作するだけの場合、行列範囲のデータ範囲を知る必要があります。Aspose.Cells for Node.js via C++はこの機能を提供します。行の最大列インデックスを取得するには、Row.getLastCell()Row.getLastDataCell()メソッドを使用し、その後Cell.getColumn()メソッドを使って最大列インデックスと最大データ列インデックスを取得します。列の最大行インデックスと最大行データインデックスを取得するには、列に範囲を作成し、その範囲をトラバースして最後のセルを見つけ、最終的にセルのCell.getRow()メソッドを呼び出します。

Aspose.Cells for Node.js via C++は、次のプロパティとメソッドを提供して、あなたの目標を達成するのに役立ちます。

行の最大列インデックスと列の最大行インデックスを取得

この例では、次のことができます:

  1. サンプルファイルをロードする。
  2. 最大列インデックスと最大データ列インデックスを取得する行を取得します。
  3. セルのCell.getColumn()メソッドを呼び出します。
  4. 列に基づいて範囲を作成します。
  5. イテレータを取得して範囲をトラバースします。
  6. セルのCell.getRow()メソッドを呼び出します。
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const workbook = new AsposeCells.Workbook(dataDir +"sample.xlsx");
const sheet = workbook.getWorksheets().get(0);
const cells = sheet.getCells();
const row = cells.checkRow(1);
if (row != null) {
//get Maximum column index of Row which contains data or style.
console.log("Max column index in row: " + row.getLastCell().getColumn());
//get Maximum column index of Row which contains data.
console.log("Max data column index in row: " + row.getLastDataCell().getColumn());
}
// create the range of column B
const columnRange = cells.createRange(1, 1, true);
var max_row_index = cells.getMaxRow() + 1;
var maxRow = 0;
var maxDataRow = 0;
for (let row_index = 0; row_index < max_row_index; row_index++)
{
var curr_cell = cells.get(row_index, 1);
if (curr_cell)
{
if (curr_cell.getStringValue())
{
maxDataRow = curr_cell.getRow();
}
if (curr_cell.getStringValue() || curr_cell.getHasCustomStyle())
{
maxRow = curr_cell.getRow();
}
}
}
//Maximum row index of Column which contains data or style.
console.log("Max row index in Column: " + maxRow);
//Maximum row index of Column which contains data.
console.log("Max data row index in Column: " + maxDataRow);