Read a binary Excel file (.xlsb)
Updated: Mar 24, 2025
This example demonstrates how to read from a binary excel file (XLSB extension) in Java using the ExcelDocument and ExcelReader classes.
The demo code reads a binary excel file and displays its contents in the standard console. However, the contents of the binary excel file may be sent to other output types like CSV, XML, Database, etc.
Java Code Listing
/* * Copyright (c) 2006-2025 North Concepts Inc. All rights reserved. * Proprietary and Confidential. Use is subject to license terms. * * https://northconcepts.com/data-pipeline/licensing/ */ package com.northconcepts.datapipeline.examples.cookbook; import java.io.File; import com.northconcepts.datapipeline.core.DataReader; import com.northconcepts.datapipeline.core.StreamWriter; import com.northconcepts.datapipeline.excel.ExcelDocument; import com.northconcepts.datapipeline.excel.ExcelDocument.ProviderType; import com.northconcepts.datapipeline.excel.ExcelReader; import com.northconcepts.datapipeline.job.Job; public class ReadFromABinaryExcelFile { public static void main(String[] args) throws Throwable { ExcelDocument document = new ExcelDocument(ProviderType.POI_XSSFB) .open(new File("example/data/input/employee_details.xlsb")); DataReader reader = new ExcelReader(document) //.setSheetName("employee_details") .setFieldNamesInFirstRow(true) .setAutoCloseDocument(true); Job.run(reader, StreamWriter.newSystemOutWriter()); } }
Code walkthrough
- An ExcelDocument is created corresponding to the input file.
- Set ProviderType.POI_XSSFB to read binary Excel files.
- The input file is opened via ExcelDocument.open method using the file path of the input file
employee_details.xlsb
. - A new ExcelReader is created and opened via ExcelReader.open.
- Each row in the excel sheet is read as a Record object and written to the standard console via the
StreamWriter.newSystemOutWriter()
. - All cell values are returned as strings in record fields.
Console output
----------------------------------------------- 0 - Record { 0:[id]:STRING=[1]:String 1:[firstName]:STRING=[John]:String 2:[lastName]:STRING=[Doe]:String 3:[address]:STRING=[120 jefferson st.]:String 4:[city]:STRING=[Riverside]:String 5:[state]:STRING=[ NJ]:String 6:[employeeId]:STRING=[8075]:String } ----------------------------------------------- 1 - Record { 0:[id]:STRING=[2]:String 1:[firstName]:STRING=[Jack]:String 2:[lastName]:STRING=[McGinnis]:String 3:[address]:STRING=[220 hobo Av.]:String 4:[city]:STRING=[Phila]:String 5:[state]:STRING=[ PA]:String 6:[employeeId]:STRING=[9119]:String } ----------------------------------------------- 2 - Record { 0:[id]:STRING=[3]:String 1:[firstName]:STRING=[John "Da Man"]:String 2:[lastName]:STRING=[Repici]:String 3:[address]:STRING=[120 Jefferson St.]:String 4:[city]:STRING=[Riverside]:String 5:[state]:STRING=[ NJ]:String 6:[employeeId]:STRING=[8075]:String } ----------------------------------------------- 3 - Record { 0:[id]:STRING=[4]:String 1:[firstName]:STRING=[Stephen]:String 2:[lastName]:STRING=[Tyler]:String 3:[address]:STRING=[7452 Terrace "At the Plaza" road]:String 4:[city]:STRING=[SomeTown]:String 5:[state]:STRING=[SD]:String 6:[employeeId]:STRING=[91234]:String } ----------------------------------------------- 4 - Record { 0:[id]:STRING=[5]:String 1:[firstName]:UNDEFINED=[null] 2:[lastName]:STRING=[Blankman]:String 3:[address]:UNDEFINED=[null] 4:[city]:STRING=[SomeTown]:String 5:[state]:STRING=[ SD]:String 6:[employeeId]:STRING=[298]:String } ----------------------------------------------- 5 - Record { 0:[id]:STRING=[6]:String 1:[firstName]:STRING=[Joan "the bone" Anne]:String 2:[lastName]:STRING=[Jet]:String 3:[address]:STRING=[9th, at Terrace plc]:String 4:[city]:STRING=[Desert City]:String 5:[state]:STRING=[CO]:String 6:[employeeId]:STRING=[123]:String } ----------------------------------------------- 6 records