特定のスタイルを持つセルを検索
Contents
[
Hide
]
特定のスタイルが適用されたセルを見つける必要がある場合があります。Aspose.Cells for Python via .NET を使用して、共通のスタイルを持つセルを検索する方法を学びます。Aspose.Cells for Python via .NET は、特定のスタイルを指定してセルを検索するために使用できる FindOptions.style プロパティを提供します。
この例のコードは、セルA1と同じスタイルのすべてのセルを見つけます。コードが実行された後、A1と同じスタイルのすべてのセルにはテキスト「Found」が含まれます。
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
from aspose.cells import FindOptions, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
filePath = "TestBook.xlsx" | |
workbook = Workbook(filePath) | |
worksheet = workbook.worksheets[0] | |
# Access the style of cell A1 | |
style = worksheet.cells.get("A1").get_style() | |
# Specify the style for searching | |
options = FindOptions() | |
options.style = style | |
nextCell = None | |
while True: | |
# Find the cell that has a style of cell A1 | |
nextCell = worksheet.cells.find(None, nextCell, options) | |
if nextCell == None: | |
break | |
# Change the text of the cell | |
nextCell.put_value("Found") | |
dataDir = "output.out.xlsx" | |
workbook.save(dataDir) |