Fixed Columns Width Text

Following example shows how to read and write Fixed Columns Width Text file which is text file with each column size fixed to some arbitrary number of characters.

Fixed-columns-width text file modified with GemBox.Spreadsheet
Screenshot of Fixed-columns-width text file modified with GemBox.Spreadsheet
using GemBox.Spreadsheet;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        // Define columns width (for input file format).
        var loadOptions = new FixedWidthLoadOptions(
            new FixedWidthColumn(8),
            new FixedWidthColumn(8),
            new FixedWidthColumn(8));

        // Load file.
        var workbook = ExcelFile.Load("%#FixedColumnsWidthText.prn%", loadOptions);

        // Modify file.
        workbook.Worksheets.ActiveWorksheet.GetUsedCellRange(true).Sort(false).By(1).Apply();

        // Define columns width (for output file format).
        var saveOptions = new FixedWidthSaveOptions(
            new FixedWidthColumn(8),
            new FixedWidthColumn(8),
            new FixedWidthColumn(8));

        workbook.Save("Fixed Columns Width Text.prn", saveOptions);
    }
}
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        ' Define columns width (for input file format).
        Dim loadOptions As New FixedWidthLoadOptions(
            New FixedWidthColumn(8),
            New FixedWidthColumn(8),
            New FixedWidthColumn(8))

        ' Load file.
        Dim workbook = ExcelFile.Load("%#FixedColumnsWidthText.prn%", loadOptions)

        ' Modify file.
        workbook.Worksheets.ActiveWorksheet.GetUsedCellRange(True).Sort(False).By(1).Apply()

        ' Define columns width (for output file format).
        Dim saveOptions As New FixedWidthSaveOptions(
            New FixedWidthColumn(8),
            New FixedWidthColumn(8),
            New FixedWidthColumn(8))

        workbook.Save("Fixed Columns Width Text.prn", saveOptions)
    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.