Sostituire il testo in un libro di lavoro utilizzando le espressioni regolari

Aspose.Cells per Python via .NET offre la funzionalità di sostituire il testo in un workbook usando un’espressione regolare. Per questo, l’API fornisce la proprietà ReplaceOptions.regex_key della classe ReplaceOptions. Impostare il ReplaceOptions.regex_key a true indica che la chiave cercata sarà un’espressione regolare.

Il frammento di codice seguente dimostra l’uso della proprietà ReplaceOptions.regex_key utilizzando il file excel di esempio. Il file di output generato dal frammento di codice seguente è allegato per riferimento.

Codice di Esempio

from aspose.cells import ReplaceOptions, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Source directory
sourceDir = RunExamples.Get_SourceDirectory()
# Output directory
outputDir = RunExamples.Get_OutputDirectory()
workbook = Workbook(sourceDir + "SampleRegexReplace.xlsx")
replace = ReplaceOptions()
replace.case_sensitive = False
replace.match_entire_cell_contents = False
# Set to true to indicate that the searched key is regex
replace.regex_key = True
workbook.replace("\\bKIM\\b", "^^^TIM^^^", replace)
workbook.save(outputDir + "RegexReplace_out.xlsx")