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 per Python via .NET offre questa funzionalità per ottenere l’indice di riga e colonna per nome della riga, colonna e cella. Aspose.Cells per Python via .NET fornisce le seguenti proprietà e metodi per aiutarti a raggiungere i tuoi obiettivi.
- CellsHelper.cell_name_to_index
- CellsHelper.column_index_to_name
- CellsHelper.column_name_to_index
- CellsHelper.row_index_to_name
- CellsHelper.row_name_to_index
Nota: L’indicizzazione è a base zero in Aspose.Cells per Python via .NET, ma l’id della riga è basato su uno in MS Excel.
Ottieni Indici delle Celle utilizzando la Libreria Excel Aspose.Cells per Python
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.
from aspose.cells import Workbook, CellsHelper | |
# Instantiating an Workbook object | |
workbook = Workbook() | |
# Obtaining the reference of the newly added worksheet | |
ws = workbook.worksheets[0] | |
cells = ws.cells | |
# Setting the value to the cells | |
cell = cells.get("A1") | |
cell.put_value("Fruit") | |
cell = cells.get("B1") | |
cell.put_value("Count") | |
cell = cells.get("C1") | |
cell.put_value("Price") | |
cell = cells.get("A2") | |
cell.put_value("Apple") | |
cell = cells.get("A3") | |
cell.put_value("Mango") | |
cell = cells.get("A4") | |
cell.put_value("Blackberry") | |
cell = cells.get("A5") | |
cell.put_value("Cherry") | |
cell = cells.get("B2") | |
cell.put_value(5) | |
cell = cells.get("B3") | |
cell.put_value(3) | |
cell = cells.get("B4") | |
cell.put_value(6) | |
cell = cells.get("B5") | |
cell.put_value(4) | |
cell = cells.get("C2") | |
cell.put_value(5) | |
cell = cells.get("C3") | |
cell.put_value(20) | |
cell = cells.get("C4") | |
cell.put_value(30) | |
cell = cells.get("C5") | |
cell.put_value(60) | |
curr = cells.find("Blackberry", None) | |
# get row and column index of current cell | |
currRow = [] | |
currCol = [] | |
CellsHelper.cell_name_to_index(curr.name, currRow, currCol) | |
print("Row Index: " + str(currRow[0]) + " Column Index: " + str(currCol[0])) | |
# get column name by column index | |
columnName = CellsHelper.column_index_to_name(currCol[0]) | |
# get row name by row index | |
rowName = CellsHelper.row_index_to_name(currRow[0]) | |
print("Column Name: " + columnName + " Row Name: " + rowName); | |
# get column index by column name | |
columnIndex = CellsHelper.column_name_to_index(columnName); | |
# get row index by row name | |
rowIndex = CellsHelper.row_name_to_index(rowName) | |
print("Column Index: " + str(columnIndex) + " Row Index: " + str(rowIndex)) |