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 {
        // If using the Professional version, put your serial key below.

        // If example exceeds Free version limitations then continue as Trial version:
        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("Row count: " + rowCount);
        System.out.println("Column count: " + columnCount);
        System.out.println("File format: " + fileFormat);

        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())

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

        start = System.nanoTime();"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