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 for Java
Screenshot of 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 the 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);
    }
}

See also


Next steps

GemBox.Spreadsheet for Java is a component that enables you to read, write, edit and convert spreadsheet files from your applications using one simple API.

Download Buy