/** * Generar un nombre de archivo a grabar en el directorio temporal del usuario y asignarlo al * fileName del report. * * @return */ public String generateFileNameTmp() { // Purgar directorio de ficheros temporales generados por gana con 2 // horas de diferencia File dir = new File(EnvironmentVariables.getUserTmp()); if (dir.list().length > 0) { for (String filename : dir.list()) { if (filename.indexOf("gana_tmp_") > -1) { File file = new File(EnvironmentVariables.getUserTmp() + filename); Date d = new Date(file.lastModified()); if (DateUtils.getDiffHoursDates(d, new Date()) > 1) { file.delete(); } } } } fileName = EnvironmentVariables.getUserTmp() + "gana_tmp_report_" + SystemUtils.getIdDocument() + ".xls"; if (excel != null) excel.setFileName(fileName); return fileName; }
/** Ajustar las propiedades de las hojas. */ protected void configPage() { HSSFSheet sheet = getExcel().getActiveSheet(); HSSFPrintSetup ps = sheet.getPrintSetup(); // Repetir filas y columnas. if (isRepeatingRows() && repeatingRowsCount > -1) excel.setRepeatingRows(0, repeatingRowsCount); // if (isRepeatingColumns() && repeatingColumnsCount > -1) // excel.setRepeatingColumns(0, repeatingColumnsCount); sheet.setDisplayGridlines(false); // Dejar fijo un conjuto filas o/y columnas // sheet.createFreezePane( 0, 3 ); // deja fijas las 3 primeras filas. // sheet.createFreezePane( 1, 0, 1, 0 ); // deja fija la primera // columna. // Create a split with the lower left side being the active quadrant // sheet.createSplitPane( 2000, 2000, 0, 0, HSSFSheet.PANE_LOWER_LEFT ); // margen bottom de la hoja 0.6 = 1.5 en Excel (para que no se solapen // las filas con el footer) sheet.setMargin((short) 3, 0.6); // marcar el radiobutton de ajustar a la página sheet.setAutobreaks(true); // excel.setColumnWidth(2, 30); // ajustar a la página 1 a 500 páginas. // excel.setFitToPage(); // sheet.setVerticallyCenter(true); ps.setFitWidth((short) 1); ps.setFitHeight((short) 500); // horizontal ps.setLandscape(landscape); if (header.hasRightLogo()) excel.getActiveSheet().setMargin(HSSFSheet.RightMargin, 0); // Crear agrupaciones de filas o columnas. // sheet.groupRow((short)3,(short)5); // sheet.setRowGroupCollapsed((short)3, true); }
/** Configurar el ancho de las columnas con respecto a la información de las celdas. */ protected void configColumns() { // configurar el ancho de las columnas de los grupos. for (int i = 0; i < groups.size(); i++) if (showDetail) getExcel().setColumnWidthCharacters(i, (i + 2)); else getExcel().setColumnWidth(i, ((ReportGroup) groups.get(i)).getMaxWidth()); // configurar el ancho de las columnas de los campos. int cont = 0; for (int i = 0; i < fields.size(); i++) { // excel.autoSizeColumn((short)i); ReportField field = ((ReportField) fields.get(i)); if (field.isVisible()) { if (field.getDisplayWidth() > 0) { getExcel().setColumnWidthCharacters(getInitColumnIndex() + cont, field.getDisplayWidth()); } else { // Formateo de la primera columna para evita tomar el ancho // del título y desajustar el informe. // if (cont == getInitColumnIndex()) { // double pixels = field.getMaxWidthPixels(); // // Ampliar el ancho de la columna si tiene un campo a // totalizar. // if // (getTotalFields().getReportTotalField(field.getFieldName()) // != null) // pixels += 2; // getExcel().setColumnWidthCharacters(getInitColumnIndex() // + cont, pixels); // } // else getExcel().autoSizeColumn(getInitColumnIndex() + cont); } ++cont; } } // Ajustar de nuevo la fila con el máximo tamaño calculado con los // valores contenidos en sus campos ya que al realizar el autosize del // paso anterior // la columna 0 se ajusta con el título y queda desproporcionada el // campo 1. // if (groups.size() == 0) { // if (fields.size() > 0) { // getExcel().setColumnWidthCharacters(0, // fields.get(0).getMaxWidthPixels()); // } // } // Merge de celdas para el título hasta completar todos los campos // mostrados en el informe. if (cont > 1 && header.hasLogos()) { if (header.getTitleRow() > -1) excel.mergeCells( header.getTitleRow(), getInitColumnIndex(), header.getTitleRow(), getInitColumnIndex() + cont - 1); if (header.getSubtitleRow() > -1) excel.mergeCells( header.getSubtitleRow(), getInitColumnIndex(), header.getSubtitleRow(), getInitColumnIndex() + cont - 1); } // Logos try { // Altura de filas de cabecera excel.setRowHeight(header.getTitleRow(), 400); if (header.getSubtitleRow() > -1) excel.setRowHeight(header.getSubtitleRow(), 400); header.generateLogos(); } catch (Exception e) { e.printStackTrace(); } }