ワークシートのセルへのアクセス
Contents
[
Hide
]
セルへのアクセス
Aspose.Cells for Python via Java を使用すると、ワークシート内のセルにセル名を使用するか、行と列のインデックスを使用してアクセスすることができます。この記事では、これらのアプローチの両方を使用してワークシート内のセルにアクセスする方法を示しています。
セル名を使用してセルにアクセスする
以下のコードスニペットは、セル名を使用してセルにアクセスする方法を示しています。サンプルコードでは、セル “C5” にアクセスし、その値を出力しています。
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())) |
行と列のインデックスを使用してセルにアクセスする
以下のコードスニペットは、行と列のインデックスを使用してセルにアクセスする方法を示しています。サンプルコードでは、行インデックス 4 とセルインデックス 2 で識別されるセル “C5” の値にアクセスしています。
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())) |