Read Excel file in Java

GemBox.Spreadsheet for Java can read many Excel file formats (including XLS, XLSX, CSV and ODS) in the same manner. Specifically, it uses a Load method to read from a physical Excel file or the Excel file's stream in Java.

The following example demonstrates how to read all ExcelCells, their Value and ValueTypes, in ExcelFile object.

Note that when you iterate through all read cells in an ExcelRow, you should use AllocatedCells collection to prevent an unnecessary allocation of ExcelCell objects.

Reading Excel Screenshot
Upload your file (Drag file here)
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws {
        // If using Professional version, put your serial key below.

        ExcelFile ef = ExcelFile.load("%InputFileName%");

        StringBuilder sb = new StringBuilder();

        // Iterate through all worksheets in an Excel workbook.
        for (ExcelWorksheet sheet : ef.getWorksheets()) {
            sb.append(String.format("%1$s %2$s %1$s", "-----", sheet.getName()));

            // Iterate through all rows in an Excel worksheet.
            for (ExcelRow row : sheet.getRows()) {

                // Iterate through all allocated cells in an Excel row.
                for (ExcelCell cell : row.getAllocatedCells()) {
                    if (cell.getValueType() != CellValueType.NULL)
                        sb.append(String.format("%1$s [%2$s]", cell.getValue(), cell.getValueType()));
                        sb.append("     ");


Check next example or download examples from GitHub.