查找具有特定样式的单元格
Contents
[
Hide
]
有时,您需要找到应用了特定样式的单元格。您可以使用 Aspose.Cells for Node.js via C++ 来查找具有共同样式的所有单元格。Aspose.Cells 提供了 FindOptions.setStyle(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
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); |