MS Excel’s text to columns feature allows you to split text in a column into multiple columns. You can split the text on a blank space, a comma, or any other character. In order to automate the feature, this article covers how to split text to columns in Excel files in C#.
Excel’s Text to Columns in C# - API Installation
In order to split text into columns in Excel files, we’ll use Aspose.Cells for .NET. It is a spreadsheet manipulation API that lets you create, modify or convert Excel files in .NET applications. You can either download the API or install it using NuGet.
PM> Install-Package Aspose.Cells
C# Split Text to Columns in Excel
The following are the steps to split text to columns in Excel using C#.
- Load the Excel file using the Workbook class.
- Get the reference of the Worksheet in which you want to perform text to columns operation.
- Insert data into the worksheet (optional).
- Create an instance of TxtLoadOptions class and set text separator character using TxtLoadOptions.Separator property.
- Split text to columns using Worksheet.Cells.TextToColumns(int row, int column, int totalRows, TxtLoadOptions options) method.
- Save the updated Excel file using Workbook.Save(string) method.
The following code sample shows how to split text to columns in Excel.
Excel Text to Column C# API - Get a Free License
You can get a temporary license in order to use the API without evaluation limitations.
In this article, you have learned how to split text to columns in Excel files using C#. The code sample has shown how easy it is to implement Excel’s text to columns based on a particular character. You can explore more about Aspose.Cells for .NET using the documentation. In case you would have any queries, contact us via our forum.