Texte in einer Arbeitsmappe mithilfe von regulären Ausdrücken mit Node.js über C++ ersetzen
Aspose.Cells bietet die Funktion, Text in einer Arbeitsmappe mithilfe eines regulären Ausdrucks zu ersetzen. Dafür stellt die API die ReplaceOptions.getRegexKey() Eigenschaft der ReplaceOptions Klasse bereit. Wenn Sie ReplaceOptions.getRegexKey() auf true setzen, bedeutet dies, dass der gesuchte Schlüssel ein regulärer Ausdruck ist.
Das folgende Codebeispiel demonstriert die Verwendung der ReplaceOptions.getRegexKey()-Eigenschaft anhand der Beispieldatei. Die Ausgabedatei, die durch das folgende Codebeispiel generiert wurde, ist zur Referenz beigefügt.
Beispielcode
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"));