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 for Node.js via C++ pour trouver toutes les cellules avec un style commun. Aspose.Cells propose la méthode FindOptions.setStyle(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
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
const filePath = path.join(dataDir, "TestBook.xlsx"); | |
const workbook = new AsposeCells.Workbook(filePath); | |
const worksheet = workbook.getWorksheets().get(0); | |
// Access the style of cell A1 | |
const style = worksheet.getCells().get("A1").getStyle(); | |
// Specify the style for searching | |
const options = new AsposeCells.FindOptions(); | |
options.setStyle(style); | |
let nextCell = null; | |
do { | |
// Find the cell that has a style of cell A1 | |
nextCell = worksheet.getCells().find(null, nextCell, options); | |
if (nextCell === null) break; | |
// Change the text of the cell | |
nextCell.putValue("Found"); | |
} while (true); | |
const outputPath = path.join(dataDir, "output.out.xlsx"); | |
workbook.save(outputPath); |