文件操作:Xml转Excel
1 添加依赖
Spire.Xls.jar
<dependency><groupId>e-iceblue</groupId><artifactId>spire.xls</artifactId><version>5.3.3</version></dependency>
2 代码使用
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格式的Excelwb.saveToFile("C:\\Users\\17240\\Downloads\\2.xlsx", FileFormat.Version2013);}
}