ワークシートの Cells へのアクセス
Contents
[
Hide
]
Cellsにアクセス
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())) |