@Override
  public void close() {
    try {
      int nbS = wb.getNumberOfSheets();
      for (int i = 0; i < nbS; i++) {
        XSSFSheet s = wb.getSheetAt(i);
        for (int j = 0; j < s.getRow(0).getLastCellNum(); j++) {
          XSSFCell c = s.getRow(0).getCell(j);
          c.getSheet().autoSizeColumn(c.getColumnIndex());
        }

        XSSFCell firstCell = s.getRow(0).getCell(0);
        XSSFCell 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();
    }
  }
Exemplo n.º 2
0
 /**
  * Enable filtering for a range of cells
  *
  * @param range the range of cells to filter
  */
 public AutoFilter setAutoFilter(CellRangeAddress range) {
   return _sh.setAutoFilter(range);
 }