@Override
  public void close() {
    try {
      int nbS = wb.getNumberOfSheets();
      for (int i = 0; i < nbS; i++) {
        Sheet s = wb.getSheetAt(i);
        if (s.getRow(0)
            != null) { // ceci arrive si on vide la mémoire tampon pour les grands fichiers. Dans ce
                       // cas pas de possibilité de traiter la mise en page de gros fichiers
          for (int j = 0; j < s.getRow(0).getLastCellNum(); j++) {
            Cell c = s.getRow(0).getCell(j);
            c.getSheet().autoSizeColumn(c.getColumnIndex());
          }

          Cell firstCell = s.getRow(0).getCell(0);
          Cell lastCell = s.getRow(0).getCell((int) s.getRow(0).getLastCellNum() - 1);
          s.setAutoFilter(
              new CellRangeAddress(
                  firstCell.getRowIndex(),
                  lastCell.getRowIndex(),
                  lastCell.getRowIndex(),
                  lastCell.getColumnIndex()));
        }
      }
      wb.write(fileOut);
      fileOut.flush();
      fileOut.close();
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 2
0
 private void writeToFile(SXSSFWorkbook wb) throws FileNotFoundException, IOException {
   FileOutputStream out = new FileOutputStream(filePath);
   wb.write(out);
   wb.dispose();
   out.close();
 }
Esempio n. 3
0
 /**
  * 输出数据流
  *
  * @param os 输出数据流
  */
 public ExportExcel write(OutputStream os) throws IOException {
   wb.write(os);
   return this;
 }