正規表現を使用してブック内のテキストを置換する

Aspose.Cellsを使用すると、正規表現を使用してブック内のテキストを置換する機能が提供されます。これにより、APIはReplaceOptionsクラスのRegexKeyプロパティを提供します。 RegexKeytrueに設定することで、検索されたキーが正規表現であることを示します。

次のコードスニペットは、サンプルエクセルファイルを使用してRegexKeyプロパティの使用を示しています。次のコードスニペットによって生成される出力ファイルが参照用に添付されています。

サンプルコード

// 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");