Exemplo n.º 1
0
 /**
  * 批量导出
  *
  * @param data
  * @throws FileNotFoundException
  */
 public void transform(Map<String, Object> data) throws FileNotFoundException {
   FileInputStream templateIs = new FileInputStream(template);
   try {
     XSSFWorkbook bookTmp = (XSSFWorkbook) transformer.transformXLS(templateIs, data);
     bookTmp.setSheetName(0, "第" + count + "页");
     if (count == 1) {
       book = new SXSSFWorkbook(bookTmp);
     } else {
       Sheet newSheet = book.createSheet(bookTmp.getSheetName(0));
       Sheet sheet = bookTmp.getSheetAt(0);
       Util.copySheets(newSheet, sheet);
     }
     count++;
   } catch (ParsePropertyException e) {
     e.printStackTrace();
   } catch (InvalidFormatException e) {
     e.printStackTrace();
   } finally {
     try {
       templateIs.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
Exemplo n.º 2
0
 public void write(String destFile) throws IOException {
   File f = new File(destFile);
   if (!f.exists()) {
     f.createNewFile();
   }
   Util.writeToFile(destFile, book);
 }
Exemplo n.º 3
0
 CellStyle duplicateStyle(Cell cell, String key) {
   if (rowStyles.containsKey(key)) {
     return (CellStyle) rowStyles.get(key);
   }
   CellStyle newStyle =
       Util.duplicateStyle(
           cell.getRow().getSheet().getPoiWorkbook(), cell.getPoiCell().getCellStyle());
   rowStyles.put(key, newStyle);
   return newStyle;
 }
Exemplo n.º 4
0
 public void writeFormulas(FormulaResolver formulaResolver) {
   Set sheetNames = sheetFormulasMap.keySet();
   for (Iterator iterator = sheetNames.iterator(); iterator.hasNext(); ) {
     String sheetName = (String) iterator.next();
     List formulas = (List) sheetFormulasMap.get(sheetName);
     for (int i = 0; i < formulas.size(); i++) {
       Formula formula = (Formula) formulas.get(i);
       String formulaString = formulaResolver.resolve(formula, null);
       if (formulaString != null) {
         Cell hssfCell =
             Util.getOrCreateCell(
                 formula.getSheet().getPoiSheet(), formula.getRowNum(), formula.getCellNum());
         try {
           hssfCell.setCellFormula(formulaString);
         } catch (RuntimeException e) {
           log.error("Can't set formula: " + formulaString, e);
           //                        hssfCell.setCellType( Cell.CELL_TYPE_BLANK );
           throw new RuntimeException("Can't set formula: " + formulaString, e);
         }
       }
     }
   }
 }