导出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;
    }
这样可以写超大数据,在写超大数据时最好用压缩的方式,写文件比较快!

你可能感兴趣的:(poi,导出Excel,超大数据,poi3.8)