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.

File used in this sample can be downloaded from FixedColumnsWidthText.prn.

Screenshot

Fixed Columns Width Text Screenshot

See the full code below.

1using System;
2using System.Collections.Generic;
3using System.Text;
4using GemBox.Spreadsheet;
5using GemBox.Spreadsheet.ConditionalFormatting;
6using GemBox.Spreadsheet.PivotTables;
7
8class Sample
9{
10    [STAThread]
11    static void Main(string[] args)
12    {
13        // If using Professional version, put your serial key below.
14        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
15
16        // Define columns width (for input file format)
17        FixedWidthLoadOptions loadOptions = new FixedWidthLoadOptions(
18            new FixedWidthColumn(8),
19            new FixedWidthColumn(8),
20            new FixedWidthColumn(8));
21
22        // Load file
23        ExcelFile ef = ExcelFile.Load("FixedColumnsWidthText.prn", loadOptions);
24
25        // Modify file
26        ef.Worksheets.ActiveWorksheet.GetUsedCellRange(true).Sort(false).By(1).Apply();
27
28        // Define columns width (for output file format)
29        FixedWidthSaveOptions saveOptions = new FixedWidthSaveOptions(
30            new FixedWidthColumn(8),
31            new FixedWidthColumn(8),
32            new FixedWidthColumn(8));
33
34        ef.Save("FixedColumnsWidthText.prn", saveOptions);
35    }
36}
1Imports System
2Imports System.Collections.Generic
3Imports System.Text
4Imports GemBox.Spreadsheet
5Imports GemBox.Spreadsheet.ConditionalFormatting
6Imports GemBox.Spreadsheet.PivotTables
7
8Module Samples
9
10    Sub Main()
11
12        ' If using Professional version, put your serial key below.
13        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
14
15        ' Define columns width (for input file format)
16        Dim loadOptions As New FixedWidthLoadOptions( _
17            New FixedWidthColumn(8), _
18            New FixedWidthColumn(8), _
19            New FixedWidthColumn(8))
20
21        ' Load file
22        Dim ef As ExcelFile = ExcelFile.Load("FixedColumnsWidthText.prn", loadOptions)
23
24        ' Modify file
25        ef.Worksheets.ActiveWorksheet.GetUsedCellRange(True).Sort(False).By(1).Apply()
26
27        ' Define columns width (for output file format)
28        Dim saveOptions As New FixedWidthSaveOptions( _
29            New FixedWidthColumn(8), _
30            New FixedWidthColumn(8), _
31            New FixedWidthColumn(8))
32
33        ef.Save("FixedColumnsWidthText.prn", saveOptions)
34
35    End Sub
36
37End Module

Check next sample or find out more about GemBox.Spreadsheet and GemBox Software.