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