Performances on large Excel in Java

The following example shows how you can test the performance of GemBox.Spreadsheet for Java component on large spreadsheet files when using the Free version of the component.

If the limits of the free version are exceeded, the component will continue to work in Trial mode if the FreeLimitReached listener is added as in the example.

For more information about Trial mode limitations, see GemBox.Spreadsheet Evaluation and Licensing help page.

Performance of GemBox.Spreadsheet for Java on large Excel file
Screenshot of performance of GemBox.Spreadsheet for Java on large Excel file
import com.gembox.spreadsheet.*;

import java.util.concurrent.TimeUnit;

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

        // If example exceeds Free version limitations then continue as Trial version:
        // https://www.gemboxsoftware.com/spreadsheet-java/docs/evaluation-and-licensing.html
        SpreadsheetInfo.addFreeLimitReachedListener((event) -> event.setFreeLimitReachedAction(FreeLimitReachedAction.CONTINUE_AS_TRIAL));

        int rowCount = 50000;
        int columnCount = 10;
        String fileFormat = "XLSX";

        System.out.println("Performance example:");
        System.out.println();
        System.out.println("Row count: " + rowCount);
        System.out.println("Column count: " + columnCount);
        System.out.println("File format: " + fileFormat);
        System.out.println();

        long start = System.nanoTime();

        ExcelFile workbook = new ExcelFile();
        ExcelWorksheet worksheet = workbook.addWorksheet("Performance");

        for (int row = 0; row < rowCount; row++)
            for (int column = 0; column < columnCount; column++)
                worksheet.getCell(row, column).setValue(row + "_" + column);

        long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
        System.out.println("Generate file (seconds): " + elapsed / 1000.0);

        start = System.nanoTime();

        int cellsCount = 0;
        for (ExcelRow row : worksheet.getRows())
            for (ExcelCell cell : row.getAllocatedCells())
                cellsCount++;

        elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
        System.out.println("Iterate through " + cellsCount + " cells (seconds): " + elapsed / 1000.0);

        start = System.nanoTime();

        workbook.save("Report." + fileFormat.toLowerCase());

        elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);

        System.out.println("Save file (seconds): " + elapsed / 1000.0);
    }
}

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