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 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);
    }
}

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 for Java 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.