Microsoft Excel allows you to store data in tabular form. In addition to that, it enables you to perform complex operations on data. Excel’s uses range from maintaining monthly budgets to managing organizational data due to its vast set of features. As compared to other features, finding and replacing text is among the more straightforward tasks you can do in Excel. This article demonstrates how to find and replace text in Excel spreadsheets programmatically using C++.
- C++ API to Find and Replace Text in Excel Files
- Finding and Replacing Text in Excel Files using C++
- Get a Free License
C++ API to Find and Replace Text in Excel Files
Aspose.Cells for C++ is a robust API for generating, transforming, and managing Excel files. It allows you to automate various aspects of spreadsheet workflows. The API also simplifies finding and replacing text in Excel files. You can either install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.Cells.Cpp
Find and Replace Text in Excel Files using C++
The following are the steps for finding and replacing text in Excel files.
- Load the Excel file using the IWorkbook class.
- Create an instance of the IReplaceOptions class.
- Set the case sensitivity for searching the text with IReplaceOptions->SetCaseSensitive(bool value) method. By setting this option to true, the API will replace only the text with the matching case.
- Set the option for matching the entire contents of the cell with IReplaceOptions->SetMatchEntireCellContents(bool value) method. By setting this option to true, the API will replace text in only the cells containing the exact placeholder text (the text you want to replace).
- Call the IWorkbook->Replace( intrusive_ptr<Aspose::Cells::Systems::String> placeHolder, intrusive_ptr<Aspose::Cells::Systems::String> newValue, intrusive_ptr<Aspose::Cells::IReplaceOptions> options) method to replace the text.
- Save the updated spreadsheet using IWorkbook->Save(intrusive_ptr<Aspose::Cells::Systems::String> fileName) method.
The following code sample shows how to find and replace text in spreadsheets.
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
In this article, you have learned how to find and replace text in Excel files. Furthermore, you have seen how to set additional options like case-sensitivity and matching the entire cell’s contents for finding text. Other than this, the API provides a bunch of features for working with Excel files. You can explore Aspose.Cells for C++ API in detail by using the official documentation.