Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/20bea3a300043930ddaff689d1629fd5 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/20bea3a300043930ddaff689d1629fd5 to your computer and use it in GitHub Desktop.
Find and Replace Text in Excel Spreadsheets using C++
Find and Replace Text in Excel Spreadsheets using C++
// Source directory path.
StringPtr srcDir = new String("SourceDirectory\\");
// Output directory path.
StringPtr outDir = new String("OutputDirectory\\");
// Load Excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("book1.xlsx")));
// Create an instance of the IReplaceOptions class
intrusive_ptr<IReplaceOptions> replaceOptions = Factory::CreateIReplaceOptions();
// Set case sensitivity option
replaceOptions->SetCaseSensitive(false);
// Set text matching option
replaceOptions->SetMatchEntireCellContents(false);
// Replace text
workbook->Replace(new String("Text to find"), new String("Text replacement"), replaceOptions);
// Save as Excel file
workbook->Save(outDir->StringAppend(new String("book1_out.xlsx")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment