Exemplo n.º 1
0
  /**
   * Remove a row from this sheet. All cells contained in the row are removed as well
   *
   * @param row representing a row to remove.
   */
  public void removeRow(Row row) {
    if (row.getSheet() != this) {
      throw new IllegalArgumentException("Specified row does not belong to this sheet");
    }

    for (Iterator<Map.Entry<Integer, SXSSFRow>> iter = _rows.entrySet().iterator();
        iter.hasNext(); ) {
      Map.Entry<Integer, SXSSFRow> entry = iter.next();
      if (entry.getValue() == row) {
        iter.remove();
        return;
      }
    }
  }
  private Row createRowFrom(IRecordable o) {
    Row lastRow, r;
    String[] data;

    if (dicoLocations.containsKey(o.getClassement()))
      lastRow = dicoLocations.get(o.getClassement());
    else {
      Sheet logSheet = wb.createSheet(o.getClassement());
      lastRow = logSheet.createRow(0);
      data = o.getTitles();
      fillRowWith(lastRow, data);
      dicoLocations.put(o.getClassement(), lastRow);
    }
    r = lastRow.getSheet().createRow(lastRow.getRowNum() + 1);
    data = o.getRecords();
    fillRowWith(r, data);
    dicoLocations.replace(o.getClassement(), r);
    return r;
  }
 private void contentProcess(
     Sheet tempSheet, Sheet newSheet, int contentRow, ConfirmationRecord data) throws Exception {
   int tempRowNum = -1;
   if (data.getAction() == null) {
     tempRowNum = 7;
   } else if (data.getAction().getParamKey().equals("CONFIRMATION_LOG_ACTION_ACCEPT")) {
     tempRowNum = 5;
   } else {
     tempRowNum = 6;
   }
   Row tempRow = tempSheet.getRow(tempRowNum);
   Row newRow = newSheet.createRow(contentRow);
   for (int c = 0; c < tempRow.getLastCellNum(); c++) {
     Cell tCell = tempRow.getCell(c);
     Cell cell = newRow.createCell(c, tCell.getCellType());
     setValue(cell, data);
     cell.setCellStyle(tCell.getCellStyle());
     cell.getRow().getSheet().setColumnWidth(c, tempRow.getSheet().getColumnWidth(c));
   }
 }
 /**
  * Discription:[写一行]
  *
  * @param row 行
  * @param keyValues 一个beanMap对象,包含着这一行中的所有数据
  * @param properties 哪些值需要写入行
  * @param dateFormat 日期格式,默认:yyyy-MM-dd
  * @author:[代超]
  * @throws Exception
  * @update:[日期YYYY-MM-DD] [更改人姓名][变更描述]
  */
 public void writeRow(Row row, Map keyValues, Map properties, String dateFormat, T t)
     throws Exception {
   // 表格内容样式
   CellStyle contentStyle = setContentSheetSysle(row.getSheet().getWorkbook());
   if (keyValues == null || keyValues.size() < 1 || row == null) {
     return;
   }
   if (dateFormat == null || "".equals(dateFormat.trim())) {
     dateFormat = "yyyy-MM-dd";
   }
   Iterator it = keyValues.entrySet().iterator();
   for (int i = 0; it.hasNext(); i++) {
     Map.Entry next = (Map.Entry) it.next();
     String dataValue = ObjectUtils.toString(properties.get(next.getKey()), "");
     if (dataValue == null || "".equals(dataValue.trim())) {
       // 无需导出当前字段
       i--;
       continue;
     }
     Object value = keyValues.get(next.getKey());
     // 值为空时仍然创建单元格并且赋予样式。
     Cell cell = row.createCell(i);
     cell.setCellStyle(contentStyle);
     if (value == null) {
       // 当值为空的时候,不必做其他操作了
       continue;
     }
     if (dataValue.toLowerCase().indexOf("formula") > -1) {
       // 公式
       String formula =
           ExcelFormula.parseFormula(value.toString())
               .replaceAll("-1", String.valueOf(cell.getRowIndex() + 1));
       cell.setCellFormula(formula);
     } else {
       Class c = PropertyUtils.getPropertyType(t, next.getKey().toString());
       writeCell(cell, value, c.getSimpleName(), dateFormat);
     }
   }
 }