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 trouver toutes les cellules avec un style commun. Aspose.Cells 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 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); |