Microsoft Excel allows splitting text into multiple columns using separators like blank space, comma, or other characters. This feature can be helpful in scenarios such as converting the comma-separated data exported from a database table to tabular form. To that end, this article will teach you how to split text into columns in Excel files using C++.
- C++ API for Splitting Text to Columns in Excel Files
- Splitting Text into Columns in Excel Files using C++
C++ API for Splitting Text to Columns in Excel Files
We will use the Aspose.Cells for C++ API for splitting text into columns in Excel files. It is a native C++ library that allows you to create, read and modify Excel files without requiring Microsoft Excel to be installed. You can either install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.Cells.Cpp
Split Text into Columns in Excel Files using C++
The following are the steps to split text into columns in Excel files.
- Create an instance of the IWorkbook class.
- Access the worksheet where you want to split the text using the IWorkbook->GetIWorksheets()->GetObjectByIndex (Aspose::Cells::Systems::Int32 index) method.
- Insert sample data into the worksheet.
- Create an instance of the ITxtLoadOptions class.
- Specify the character that will be used to split the text using the ITxtLoadOptions->SetSeparator(Aspose::Cells::Systems::Char value) method.
- Split the text into columns using the IWorksheet->GetICells()->TextToColumns(Aspose::Cells::Systems::Int32 row, Aspose::Cells::Systems::Int32 column, Aspose::Cells::Systems::Int32 totalRows, intrusive_ptr<Aspose::Cells::ITxtLoadOptions> options) method.
- Save the Excel file using the IWorkbook->Save (intrusive_ptr<Aspose::Cells::Systems::String> fileName) method.
The following sample code demonstrates how to split text into columns in Excel files using C++.
Get a Free License
In order to try the API without evaluation limitations, you can request a free temporary license.
In this article, you have learned how to split text into multiple columns in Excel files using C++. You have seen the complete code snippet along with the steps required to achieve this. Aspose.Cells for C++ is a robust API that provides many additional features for automating your Excel-related tasks. You can explore the API in detail by visiting the official documentation. In case of any questions, please feel free to reach us on our free support forum.