Sostituisci il testo in una cartella di lavoro usando l'espressione regolare
Contents
[
Hide
]
Aspose.Cells fornisce la funzione per sostituire il testo in una cartella di lavoro utilizzando un’espressione regolare. Per questo, lo API fornisceRegexKeyproprietà delSostituisciOpzioni classe. Impostazione delRegexKey aVERO indica che la chiave cercata sarà un’espressione regolare.
Il seguente frammento di codice illustra l’uso diRegexKey proprietà utilizzando ilfile excel di esempio . Ilfile di uscita generato dal seguente frammento di codice è allegato per riferimento.
Codice d’esempio
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"); |