Last active
June 25, 2021 08:59
-
-
Save aspose-com-gists/05b1407519b4ee653792fc456bb06506 to your computer and use it in GitHub Desktop.
Split Text to Column in Excel in Java | https://blog.aspose.com/2021/05/25/split-text-to-columns-in-excel-using-java/
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
// Open a workbook. | |
Workbook wb = new Workbook("workbook.xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Add people name in column A. Fast name and Last name are separated by space. | |
ws.getCells().get("A1").putValue("John Teal"); | |
ws.getCells().get("A2").putValue("Peter Graham"); | |
ws.getCells().get("A3").putValue("Brady Cortez"); | |
ws.getCells().get("A4").putValue("Mack Nick"); | |
ws.getCells().get("A5").putValue("Hsu Lee"); | |
// Create text load options with space as separator. | |
TxtLoadOptions opts = new TxtLoadOptions(); | |
opts.setSeparator(' '); | |
// 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.getCells().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
Read the article: https://blog.aspose.com/2021/05/25/split-text-to-columns-in-excel-using-java/