scala : poi XLSX2CSV

下载 poi-bin-3.10-FINAL-20140208.zip ,解压后

copy *.jar   \scala\lib\

copy \poi-3.10-FINAL\ooxml-lib\*.jar  \scala\lib\

示例代码: xlsx2csv.scala

//package test;
import java.io.File
import java.io.PrintStream
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]");
    System.exit(4)
}
val file1 = args(0)
val xlsxFile = new File(file1);
if (!xlsxFile.exists()) {
    System.err.println("Not found or not a file: " + xlsxFile.getPath());
    System.exit(4)
}

val file2 = file1.replace(".xlsx",".csv")
val csvFile = new File(file2);
if ( csvFile.exists()) {
    System.err.println(file2+": csvFile is exists. " );
    System.exit(4)
}

var minColumns = -1;
if (args.length >= 2)
    minColumns = Integer.parseInt(args(1));

// System.out redirect
val out = new PrintStream(file2);
System.setOut(out);

// The package open is instantaneous, as it should be.
val p = OPCPackage.open(xlsxFile.getPath(), PackageAccess.READ);
val xlsx2csv = new XLSX2CSV(p, out, minColumns);
xlsx2csv.process();
out.close();

运行 scala xlsx2csv.scala test.xlsx


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值