Convert Excel to Office Open XML and Office Open to Excel in Java

·

2 min read

Office OpenXML, also known as OpenXML or OOXML, is a zipped, XML-based format developed by Microsoft. It can include Word documents, Excel spreadsheets, PowerPoint presentations, and Charts, Diagrams, Shapes, etc. This article will share how to Convert Excel to Office Open XML and then convet it back using a free Java library named Free Spire.XLS for Java.

Install the free library (2 Method)

1# Download the free library and unzip it, then add the Spire.Xls.jar file to your project as dependency.
2# Directly add the jar dependency to maven project by adding the following configurations to the pom.xml.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>http://repo.e iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls.free</artifactId>
        <version>5.1.0</version>
    </dependency>
</dependencies>

Convert Excel to Office Open XML Using Java

Free Spire.XLS for Java offers the Workbook.saveAsXml() method to save the Excel file as Office Open XML.

import com.spire.xls.Workbook;

public class ExcelToOpenXML {
    public static void main(String []args){
        //Create a Workbook instance
        Workbook workbook = new Workbook();
        //Load an Excel file
        workbook.loadFromFile("Sales1.xlsx");

        //Save as Office Open XML file format
        workbook.saveAsXml("ToXML.xml");
    }
}

Convert Office Open XML to Excel in Java

Using the Workbook.saveToFile() method, you can save the Office Open XML file as Excel.

import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;

public class OpenXmlToExcel {
    public static void main(String []args){
        //Create an instance of Workbook class
        Workbook workbook = new Workbook();
        //Load an Office Open XML file
        workbook.loadFromXml("ToXML.xml");

        //Save as Excel XLSX file format
        workbook.saveToFile("ToExcel.xlsx", ExcelVersion.Version2016);
    }
}

ConvertOOXML.jpg