查找具有特定样式的单元格
Contents
[
Hide
]
有时,您需要查找具有特定样式的单元格。您可以使用Aspose.Cells for Python via .NET来查找所有具有公共样式的单元格。Aspose.Cells for Python via .NET提供了FindOptions.style属性,您可以使用它来指定要搜索单元格的样式。
此示例中的代码查找所有具有与A1单元格相同样式的单元格。在代码执行后,所有具有与A1相同样式的单元格将包含文本“找到”。
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) |