Java converts Excel to XML

An Extensible Markup Language (XML) file is a standard text file that uses specific tags to describe the structure and other characteristics of a document. Usually, we can get files in XML format through format conversion. This article will introduce how to realize the conversion from Excel to XML format through Java code.


Import Jar

Introduce the Spire.Xls.jar file in Free Spire.XLS for Java in the program (the file is under the lib folder); if you need to download and import through Maven , you can configure pom.xml as follows:

<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <url>https://repo.e-iceblue.cn/repository/maven-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 XML

When converting, only three lines of code are required, namely:

  • Create an object of the Workbook class and load an Excel document through the Workbook.loadFromFile() method.
  • Call the Workbook.saveAsXml() method to save the XML file to the specified path.

Java

import com.spire.xls.*;

public class ExcelToXML {
    public static void main(String[] args) {
        //创建Workbook类的对象
        Workbook wb = new Workbook();

        //加载Excel文档
        wb.loadFromFile("test.xlsx");

        //保存为XML文件
        wb.saveAsXml("result.xml");
    }
}

Conversion result:

Recommended reading:

Java converts CSV to Excel icon-default.png?t=M666https://blog.csdn.net/Eiceblue/article/details/123845988

Java converts Excel to OFD icon-default.png?t=M666https://blog.csdn.net/Eiceblue/article/details/122216917

Java converts Excel to et and ett formats icon-default.png?t=M666https://blog.csdn.net/Eiceblue/article/details/121079795

Java method to convert Excel to SVG icon-default.png?t=M666https://blog.csdn.net/Eiceblue/article/details/117360538

Java converts Excel to pictures, html, XPS, XML, CSV icon-default.png?t=M666https://blog.csdn.net/Eiceblue/article/details/103564058

Java converts Excel to PDF icon-default.png?t=M666https://blog.csdn.net/Eiceblue/article/details/103530993

—END—

Guess you like

Origin blog.csdn.net/Eiceblue/article/details/126136053