Converting XLSB to XLSX in Java

Convert XLSB to XLSX

Excel files with the .xlsb extension use Microsoft’s binary workbook format, which is smaller and faster to load than XLSX for large sheets. Converting one to the standard .xlsx format is a common need when a downstream tool or library does not accept binary workbooks.

Why Apache POI Alone Is Not Enough

A common approach is to pass an XLSB stream to XSSFWorkbookFactory.createWorkbook(). That method expects an OOXML package, so it does not accept XLSB content. Apache POI can read XLSB data through its read-only binary API in org.apache.poi.xssf.binary, but it cannot write XLSB, and that reader does not give you a workbook you can save directly as XLSX.

For a direct conversion, use a library that supports both formats. This article uses Aspose.Cells.

Add Aspose.Cells to Your Project

Aspose.Cells is distributed through its own Maven repository. Add the repository and dependency, replacing the version with the release you want to use:

<repositories>
    <repository>
        <id>aspose-repo</id>
        <url>https://repository.aspose.com/repo/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-cells</artifactId>
        <version>YOUR_VERSION</version>
    </dependency>
</dependencies>

Convert XLSB to XLSX

Load the binary workbook and save it in XLSX format:

import com.aspose.cells.LoadFormat;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;

public class XlsbToXlsxConverter {

    public static void main(String[] args) {
        String inputFile = "input.xlsb";
        String outputFile = "output.xlsx";

        try {
            // Load the XLSB file, specifying its format explicitly
            Workbook workbook = new Workbook(inputFile, LoadFormat.XLSB);

            // Save the workbook as XLSX
            workbook.save(outputFile, SaveFormat.XLSX);

            System.out.println("Conversion completed: " + outputFile);
        } catch (Exception e) {
            System.err.println("Could not convert the workbook: " + e.getMessage());
        }
    }
}

Considerations

  • Licensing: Aspose.Cells is a commercial library. Evaluation builds add watermarks and have other limits, so review the license before using it in production.
  • Fidelity: Check formulas, macros, charts, and formatting after conversion. Macros are not carried over when saving to XLSX.
  • Input handling: Validate files from external sources and handle exceptions for corrupt or password-protected workbooks.

Conclusion

To convert XLSB to XLSX in Java, use a library that supports both formats. With Aspose.Cells, load the file as LoadFormat.XLSB and save it as SaveFormat.XLSX. Verify the output and confirm that the library’s license fits your project.

Comments