groovy : poi XLSX2CSV
发布时间:2020-12-14 16:45:56 所属栏目:大数据 来源:网络整理
导读:下载 poi-bin-3.10-FINAL-20140208.zip ,解压后 copy *.jar ? groovylib copy poi-3.10-FINALooxml-lib*.jar ?groovylib jar tvf poi-ooxml-3.10-FINAL-20140208.jar | findstr OPCPackage 可见 org/apache/poi/openxml4j/opc/OPCPackage.class ja
下载 poi-bin-3.10-FINAL-20140208.zip ,解压后
copy *.jar ? groovylib copy poi-3.10-FINALooxml-lib*.jar ?groovylib jar tvf poi-ooxml-3.10-FINAL-20140208.jar | findstr OPCPackage jar tvf poi-examples-3.10-FINAL-20140208.jar | findstr XLSX2CSV 示例代码: 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |