Accesso a Cells di un foglio di lavoro
Contents
[
Hide
]
Accedendo allo Cells
Aspose.Cells for Python via Java consente di accedere alle celle in un foglio di lavoro utilizzando il nome della cella o utilizzando l’indice della riga e della colonna. Questo articolo mostra entrambi questi approcci usati per accedere alle celle in un foglio di lavoro
Accedere alla cella utilizzando il nome della cella
Il seguente frammento di codice illustra l’accesso alla cella utilizzando il nome della cella. Il codice di esempio accede alla cella “C5” e ne stampa il valore.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source_directory = "Examples/SampleFiles/SourceDirectory/" | |
# Instantiating a Workbook object | |
workbook = Workbook(source_directory + "Book1.xlsx") | |
# Accessing the worksheet in the Excel file | |
worksheet = workbook.getWorksheets().get(0) | |
cells = worksheet.getCells() | |
# Accessing a cell using its name | |
cell = cells.get("C5") | |
# Print Message | |
print("Cell Value: " + str(cell.getValue())) |
Accedere alla cella utilizzando l’indice di riga e colonna
Il seguente frammento di codice illustra l’accesso alla cella utilizzando l’indice di riga e colonna. Il codice di esempio accede e stampa il valore della cella “C5” identificata dall’indice di riga 4 e dall’indice di cella 2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source_directory = "Examples/SampleFiles/SourceDirectory/" | |
# Instantiating a Workbook object | |
workbook = Workbook(source_directory + "Book1.xlsx") | |
# Accessing the worksheet in the Excel file | |
worksheet = workbook.getWorksheets().get(0) | |
cells = worksheet.getCells() | |
# Accessing a cell using the row and column index | |
cell = cells.get(4, 2) | |
# Print Message | |
print("Cell Value: " + str(cell.getValue())) |