Ersetzen Sie Text in einer Arbeitsmappe mithilfe eines regulären Ausdrucks
Contents
[
Hide
]
Aspose.Cells bietet die Funktion zum Ersetzen von Text in einer Arbeitsmappe mithilfe eines regulären Ausdrucks. Dafür sorgt die APIRegexKeyEigentum derOptionen ersetzenKlasse. Einstellung derRegexKeyzuwahrgibt an, dass der gesuchte Schlüssel ein regulärer Ausdruck sein wird.
Das folgende Code-Snippet demonstriert die Verwendung vonRegexKeyEigenschaft durch Verwendung derExcel-Beispieldatei. DasAusgabedateigeneriert durch das folgende Code-Snippet ist als Referenz beigefügt.
Beispielcode
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-Java | |
// directories | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "SampleRegexReplace.xlsx"); | |
ReplaceOptions replace = new 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(outputDir + "RegexReplace_out.xlsx"); |