Åtkomst till Cells i ett arbetsblad
Contents
[
Hide
]
Tillgång till Cells
Aspose.Cells for Python via Java låter dig komma åt celler i ett kalkylblad genom att använda cellnamnet eller genom att använda indexet för raden och kolumnen. Den här artikeln visar båda dessa metoder som används för att komma åt celler i ett kalkylblad
Åtkomst till cell med cellnamn
Följande kodsnutt visar åtkomst till cellen med cellens namn. Exempelkoden kommer åt cellen “C5” och skriver ut dess värde.
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())) |
Åtkomst till cell med hjälp av rad- och kolumnindex
Följande kodavsnitt visar åtkomst till cellen med hjälp av rad- och kolumnindex. Exempelkoden kommer åt och skriver ut värdet för cellen “C5” som identifieras av radindex 4 och cellindex 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())) |