正規表現を使用してブック内のテキストを置換する
Contents
[
Hide
]
Aspose.Cellsは、正規表現を使用してワークブック内のテキストを置換する機能を提供しています。このため、API は ReplaceOptions クラスの RegexKey プロパティを提供します。RegexKey を true に設定すると、検索されるキーが正規表現であることを示します。
次のコードスニペットは、RegexKey プロパティの使用例を示しています。サンプルExcelファイルを使用して、このプロパティを使用したコードによって生成された出力ファイルが添付されています。
サンプルコード
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-.NET | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "SampleRegexReplace.xlsx"); | |
ReplaceOptions replace = new ReplaceOptions(); | |
replace.CaseSensitive = false; | |
replace.MatchEntireCellContents = false; | |
// Set to true to indicate that the searched key is regex | |
replace.RegexKey = true; | |
workbook.Replace("\\bKIM\\b", "^^^TIM^^^", replace); | |
workbook.Save(outputDir + "RegexReplace_out.xlsx"); |