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.

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

class Program
{
    static void Main(string[] args)
    {
        // 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

Check next example or download examples from GitHub.