groovy : poi XLSX2CSV
2015-09-13 21:05
543 查看
下载 poi-bin-3.10-FINAL-20140208.zip ,解压后
copy *.jar \groovy\lib\
copy \poi-3.10-FINAL\ooxml-lib\*.jar \groovy\lib\
jar tvf poi-ooxml-3.10-FINAL-20140208.jar | findstr OPCPackage
可见 org/apache/poi/openxml4j/opc/OPCPackage.class
jar tvf poi-examples-3.10-FINAL-20140208.jar | findstr XLSX2CSV
可见 org/apache/poi/xssf/eventusermodel/XLSX2CSV.class
示例代码: xlsx2csv.groovy
运行 groovy xlsx2csv test.xlsx
copy *.jar \groovy\lib\
copy \poi-3.10-FINAL\ooxml-lib\*.jar \groovy\lib\
jar tvf poi-ooxml-3.10-FINAL-20140208.jar | findstr OPCPackage
可见 org/apache/poi/openxml4j/opc/OPCPackage.class
jar tvf poi-examples-3.10-FINAL-20140208.jar | findstr XLSX2CSV
可见 org/apache/poi/xssf/eventusermodel/XLSX2CSV.class
示例代码: xlsx2csv.groovy
//package test; import org.apache.poi.openxml4j.opc.*; import org.apache.poi.xssf.eventusermodel.XLSX2CSV; if (args.length < 1) { System.err.println("Use:"); System.err.println(" XLSX2CSV <xlsx file> [min columns]"); return; } def file1 = args[0] File xlsxFile = new File(file1); if (!xlsxFile.exists()) { System.err.println("Not found or not a file: " + xlsxFile.getPath()); return; } def file2 = file1.replace('.xlsx','.csv') File csvFile = new File(file2); if ( csvFile.exists()) { System.err.println(file2+": csvFile is exists. " ); return; } int minColumns = -1; if (args.length >= 2) minColumns = Integer.parseInt(args[1]); // System.out redirect def out = new PrintStream(file2); System.setOut(out); // The package open is instantaneous, as it should be. OPCPackage p = OPCPackage.open(xlsxFile.getPath(), PackageAccess.READ); XLSX2CSV xlsx2csv = new XLSX2CSV(p, out, minColumns); xlsx2csv.process(); out.close();
运行 groovy xlsx2csv test.xlsx
相关文章推荐
- 我的Docker学习笔记
- Processing实现Google新图标
- oracle里long类型的总结
- Android实战简易教程-第五十八枪(AlarmManager类用法研究小实例)
- JS面向对象
- JS实现页面回到顶部效果
- 漏洞信息发布平台和网络安全
- 设计模式C++实现(3)——适配器模式
- 异常处理最佳实践
- 可视化算法网站
- 打算有时间写写博客
- 使用VS Code开发ASP.NET 5 应用程序
- Elven Postman(BST )
- 类的实现
- 设计模式C++实现(4)——饿汉懒汉之单例模式
- struts2 出现com.opensymphony.xwork2.util.ValueStack
- 浅谈C/C++引用和指针的联系和区别
- Leetcode #4 Median of Two Sorted Arrays
- 判断用户关闭浏览器-beforeunload事件
- windows下 MySQL的表名大小写 移植到Linux 区分大小写