Text to Columns is used to convert simple text or sentences having multiple words into separate columns. It enables us to get the tabular structure of data using a suitable delimiter or column width option.
For example, when you want to separate a list of full names into first and last names, you can use Text to Columns feature.
You can set the TextToColumns method from the IRange interface to parse the text from one cell or column into many columns.
C# |
Copy Code
|
---|---|
IWorksheet TestActiveSheet = fpSpread1.AsWorkbook().ActiveSheet; TestActiveSheet.Cells["A1"].Value = "Jacob Dev SpreadWin"; TestActiveSheet.Cells["A2"].Value = "Steve Dev Raykit"; TestActiveSheet.Cells["A3"].Value = "Serena Tester SpreadWin"; TestActiveSheet.Cells["A4"].Value = "Keira Tester Raykit"; TestActiveSheet.Cells["A1:A4"].TextToColumns("A5", TextParsingType.Delimited, TextQualifier.None, false, false, false, false, true); |
VB |
Copy Code
|
---|---|
Dim TestActiveSheet As IWorksheet = FpSpread1.AsWorkbook().ActiveSheet TestActiveSheet.Cells("A1").Value = "Jacob Dev SpreadWin" TestActiveSheet.Cells("A2").Value = "Steve Dev Raykit" TestActiveSheet.Cells("A3").Value = "Serena Tester SpreadWin" TestActiveSheet.Cells("A4").Value = "Keira Tester Raykit" TestActiveSheet.Cells("A1:A4").TextToColumns("A5", TextParsingType.Delimited, TextQualifier.None, False, False, False, False, True) |
You can enable the built-in TextToColumn dialog box using BuiltInDialogs class at run-time to the end-user with the specified range.
The following code example shows how to use the runtime dialog box in a Spread worksheet:
C# |
Copy Code
|
---|---|
IWorksheet TestActiveSheet = fpSpread1.AsWorkbook().ActiveSheet; TestActiveSheet.Cells["A1"].Value = "Red,Blue,Green,Black,White,Yellow"; FarPoint.Win.Spread.Dialogs.BuiltInDialogs.TextToColumns(fpSpread1).Show(fpSpread1); |
VB |
Copy Code
|
---|---|
Dim TestActiveSheet As IWorksheet = FpSpread1.AsWorkbook().ActiveSheet TestActiveSheet.Cells("A1").Value = "Red,Blue,Green,Black,White,Yellow" FarPoint.Win.Spread.Dialogs.BuiltInDialogs.TextToColumns(fpSpread1).Show(FpSpread1) |
Spread for WinForms designer provides the "Text to Columns" ribbon button in the "Data Tools" group of the "Data" tab.
This method splits the text using the present delimiter in a cell or range. You can define your delimiter as well. Only one character is considered a delimiter.
Follow the steps below to convert the sample text using the comma delimiter.
Select the Delimited option from the "Original data type" section.
Click Next to open the "Convert Text to Columns Wizard- Step 2 for 3" window.
Set the delimiter from the pre defined list of delimiters or you can enter your delimiter by specifying the desired character in the "Other" option.
The delimiter in the "" or '' will be ignored.
Check "Treat consecutive delimiters as one" option to allow if multiple characters ";;;;" are specified, they will be treated as one ";" only.
Click Next to open the "Convert Text to Columns wizard-Step 3 of 3" window. Now, set the Data format for each column.
You can select the Destination for the text. The default destination is the original cell.
Click Finish to convert the text to the cell into columns.
This method splits the text using the fixed width between text. You can set column breaks to separate the text into columns.
Follow the steps below to convert the sample text using the fixed width:
Select the Fixed width option from the "Original data type" section.
Click Next to open the "Convert Text to Columns Wizard- Step 2 for 3" window.
Create fixed-width column breaks using the instructions mentioned on the window.
Click Next to open the "Convert Text to Columns wizard-Step 3 of 3" window.
Set the Data format for each column.
You can select the Destination for the text. The default destination is the original cell.
Click Finish to convert the text to the cell into columns.
A warning is displayed in the following scenarios: