private void putBasicInfo(Table table, int rowIndex, String key, Object value, int numbOfCols) {
    row = table.getRowByIndex(rowIndex);
    row.getCellByIndex(1).setCellStyleName(null);
    row.getCellByIndex(2).setCellStyleName(null);
    cell = CalcUtils.putHeader(row, 1, key);
    cell.setHorizontalAlignment(ExportConstants.ALIGH_HOR_RIGHT);

    cell = CalcUtils.createBasicCell(table, 2, rowIndex, value);
    CalcUtils.mergeCell(table, 2, rowIndex, numbOfCols, rowIndex);
  }
Ejemplo n.º 2
0
  /**
   * @param table
   * @param prof
   * @param bim
   * @return a planilha parseada ou <code>null</code> caso a primeira célula de aulas dadas esteja
   *     vazia, ou algum outro problema aconteça
   * @throws NotasParserException
   */
  private ProfSheet parseSheet(Table table, String prof, Periodo bim) throws NotasParserException {

    logger.debug("Lendo período " + bim);

    ProfSheet profSheet = new ProfSheet(bim, prof);

    Coluna y = new Coluna(COL_FIRST_TARJETA);
    int i = 0;
    String posTurma = y.getValor().concat(LIN_TURMAS);
    String turma = "";
    turma = table.getCellByPosition(posTurma).getDisplayText();

    while (!turma.isEmpty() && !turma.contains("FIM")) {

      try {
        Tarjeta tarj = parseTarjeta(table, i, prof, bim);
        profSheet.getTarjetas().add(tarj);
      } catch (NotasParserException e) {
        logger.warn(
            "Tarjeta da "
                + turma
                + " "
                + bim
                + " não incluída na planilha de "
                + profSheet.getProfessor());
      }

      i++;
      y.inc(TARJETAS_DISTANCE);
      String pos = y.getValor().concat(LIN_TURMAS);
      Cell nextCell = table.getCellByPosition(pos);
      turma = nextCell.getDisplayText();
    }

    return profSheet;
  }
 private void putValueCell(
     Table table, int rowIndex, int cellIndex, Object value, boolean rightAligned) {
   cell = CalcUtils.createBasicCell(table, cellIndex, rowIndex, value);
   if (rightAligned) cell.setHorizontalAlignment(ExportConstants.ALIGH_HOR_RIGHT);
 }
  private void createDetailSheet(final IndicatorDTO indicator) throws Throwable {
    final boolean isQualitative = indicator.getAggregation() == IndicatorDTO.AGGREGATE_MULTINOMIAL;
    final Table tableEx =
        doc.appendSheet(
            CalcUtils.normalizeAsLink(
                ExportConstants.INDICATOR_SHEET_PREFIX + indicator.getName()));
    int rowIndex = -1;

    List<PivotTableData.Axis> leaves =
        data.getEntryMap().get(indicator.getId()).getRootColumn().getLeaves();
    int numbOfLeaves = leaves.size();
    int numbOfCols = 4;

    // back to list link
    row = tableEx.getRowByIndex(++rowIndex);
    cell = tableEx.getCellByPosition(1, rowIndex);
    CalcUtils.applyLink(
        cell,
        data.getLocalizedVersion("goToIndicatorsList"),
        data.getLocalizedVersion("flexibleElementIndicatorsList"));
    CalcUtils.mergeCell(tableEx, 1, rowIndex, data.getNumbOfCols(), rowIndex);

    // title
    CalcUtils.putMainTitle(tableEx, ++rowIndex, numbOfCols, indicator.getName());

    // empty row
    CalcUtils.putEmptyRow(tableEx, ++rowIndex);

    // put details
    putBasicInfo(
        tableEx, ++rowIndex, data.getLocalizedVersion("code"), indicator.getCode(), numbOfCols);

    putBasicInfo(
        tableEx,
        ++rowIndex,
        data.getLocalizedVersion("group"),
        data.getGroupMap().get(indicator.getGroupId()),
        numbOfCols);

    // type
    String type = null;
    ;
    if (isQualitative) {
      // qualitative
      type = data.getLocalizedVersion("qualitative");
    } else {
      // quantitative
      type = data.getLocalizedVersion("quantitative");
    }
    putBasicInfo(tableEx, ++rowIndex, data.getLocalizedVersion("type"), type, numbOfCols);

    // conditional
    if (isQualitative) {
      // qualitative

      // possible values
      row = tableEx.getRowByIndex(++rowIndex);

      // key
      cell = CalcUtils.putHeader(row, 1, data.getLocalizedVersion("possibleValues"));
      cell.setHorizontalAlignment(ExportConstants.ALIGH_HOR_RIGHT);

      // value
      final MultiItemText itemText = data.formatPossibleValues(indicator.getLabels());
      CalcUtils.createBasicCell(tableEx, 2, rowIndex, itemText.text);
      CalcUtils.mergeCell(tableEx, 2, rowIndex, numbOfCols, rowIndex);

    } else {
      // quantitative

      // aggregation method
      String aggrMethod = null;
      if (indicator.getAggregation() == IndicatorDTO.AGGREGATE_AVG)
        aggrMethod = data.getLocalizedVersion("average");
      else aggrMethod = data.getLocalizedVersion("sum");
      putBasicInfo(
          tableEx,
          ++rowIndex,
          data.getLocalizedVersion("aggregationMethod"),
          aggrMethod,
          numbOfCols);
      // units
      putBasicInfo(
          tableEx, ++rowIndex, data.getLocalizedVersion("units"), indicator.getUnits(), numbOfCols);

      // target value
      putBasicInfo(
          tableEx,
          ++rowIndex,
          data.getLocalizedVersion("targetValue"),
          indicator.getObjective(),
          numbOfCols);
    }

    // source of ver
    putBasicInfo(
        tableEx,
        ++rowIndex,
        data.getLocalizedVersion("sourceOfVerification"),
        indicator.getSourceOfVerification(),
        numbOfCols);

    // comment
    putBasicInfo(
        tableEx,
        ++rowIndex,
        data.getLocalizedVersion("indicatorComments"),
        indicator.getDescription(),
        numbOfCols);

    // value
    putBasicInfo(
        tableEx,
        ++rowIndex,
        data.getLocalizedVersion("value"),
        data.getFormattedValue(indicator),
        numbOfCols);
    // empty row
    CalcUtils.putEmptyRow(tableEx, ++rowIndex);

    row = tableEx.getRowByIndex(rowIndex);
    row.getCellByIndex(1).setCellStyleName(null);
    row.getCellByIndex(2).setCellStyleName(null);
    row.getCellByIndex(3).setCellStyleName(null);
    row.getCellByIndex(4).setCellStyleName(null);

    // data entry
    // header
    row = tableEx.getRowByIndex(++rowIndex);
    int cellIndex = 0;
    CalcUtils.putHeader(row, ++cellIndex, data.getLocalizedVersion("sideAndMonth"));
    Map<String, Integer> columnIndexMap = new HashMap<String, Integer>();
    for (PivotTableData.Axis axis : leaves) {
      CalcUtils.putHeader(row, ++cellIndex, axis.getLabel());
      columnIndexMap.put(axis.getLabel(), cellIndex);
    }

    // rows
    for (PivotTableData.Axis axis :
        data.getEntryMap().get(indicator.getId()).getRootRow().getChildren()) {
      row = tableEx.getRowByIndex(++rowIndex);
      CalcUtils.putHeader(row, 1, axis.getLabel());
      // populate empty cells
      for (int i = 0; i < numbOfLeaves; i++) {
        cell = CalcUtils.createBasicCell(tableEx, i + 2, rowIndex, "");
      }

      // insert values
      for (Map.Entry<PivotTableData.Axis, PivotTableData.Cell> entry : axis.getCells().entrySet()) {
        cellIndex = columnIndexMap.get(entry.getKey().getLabel());
        Object value = null;
        boolean rightAligned = false;
        if (isQualitative) {
          value = data.getLabelByIndex(indicator.getLabels(), entry.getValue().getValue());
        } else {
          value = new Long(Math.round(entry.getValue().getValue()));
          rightAligned = true;
        }
        putValueCell(tableEx, rowIndex, cellIndex, value, rightAligned);
      }
    }
    // col width
    tableEx.getColumnByIndex(0).setWidth(3.8);
    tableEx.getColumnByIndex(1).setWidth(60);
    for (int i = 2; i < 2 + numbOfLeaves; i++) {
      tableEx.getColumnByIndex(i).setWidth(30);
    }
  }
Ejemplo n.º 5
0
 private Object getCellValue(Cell varCell) {
   Object cellValue = null;
   if ("boolean".equals(varCell.getValueType())) {
     // Boolean
     cellValue = varCell.getBooleanValue();
   } else if ("time".equals(varCell.getValueType())) {
     // Date
     cellValue = varCell.getTimeValue().getTime();
   } else if ("date".equals(varCell.getValueType())) {
     // Date
     cellValue = varCell.getDateValue().getTime();
   } else if ("float".equals(varCell.getValueType())) {
     // Double
     cellValue = varCell.getDoubleValue();
   } else if ("percentage".equals(varCell.getValueType())) {
     // Double
     cellValue = varCell.getPercentageValue();
   } else if ("currency".equals(varCell.getValueType())) {
     // String
     cellValue = varCell.getCurrencyCode();
   } else {
     // String
     cellValue = varCell.getStringValue();
   }
   return cellValue;
 }