Replace text in a workbook using Regular Expression with Node.js via C++

Contents
[ ]

Aspose.Cells provides the feature to replace text in a workbook using a regular expression. For this, the API provides ReplaceOptions.getRegexKey() property of the ReplaceOptions class. Setting the ReplaceOptions.getRegexKey() to true indicates that the searched key will be a regular expression.

The following code snippet demonstrates the use of the ReplaceOptions.getRegexKey() property by using the sample excel file. The output file generated by the following code snippet is attached for reference.

Sample Code

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// Source directory
const sourceDir = path.join(__dirname, "data");

// Output directory
const outputDir = path.join(__dirname, "output");

const filePath = path.join(sourceDir, "SampleRegexReplace.xlsx");
const workbook = new AsposeCells.Workbook(filePath);

const replace = new AsposeCells.ReplaceOptions();
replace.setCaseSensitive(false);
replace.setMatchEntireCellContents(false);
// Set to true to indicate that the searched key is regex
replace.setRegexKey(true);

workbook.replace("\\bKIM\\b", "^^^TIM^^^", replace);
workbook.save(path.join(outputDir, "RegexReplace_out.xlsx"));