Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created June 25, 2021 09:01
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/67152c52a3ecfd712fe060c0c0a9b4be to your computer and use it in GitHub Desktop.
Save aspose-com-gists/67152c52a3ecfd712fe060c0c0a9b4be to your computer and use it in GitHub Desktop.
Text to Columns in Excel using C#
// Load a workbook
Workbook wb = new Workbook("Excel.xlsx");
// Access first worksheet
Worksheet ws = wb.Worksheets[0];
// Add people name in column A. Fast name and Last name are separated by space
ws.Cells["A1"].PutValue("John Teal");
ws.Cells["A2"].PutValue("Peter Graham");
ws.Cells["A3"].PutValue("Brady Cortez");
ws.Cells["A4"].PutValue("Mack Nick");
ws.Cells["A5"].PutValue("Hsu Lee");
// Create text load options with space as separator
TxtLoadOptions opts = new TxtLoadOptions();
opts.Separator = ' ';
// Split the column A into two columns using TextToColumns() method
// Now column A will have first name and column B will have second name
ws.Cells.TextToColumns(0, 0, 5, opts);
// Save the workbook in xlsx format
wb.Save("TextToColumns.xlsx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment