导出excel2007 poi3.8

poi3.8默认情况下,用到的临时目录是系统自带的临时目录,在本次项目中遇到临时目录超限,所以需要修改源代码指定需要设置的临时目录
需要修改的类为:GZIPSheetDataWriter,SheetDataWriter
GZIPSheetDataWriter压缩时候用到,如在构造workbook时:
wokbook = new SXSSFWorkbook(new XSSFWorkbook(
new FileInputStream(FanExcel2007.TEMPLATE_PATH)), 2000,true);
false代表不压缩,默认为False用SheetDataWriter

GZIPSheetDataWriter修改:
/**
* @return temp file to write sheet data
*/
public File createTempFile()throws IOException {
// 获取tmp目录
String tmpDir = null;
File fd = null;
File file = null;
try {
// tmpDir = FileUtils.readFileToString(new File(SheetDataWriter.class
// .getResource("/tmpPath.txt").getFile()), "utf8");
tmpDir="/home/hdfs/effect/liubx/tmp";
System.out.println("临时缓存目录为:" + tmpDir);
if (tmpDir != null && !tmpDir.equals("")) {
file = new File(tmpDir);
if (!file.exists()) {
file.mkdirs();
}
}

} catch (Exception ex) {
System.out.println("指定缓存目录失败:" + tmpDir);
tmpDir = null;
}
if (tmpDir == null || tmpDir.equals("")) {
fd = File.createTempFile("poi-sxssf-sheet-xml", ".gz");
} else {
fd = File.createTempFile("poi-sxssf-sheet-xml", ".gz",file);
}


fd.deleteOnExit();
return fd;
}
SheetDataWriter修改处:
/**
* Create a temp file to write sheet data.
* By default, temp files are created in the default temporary-file directory
* with a prefix "poi-sxssf-sheet" and suffix ".xml". Subclasses can override
* it and specify a different temp directory or filename or suffix, e.g. <code>.gz</code>
*
* @return temp file to write sheet data
*/
public File createTempFile()throws IOException {
// 获取tmp目录
String tmpDir = null;
File fd = null;
File file = null;
try {
tmpDir="/home/hdfs/effect/liubx/tmp";
System.out.println("临时缓存目录为:" + tmpDir);
if (tmpDir != null && !tmpDir.equals("")) {
file = new File(tmpDir);
if (!file.exists()) {
file.mkdirs();
}
}

} catch (Exception ex) {
System.out.println("指定缓存目录失败:" + tmpDir);
tmpDir = null;
}
if (tmpDir == null || tmpDir.equals("")) {
fd = File.createTempFile("poi-sxssf-sheet", ".xml");
} else {
fd = File.createTempFile("poi-sxssf-sheet", ".xml",file);
}

fd.deleteOnExit();
return fd;
}
这样可以写超大数据,在写超大数据时最好用压缩的方式,写文件比较快!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值