文件操作: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 实现效果

相关推荐
TDengine (老段)12 小时前
TDengine IDMP ---- Excel 插件
大数据·数据库·excel·时序数据库·tdengine·涛思数据
用户2986985301412 小时前
使用 Python 替换 Word 文档文字:从全文到指定范围
python·api
Thanks_ks13 小时前
手写一个 LRU 缓存:哈希表与双向链表的组合设计
python·哈希表·lru·双向链表·ordereddict·命中率·哨兵节点
lusklusklusk13 小时前
图文详解:使用 Power BI Desktop 一步步创建并部署跨 Excel 与 SQL 数据的 PBIRS 报表
数据库·sql·excel
AI创界者1 天前
Python 进阶实战(七十一章):研发效能度量、自动化质量门禁与工程规范落地实战
人工智能·python·aigc
yingjie1101 天前
快榜GEO|官网 AI 可读性自查 12 项(附 Python 检测脚本)
开发语言·人工智能·python
tryCbest1 天前
Python 爬虫扩展篇(二):验证码的检测与人工介入——把“拦路虎”当作信号,而不是要征服的对手
开发语言·爬虫·python
@陈小鱼1 天前
基于InceptionTime网络的PPG无创血压估计算法研究
人工智能·python·算法·回归·开源·ppg·血压估计
谙弆悕博士1 天前
动态自适应多智能体架构的 LangGraph 实现:从元调度器到可运行原型
人工智能·python·神经网络·机器学习·架构·多智能体·智能体
SeanQhl1 天前
用 Python 给长文做排版体检:图够不够、段落是不是太长
python·自动化·markdown·代码规范·写作工具