Zellenindex erhalten

Mögliche Verwendungsszenarien

Wenn Sie nur eine bestimmte Daten auf dem Arbeitsblatt mit Zeilen- und Spaltenindex manipulieren müssen, müssen Sie die Spalten- und Zeilenindizes dieser bestimmten Zelle kennen. Aspose.Cells for Node.js via C++ bietet diese Funktion, um Zeilen- und Spaltenindex anhand des Namens der Zeile, Spalte und Zelle zu erhalten. Aspose.Cells for Node.js via C++ stellt die folgenden Eigenschaften und Methoden bereit, um Ihre Ziele zu erreichen.

Hinweis: Die Indizierung ist in Aspose.Cells for Node.js via C++ nullbasiert, aber die ID der Zeile ist einsbasiert in MS Excel.

Zellindizes mit Aspose.Cells for Node.js via C++ abrufen

Dieses Beispiel zeigt, wie Sie:

  1. Erstellen Sie ein Arbeitsbuch und fügen Sie einige Daten hinzu.
  2. Finden Sie die spezifische Zelle im ersten Arbeitsblatt.
  3. Holen Sie sich den Zeilenindex und Spaltenindex nach dem Namen der Zelle.
  4. Holen Sie sich den Spaltenindex nach dem Namen der Spalte.
  5. Holen Sie sich den Zeilenindex nach dem Namen der Zeile.
const AsposeCells = require("aspose.cells.node");
var workbook = new AsposeCells.Workbook(AsposeCells.FileFormatType.Xlsx);
var cells = workbook.getWorksheets().get(0).getCells();
var cell = cells.get("A1");
cell.putValue("Fruit");
cell = cells.get("B1");
cell.putValue("Count");
cell = cells.get("C1");
cell.putValue("Price");
cell = cells.get("A2");
cell.putValue("Apple");
cell = cells.get("A3");
cell.putValue("Mango");
cell = cells.get("A4");
cell.putValue("Blackberry");
cell = cells.get("A5");
cell.putValue("Cherry");
cell = cells.get("B2");
cell.putValue(5);
cell = cells.get("B3");
cell.putValue(3);
cell = cells.get("B4");
cell.putValue(6);
cell = cells.get("B5");
cell.putValue(4);
cell = cells.get("C2");
cell.putValue(5);
cell = cells.get("C3");
cell.putValue(20);
cell = cells.get("C4");
cell.putValue(30);
cell = cells.get("C5");
cell.putValue(60);
var curr = cells.find("Blackberry", null);
//var curr = cells.get("A4");
console.log("Current Cell Name: " + curr.getName());
//get row and column index of current cell
var rowCol = AsposeCells.CellsHelper.cellNameToIndex(curr.getName());
var currRow = rowCol[0];
var currCol = rowCol[1];
console.log("Row Index: " + currRow + " Column Index: " + currCol);
//get column name by column index
var columnName = AsposeCells.CellsHelper.columnIndexToName(currCol);
//get row name by row index
var rowName = AsposeCells.CellsHelper.rowIndexToName(currRow);
console.log("Column Name: " + columnName + " Row Name: " + rowName);
//get column index by column name
var columnIndex = AsposeCells.CellsHelper.columnNameToIndex(columnName);
//get row index by row name
var rowIndex = AsposeCells.CellsHelper.rowNameToIndex(rowName);
console.log("Column Index: " + columnIndex + " Row Index: " + rowIndex);
console.log(columnIndex == currCol);
console.log(rowIndex == currRow);