Created
June 25, 2021 09:01
-
-
Save aspose-com-gists/67152c52a3ecfd712fe060c0c0a9b4be to your computer and use it in GitHub Desktop.
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
// 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