查找具有特定样式的单元格
Contents
[
Hide
]
有时,您需要查找应用了特定样式的单元格。您可以使用 Aspose.Cells 查找所有具有相同样式的单元格。 Aspose.Cells 提供了 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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
string filePath = dataDir+ "TestBook.xlsx"; | |
Workbook workbook = new Workbook(filePath); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the style of cell A1 | |
Style style = worksheet.Cells["A1"].GetStyle(); | |
// Specify the style for searching | |
FindOptions options = new FindOptions(); | |
options.Style = style; | |
Cell nextCell = null; | |
do | |
{ | |
// Find the cell that has a style of cell A1 | |
nextCell = worksheet.Cells.Find(null, nextCell, options); | |
if (nextCell == null) | |
break; | |
// Change the text of the cell | |
nextCell.PutValue("Found"); | |
} while (true); | |
dataDir = dataDir + "output.out.xlsx"; | |
workbook.Save(dataDir); |