Поиск ячеек с определенным стилем
Contents
[
Hide
]
Иногда вам может понадобиться найти ячейки с определенным примененным стилем. Вы можете использовать Aspose.Cells для Python via .NET, чтобы найти все ячейки с общим стилем. Aspose.Cells для Python via .NET предоставляет свойство FindOptions.style, которое вы можете использовать, чтобы указать стиль для поиска ячеек.
Код в этом примере находит все ячейки, у которых такой же стиль, как у ячейки A1. После выполнения кода все ячейки, у которых такой же стиль, как у A1, содержат текст “Найдено”.
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) |