Convert Text to Columns
Convert Text to Columns
You can convert your Text to Columns using Microsoft Excel. This feature is available from Data Tools under the Data tab. In order to split the contents of a column to multiple columns, the data should contain a specific delimiter such as a comma (or any other character) based on which Microsoft Excel splits the contents of a cell to multiple cells. Aspose.Cells also provides this feature via the TextToColumns method. The following code snippet demonstrates the use of the TextToColumns method by converting text to columns with space as a delimiter.
output_directory = "Examples/SampleFiles/OutputDirectory/" | |
# Create Workbook | |
workbook = Workbook() | |
# Access the first worksheet | |
worksheet = workbook.getWorksheets().get(0) | |
# Add people name in column A. Fast name and Last name are separated by space. | |
worksheet.getCells().get("A1").putValue("John Teal") | |
worksheet.getCells().get("A2").putValue("Peter Graham") | |
worksheet.getCells().get("A3").putValue("Brady Cortez") | |
worksheet.getCells().get("A4").putValue("Mack Nick") | |
worksheet.getCells().get("A5").putValue("Hsu Lee") | |
# Create text load options with space as separator. | |
txtLoadOptions = TxtLoadOptions() | |
txtLoadOptions.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. | |
worksheet.getCells().textToColumns(0, 0, 5, txtLoadOptions) | |
# Save the excel file. | |
workbook.save(output_directory + "outputTextToColumns.xlsx") |