Ejemplo n.º 1
0
  private static void toPdfInternal(Grid grid, Document document, float spacing) {
    if (grid == null || grid.getVisibleWidth() == 0) {
      return;
    }

    PdfPTable table = new PdfPTable(grid.getVisibleWidth());

    table.setHeaderRows(1);
    table.setWidthPercentage(100F);
    table.setKeepTogether(false);
    table.setSpacingAfter(spacing);

    table.addCell(
        resetPaddings(getTitleCell(grid.getTitle(), grid.getVisibleWidth()), 0, 30, 0, 0));

    if (StringUtils.isNotEmpty(grid.getSubtitle())) {
      table.addCell(getSubtitleCell(grid.getSubtitle(), grid.getVisibleWidth()));
      table.addCell(getEmptyCell(grid.getVisibleWidth(), 30));
    }

    for (GridHeader header : grid.getVisibleHeaders()) {
      table.addCell(getItalicCell(header.getName()));
    }

    table.addCell(getEmptyCell(grid.getVisibleWidth(), 10));

    for (List<Object> row : grid.getVisibleRows()) {
      for (Object col : row) {
        table.addCell(getTextCell(col));
      }
    }

    addTableToDocument(document, table);
  }
Ejemplo n.º 2
0
  private static void toXlsInternal(
      Grid grid, WritableWorkbook workbook, String sheetName, int sheetNo) throws Exception {
    if (grid == null) {
      return;
    }

    WritableSheet sheet = workbook.createSheet(sheetName, sheetNo);

    int rowNumber = 1;

    int columnIndex = 0;

    if (StringUtils.isNotEmpty(grid.getTitle())) {
      sheet.addCell(new Label(0, rowNumber++, grid.getTitle(), XLS_FORMAT_TTTLE));
      rowNumber++;
    }

    if (StringUtils.isNotEmpty(grid.getSubtitle())) {
      sheet.addCell(new Label(0, rowNumber++, grid.getSubtitle(), XLS_FORMAT_TTTLE));
      rowNumber++;
    }

    for (GridHeader header : grid.getVisibleHeaders()) {
      sheet.addCell(new Label(columnIndex++, rowNumber, header.getName(), XLS_FORMAT_LABEL));
    }

    rowNumber++;

    for (List<Object> row : grid.getVisibleRows()) {
      columnIndex = 0;

      for (Object column : row) {
        if (column != null && MathUtils.isNumeric(String.valueOf(column))) {
          sheet.addCell(
              new Number(
                  columnIndex++,
                  rowNumber,
                  Double.valueOf(String.valueOf(column)),
                  XLS_FORMAT_TEXT));
        } else {
          String content = column != null ? String.valueOf(column) : EMPTY;

          sheet.addCell(new Label(columnIndex++, rowNumber, content, XLS_FORMAT_TEXT));
        }
      }

      rowNumber++;
    }
  }
Ejemplo n.º 3
0
  /** Writes an XML representation of the given Grid to the given OutputStream. */
  public static void toXml(Grid grid, OutputStream out) {
    XMLWriter writer = XMLFactory.getXMLWriter(out);

    writer.openDocument();
    writer.openElement(
        ATTR_GRID,
        ATTR_TITLE,
        grid.getTitle(),
        ATTR_SUBTITLE,
        grid.getSubtitle(),
        ATTR_WIDTH,
        String.valueOf(grid.getWidth()),
        ATTR_HEIGHT,
        String.valueOf(grid.getHeight()));

    writer.openElement(ATTR_HEADERS);

    for (GridHeader header : grid.getHeaders()) {
      writer.writeElement(
          ATTR_HEADER,
          null,
          ATTR_NAME,
          header.getName(),
          ATTR_COLUMN,
          header.getColumn(),
          ATTR_TYPE,
          header.getType(),
          ATTR_HIDDEN,
          String.valueOf(header.isHidden()),
          ATTR_META,
          String.valueOf(header.isMeta()));
    }

    writer.closeElement();
    writer.openElement(ATTR_ROWS);

    for (List<Object> row : grid.getRows()) {
      writer.openElement(ATTR_ROW);

      for (Object field : row) {
        writer.writeElement(ATTR_FIELD, field != null ? String.valueOf(field) : EMPTY);
      }

      writer.closeElement();
    }

    writer.closeElement();
    writer.closeElement();

    writer.closeDocument();
  }