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 for Java
Fixed-columns-width text file modified with GemBox.Spreadsheet for Java
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.setLicense("FREE-LIMITED-KEY");

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

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

        // Modify file
        workbook.getWorksheets().getActiveWorksheet().getUsedCellRange(true).sort(false).by(1).apply();

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

        workbook.save("SortedFixedColumnsWidthText.prn", saveOptions);
    }
}

Check next example or download examples from GitHub.