Accessing Cells of a Worksheet
Contents
[
Hide
]
Accessing Cells
Aspose.Cells for Python via Java allows you to access cells in a worksheet by using the cell name or by using the index of the row and column. This article shows both these approaches used to access cells in a worksheet
Access cell using cell name
The following code snippet demonstrates accessing the cell using the name of the cell. The sample code accesses the cell “C5” and prints its value.
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())) |
Access cell using the row and column index
The following code snippet demonstrates accessing the cell using the row and column index. The sample code accesses and prints the value of the cell “C5” that is identified by row index 4 and cell index 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())) |