Trouver des cellules avec un style spécifique
Contents
[
Hide
]
Parfois, vous devez trouver des cellules avec un style particulier appliqué. Vous pouvez utiliser Aspose.Cells pour Python via .NET pour trouver toutes les cellules avec un style commun. Aspose.Cells pour Python via .NET fournit la propriété FindOptions.style que vous pouvez utiliser pour spécifier le style à rechercher dans les cellules.
Dans cet exemple, le code trouve toutes les cellules ayant le même style que celle de la cellule A1. Après l’exécution du code, toutes les cellules ayant le même style que A1 contiennent le texte “Trouvé”.
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) |