Ejemplo n.º 1
0
  private Cell getXlsCell(ColumnDisplayDefinition colDef, int colIdx, int curRow, Object cellObj) {
    Row row = sheet.getRow(curRow);
    if (row == null) {
      row = sheet.createRow(curRow);
    }
    Cell retVal = row.createCell(colIdx);

    if (null == cellObj || null == colDef) {
      retVal.setCellValue(getDataXLSAsString(cellObj));
      return retVal;
    }

    int colType = colDef.getSqlType();

    switch (colType) {
      case Types.BIT:
      case Types.BOOLEAN:
        if (null == cellObj) {
          // retVal.setCellValue((Boolean)null);
        } else {
          retVal.setCellValue((Boolean) cellObj);
        }
        break;
      case Types.INTEGER:
        if (null == cellObj) {
          // retVal.setCellValue((Integer)null);
        } else {
          retVal.setCellValue(((Number) cellObj).intValue());
        }
        break;
      case Types.SMALLINT:
      case Types.TINYINT:
        if (null == cellObj) {
          // retVal.setCellValue(((Short) null));
        } else {
          retVal.setCellValue(((Number) cellObj).shortValue());
        }
        break;
      case Types.NUMERIC:
      case Types.DECIMAL:
      case Types.FLOAT:
      case Types.DOUBLE:
      case Types.REAL:
        if (null == cellObj) {
          // retVal.setCellValue((Double) null);
        } else {
          retVal.setCellValue(((Number) cellObj).doubleValue());
        }
        break;
      case Types.BIGINT:
        if (null == cellObj) {
          // retVal.setCellValue((Long)null);
        } else {
          retVal.setCellValue(Long.parseLong(cellObj.toString()));
        }
        break;
      case Types.DATE:
        makeTemporalCell(retVal, (Date) cellObj, "m/d/yy");
        break;
      case Types.TIMESTAMP:
        makeTemporalCell(retVal, (Date) cellObj, "m/d/yy h:mm");
        break;
      case Types.TIME:
        makeTemporalCell(retVal, (Date) cellObj, "h:mm");
        break;
      case Types.CHAR:
      case Types.VARCHAR:
      case Types.LONGVARCHAR:
        cellObj = CellComponentFactory.renderObject(cellObj, colDef);
        retVal.setCellValue(getDataXLSAsString(cellObj));
        break;
      default:
        cellObj = CellComponentFactory.renderObject(cellObj, colDef);
        retVal.setCellValue(getDataXLSAsString(cellObj));
    }

    return retVal;
  }
Ejemplo n.º 2
0
  public void exportToStream(List<ModelMap> list) {
    // System.out.println(list.size());
    if (list == null || list.size() == 0) {
      // System.out.println("list is blank");
      return;
    }
    System.out.println(list.size());
    Set<String> set = list.get(0).keySet();

    for (Map<String, Object> map : list) {
      createRow(_rowcnt++);
      _backColor = -1;
      Object _obj = map.get("t13y");
      int _spanr = 1;

      for (int i = 0; i < keys.length - 1; i++) {

        Object obj = map.get(keys[i]);
        // if (obj instanceof List) {
        // continue;
        // }

        if (obj == null) continue;
        String _str = obj.toString();
        // try {
        // _str = obj.toString();
        // } catch (Exception e) {
        // System.out.println(i + keys[i]);
        // }
        // System.out.println(_str);
        if (keys[i].equals("dupFlag")) {
          if (obj != null) {
            setCell(i, Long.parseLong(_str));
          } else {
            setCell(i, "");
          }
        } else if (keys[i].equals("key")
            || keys[i].equals("resStatus")
            || keys[i].equals("tvalue")
            || keys[i].equals("arrayFlag")
            || keys[i].equals("filepath")) {
          if (obj != null) {
            setCell(i, _str);
          } else {
            setCell(i, "");
          }
        } else if (keys[i].equals("svalue")) {
          if (obj != null) {
            setCell(i, _str, Double.parseDouble((String) map.get("similarity")));
          } else {
            setCell(i, "");
          }
        } else if (keys[i].equals("similarity")) {
          if (obj != null) {
            setCell(i, Double.parseDouble(_str));
          } else {
            setCell(i, "");
          }
        }
        // else if (keys[i].equals("t13y")) {
        // if (obj != null) {
        // setPlainCell(i, obj, map.get("t13y1"));
        // } else {
        // setPlainCell(i, "", null);
        // }
        // } else if (keys[i].equals("t13ys")) {
        // if (obj != null) {
        // setPlainCell(i, obj, null);
        // } else {
        // setPlainCell(i, "", null);
        // }
        // }

      }
      if (_obj == null) continue;
      List<t13yRule> _rules = null;
      _rules = (List<t13yRule>) _obj;
      _spanr = _rules.size();
      int _tidx = lbls.length - 3;
      for (int j = 0; j < _spanr; j++) {
        t13yRule _rule = _rules.get(j);
        if (j > 0) {
          createRow(_rowcnt++);
        }
        setPlainCell(_tidx, _rule.getRuleSeverity(), 0, _rule.getRuleSeverity().length());
        setPlainCell(_tidx + 1, _rule.getRuleDescription(), -1, -1);
        setPlainCell(_tidx + 2, _rule.getRuleSuggestion(), -1, -1);
      }
    }
    // set column width, if the keys' order changed, you should update this

    int[] wdt = {300, 50, 50, 250, 70, 70, 250, 250, 60, 250, 300};
    setWidth(wdt);

    // export to stream

    // exportXLSToStream(os);
  }