Find Cells with Specific Style
Contents
[
Hide
]
Sometimes, you need to find cells with a particular style applied. You can use Aspose.Cells for Python via .NET to find all cells with a common style. Aspose.Cells for Python via .NET provides the FindOptions.style property which you can use to specify the style to search cells for.
The code in this example finds all cells that have the same style as that of cell A1. After the code has been executed, all the cells that have the same style as A1 contain the text “Found”.
This file contains hidden or 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) |