Last active
June 30, 2021 11:30
-
-
Save aspose-com-gists/93312ed586022489c842096a4558422e to your computer and use it in GitHub Desktop.
Split Text to Columns in Excel using C++
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
Split Text to Columns in Excel using C++ |
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
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Path of the output excel file | |
StringPtr outputFile = outDir->StringAppend(new String("TextToColumns.xlsx")); | |
// Create an instance of the IWorkbook class | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(); | |
// Access the first worksheet | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Add sample data | |
intrusive_ptr<String> str = new String("John Teal"); | |
worksheet->GetICells()->GetObjectByIndex(new String("A1"))->PutValue(str); | |
str = new String("Peter Graham"); | |
worksheet->GetICells()->GetObjectByIndex(new String("A2"))->PutValue(str); | |
str = new String("Brady Cortez"); | |
worksheet->GetICells()->GetObjectByIndex(new String("A3"))->PutValue(str); | |
str = new String("Mack Nick"); | |
worksheet->GetICells()->GetObjectByIndex(new String("A4"))->PutValue(str); | |
str = new String("Hsu Lee"); | |
worksheet->GetICells()->GetObjectByIndex(new String("A5"))->PutValue(str); | |
// Create an instance of the ITxtLoadOptions class | |
intrusive_ptr<ITxtLoadOptions> options = Factory::CreateITxtLoadOptions(); | |
// Specify the separator for separating the text | |
options->SetSeparator(' '); | |
// Split Text to Columns | |
worksheet->GetICells()->TextToColumns(0, 0, 5, options); | |
// Save the output excel file | |
workbook->Save(outputFile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment