文件操作:Xml转Excel

1 添加依赖

Spire.Xls.jar

xml 复制代码
        <dependency>
            <groupId>e-iceblue</groupId>
            <artifactId>spire.xls</artifactId>
            <version>5.3.3</version>
        </dependency>

2 代码使用

java 复制代码
package cctd.controller;

import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;

import java.io.*;

public class MainServer {
    public static void main(String[] args) {
        //加载xml文件或 Office OpenXml 类型的xsl文件
        Workbook wb = new Workbook();
        File file = new File("C:\\Users\\17240\\Downloads\\1.xml");
        //将File转为inputstream流
        InputStream is = null;
        try {
            is = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        wb.loadFromXml(is);
        //转为2013版xlsx格式的Excel
        wb.saveToFile("C:\\Users\\17240\\Downloads\\2.xlsx", FileFormat.Version2013);
    }
}

3 实现效果

相关推荐
多恩Stone1 小时前
【3DV 进阶-2】Hunyuan3D2.1 训练代码详细理解下-数据读取流程
人工智能·python·算法·3d·aigc
xiaopengbc1 小时前
在 Python 中实现观察者模式的具体步骤是什么?
开发语言·python·观察者模式
Python大数据分析@1 小时前
python用selenium怎么规避检测?
开发语言·python·selenium·网络爬虫
ThreeAu.1 小时前
Miniconda3搭建Selenium的python虚拟环境全攻略
开发语言·python·selenium·minicoda·python环境配置
偷心伊普西隆1 小时前
Python EXCEL 理论探究:格式转换时处理缺失值方法
python·excel
精灵vector2 小时前
LLMCompiler:基于LangGraph的并行化Agent架构高效实现
人工智能·python·langchain
java1234_小锋2 小时前
Scikit-learn Python机器学习 - 特征降维 压缩数据 - 特征选择 - 移除低方差特征(VarianceThreshold)
python·机器学习·scikit-learn
万邦科技Lafite3 小时前
实战演练:通过API获取商品详情并展示
大数据·数据库·python·开放api接口