正規表現を使用してブック内のテキストを置換する
Contents
[
Hide
]
Aspose.Cellsを使用すると、正規表現を使用してブック内のテキストを置換する機能が提供されます。これにより、APIはReplaceOptionsクラスのRegexKeyプロパティを提供します。 RegexKeyをtrueに設定することで、検索されたキーが正規表現であることを示します。
次のコードスニペットは、サンプルエクセルファイルを使用してRegexKeyプロパティの使用を示しています。次のコードスニペットによって生成される出力ファイルが参照用に添付されています。
サンプルコード
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"); |