Exemplo n.º 1
0
  /** Escribir el fichero Excel. */
  public void writeFile() throws Exception {

    if (StringUtils.isEmpty(fileName)) {
      generateFileNameTmp();
    }
    getExcel().writeFile();
  }
Exemplo n.º 2
0
 /** Mostrar el archivo en pantalla. */
 public void show() throws Exception {
   if (!StringUtils.isEmpty(fileName)) {
     if (new File(fileName).exists()) {
       DesktopUtils.openFile(fileName);
     } else throw new Exception("File " + fileName + " not found");
   }
 }
Exemplo n.º 3
0
  /**
   * Ejecutar el informe.
   *
   * @throws Exception
   */
  public void execute(boolean writeFile) throws Exception {

    if (object == null) throw new JavaLegoException("Not exist object", JavaLegoException.WARNING);

    // Generar el nombre del fichero xls temporal.
    if (excel.getFileName() == null && StringUtils.isEmpty(fileName)) {
      fileName = generateFileNameTmp();
      excel.setFileName(fileName);
    }

    // Inicializar posición de la fila y columna.
    rowIndex = -1;
    columnIndex = 0;

    header.generate();

    writeSections();

    writeFooter();

    configColumns();

    configPage();

    if (writeFile) writeFile();
  }
Exemplo n.º 4
0
 @Override
 public void setConvertedValue(Object newValue) {
   super.setConvertedValue(
       newValue instanceof Double
           ? StringUtils.toString(((Double) newValue).intValue())
           : newValue);
 }
Exemplo n.º 5
0
  /** Escribir el píe del informe. */
  protected void writeFooter() {

    HSSFSheet sheet = getExcel().getActiveSheet();
    HSSFFooter footer = sheet.getFooter();

    if (showDate) footer.setLeft("Date " + HSSFFooter.date());

    if (!StringUtils.isEmpty(textFooter)) footer.setCenter(textFooter);
  }
Exemplo n.º 6
0
  /** Escribir el píe del informe. */
  protected void writeFooter() {

    HSSFSheet sheet = getExcel().getActiveSheet();
    HSSFFooter footer = sheet.getFooter();

    if (showDate) footer.setLeft("Date " + HSSFFooter.date());

    if (!StringUtils.isEmpty(textFooter)) footer.setCenter(textFooter);

    if (showNumberPages)
      footer.setRight("Pages: " + HSSFFooter.page() + " - " + HSSFFooter.numPages()); // .,.r
  }
Exemplo n.º 7
0
  /** Traducir el token con la información contenida en el adoEditor. */
  public String translateToken(String token, String value) throws Exception {

    // Datos del ado.
    if (token.equals(TOKEN_FIELD) && field != null) {

      Object object = field.getReport().getFieldValue(field.getReport().getActualObject(), value);
      if (object instanceof String) return StringUtils.getSingleQuotedStr(object.toString());
      else if (object != null) return object.toString();
      else return "";
    }
    return null;
  }
Exemplo n.º 8
0
  /** Configurar el ancho de las columnas con respecto a la información de las celdas. */
  protected void configColumns() {

    excel.setColumnWidth(0, 1);

    // Ajustar todas las columnas
    for (int i = 1; i < getColumnIndex() + 1; i++) {
      excel.autoSizeColumn((short) i);
    }

    // Ajusta secciones y grupos con títulos.
    for (int i = 0; i < sections.size(); i++) {

      if (!StringUtils.isEmpty(sections.get(i).getTitle())) {
        excel.setColumnWidth(sections.get(i).getColumnIndex(), 1);
      }

      for (int k = 0; k < sections.get(i).getGroups().size(); k++) {

        if (!StringUtils.isEmpty(sections.get(i).getGroups().get(k).getTitle())) {
          excel.setColumnWidth(sections.get(i).getGroups().get(k).getColumnndex(), 1);
        }
      }
    }
  }