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/93312ed586022489c842096a4558422e to your computer and use it in GitHub Desktop.
Save aspose-com-gists/93312ed586022489c842096a4558422e to your computer and use it in GitHub Desktop.
Split Text to Columns in Excel using C++
Split Text to Columns in Excel using C++
// 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