Ottenere l indice delle celle
Possibili Scenari di Utilizzo
Quando hai bisogno solo di manipolare un dato specifico nel foglio di lavoro per indice di riga e colonna, devi conoscere gli indici di riga e colonna di quella cella specifica. Aspose.Cells for Node.js via C++ offre questa funzione per ottenere l’indice di riga e colonna in base al nome di riga, colonna e cella. Aspose.Cells for Node.js via C++ fornisce le seguenti proprietà e metodi per aiutarti a raggiungere i tuoi obiettivi.
- CellsHelper.cellNameToIndex(string)
- CellsHelper.columnIndexToName
- CellsHelper.columnNameToIndex
- CellsHelper.rowIndexToName
- CellsHelper.rowNameToIndex
Nota: L’indicizzazione è basata su zero in Aspose.Cells for Node.js via C++, ma l’ID di Riga è uno-based in MS Excel.
Ottieni gli Indici delle Celle usando Aspose.Cells for Node.js via C++
Questo esempio mostra come:
- Creare un workbook e aggiungere alcuni dati.
- Trova la cella specifica nel primo foglio di lavoro.
- Ottieni l’indice di riga e l’indice di colonna per nome della cella.
- Ottieni l’indice di colonna per nome della colonna.
- Ottieni l’indice di riga per nome della riga.
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); |