ToText (Fixed-width text files)
As of EPPlus 7.2 it can read and write fixed width text files. It supports two ways of doing it using either start positions of columns or the length of each column.
Basic Usage¶
Saving Width of columns¶
Now let's create a workbook with a worksheet and add this data into it using the ToText method.
In this case ToText will need an ExcelOutputTextFormatFixedWidth where we enter the lengths of each column. This is the default behavior.
- This will write the contents from cell A1 to E6
- Numbers will be right aligned. Text will be left aligned
- By default the space character will be the padding character.
Saving Positions of columns¶
Now we will create a workbook with a worksheet and add data into it using ToText method, but this time we will use positions.
- This will write the contents from cell A1 to E6
- Numbers will be right aligned. Text will be left aligned
- By default the space character will be the padding character.
ExcelOutputTextFormatFixedWidth¶
You have the same properties when loading a fixed width text file as when saving, but you also have some extra properties as documented under the ToText article.
UseTrailingMinus¶
You can write fixed width file with trailing minus sign for numerics by setting the property. This will put the minus sign after the number in the column.