List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle setAlignment
@Override public void setAlignment(HorizontalAlignment align)
From source file:neg.JRViewerComercial.java
License:Open Source License
private static void crearCabeceraHojaExcel(HSSFWorkbook libro, HSSFSheet hoja) { HSSFRow fila = null;//from ww w . j av a2 s. c om HSSFCell celda = null; // Modificamos la fuente por defecto para que salga en negrita HSSFCellStyle cs = libro.createCellStyle(); HSSFFont f = libro.createFont(); f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); f.setColor(HSSFColor.WHITE.index); cs.setFont(f); //cs.setFillBackgroundColor(HSSFColor.GREEN.index); cs.setFillForegroundColor(HSSFColor.GREEN.index); cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cs.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); cs.setBottomBorderColor(HSSFColor.BLACK.index); cs.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); cs.setLeftBorderColor(HSSFColor.BLACK.index); cs.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); cs.setRightBorderColor(HSSFColor.BLACK.index); cs.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); cs.setTopBorderColor(HSSFColor.BLACK.index); cs.setAlignment(HSSFCellStyle.ALIGN_CENTER); // Creamos la cabecera de las columnas fila = hoja.createRow(0); celda = fila.createCell((short) 0); celda.setCellStyle(cs); HSSFRichTextString texto = new HSSFRichTextString("CLIENTE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 0, (short) ((220 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 1); celda.setCellStyle(cs); texto = new HSSFRichTextString("ENERO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 1, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 2); celda.setCellStyle(cs); texto = new HSSFRichTextString("FEBRERO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 2, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 3); celda.setCellStyle(cs); texto = new HSSFRichTextString("MARZO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 3, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 4); celda.setCellStyle(cs); texto = new HSSFRichTextString("ABRIL"); celda.setCellValue(texto); hoja.setColumnWidth((short) 4, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 5); celda.setCellStyle(cs); texto = new HSSFRichTextString("MAYO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 5, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 6); celda.setCellStyle(cs); texto = new HSSFRichTextString("JUNIO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 6, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 7); celda.setCellStyle(cs); texto = new HSSFRichTextString("JULIO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 7, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 8); celda.setCellStyle(cs); texto = new HSSFRichTextString("AGOSTO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 8, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 9); celda.setCellStyle(cs); texto = new HSSFRichTextString("SEPTIEMBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 9, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 10); celda.setCellStyle(cs); texto = new HSSFRichTextString("OCTUBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 10, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 11); celda.setCellStyle(cs); texto = new HSSFRichTextString("NOVIEMBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 11, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 12); celda.setCellStyle(cs); texto = new HSSFRichTextString("DICIEMBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 12, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 13); celda.setCellStyle(cs); texto = new HSSFRichTextString("IMPORTE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 13, (short) ((90 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 14); celda.setCellStyle(cs); texto = new HSSFRichTextString("MARGEN"); celda.setCellValue(texto); hoja.setColumnWidth((short) 14, (short) ((90 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 15); celda.setCellStyle(cs); texto = new HSSFRichTextString("MARGEN %"); celda.setCellValue(texto); hoja.setColumnWidth((short) 15, (short) ((90 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 16); celda.setCellStyle(cs); texto = new HSSFRichTextString("M.G. PEDIDO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 16, (short) ((90 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 17); celda.setCellStyle(cs); texto = new HSSFRichTextString("NM.PEDIDOS"); celda.setCellValue(texto); hoja.setColumnWidth((short) 17, (short) ((90 * 2) / ((double) 1 / 20))); }
From source file:neg.JRViewerComercialProveedor.java
License:Open Source License
private void btnExcelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcelActionPerformed String queryInf = this.jasperPrint.getProperty("query"); try {//from w w w . jav a 2 s . co m // Se crea el libro excel HSSFWorkbook libro = new HSSFWorkbook(); //Se crea la hoja HSSFSheet hoja = libro.createSheet("Informe"); //Numero de fila de la hoja Excel int num_fila = 1; crearCabeceraHojaExcel(libro, hoja); HSSFCellStyle cs2 = libro.createCellStyle(); cs2.setAlignment(HSSFCellStyle.ALIGN_LEFT); cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs2.setBottomBorderColor(HSSFColor.BLACK.index); cs2.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs2.setLeftBorderColor(HSSFColor.BLACK.index); cs2.setBorderRight(HSSFCellStyle.BORDER_THIN); cs2.setRightBorderColor(HSSFColor.BLACK.index); cs2.setBorderTop(HSSFCellStyle.BORDER_THIN); cs2.setTopBorderColor(HSSFColor.BLACK.index); HSSFCellStyle cs3 = libro.createCellStyle(); HSSFDataFormat format = libro.createDataFormat(); cs3.setAlignment(HSSFCellStyle.ALIGN_RIGHT); cs3.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs3.setBottomBorderColor(HSSFColor.BLACK.index); cs3.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs3.setLeftBorderColor(HSSFColor.BLACK.index); cs3.setBorderRight(HSSFCellStyle.BORDER_THIN); cs3.setRightBorderColor(HSSFColor.BLACK.index); cs3.setBorderTop(HSSFCellStyle.BORDER_THIN); cs3.setTopBorderColor(HSSFColor.BLACK.index); cs3.setDataFormat(format.getFormat("#,##0")); //Datos ResultSet rs = CSDesktop.datos.select(queryInf); crearFilaHojaExcel(libro, hoja, num_fila, rs, cs2, cs3); FileOutputStream elFichero = null; elFichero = new FileOutputStream("c:\\AplicacionCarSet\\informe_comercial_proveedor.xls"); libro.write(elFichero); elFichero.close(); elFichero.flush(); String property = "java.io.tmpdir"; String tempDir = System.getProperty(property); System.out.println("OS current temporary directory is " + tempDir); String file = new String("C:\\AplicacionCarSet\\informe_comercial_proveedor.xls"); Process p = Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); } catch (SQLException ex) { Logger.getLogger(CSResultBuscarPedidoNew.class.getName()).log(Level.SEVERE, null, ex); } catch (UnknownHostException ex) { Logger.getLogger(CSResultBuscarPedidoNew.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CSResultBuscarPedidoNew.class.getName()).log(Level.SEVERE, null, ex); } //System.out.println("Vamoooooos: "+queryInf); }
From source file:neg.JRViewerComercialProveedor.java
License:Open Source License
private static void crearCabeceraHojaExcel(HSSFWorkbook libro, HSSFSheet hoja) { HSSFRow fila = null;/*from w ww. ja v a 2s.c om*/ HSSFCell celda = null; // Modificamos la fuente por defecto para que salga en negrita HSSFCellStyle cs = libro.createCellStyle(); HSSFFont f = libro.createFont(); f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); f.setColor(HSSFColor.WHITE.index); cs.setFont(f); //cs.setFillBackgroundColor(HSSFColor.GREEN.index); cs.setFillForegroundColor(HSSFColor.GREEN.index); cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cs.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); cs.setBottomBorderColor(HSSFColor.BLACK.index); cs.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); cs.setLeftBorderColor(HSSFColor.BLACK.index); cs.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); cs.setRightBorderColor(HSSFColor.BLACK.index); cs.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); cs.setTopBorderColor(HSSFColor.BLACK.index); cs.setAlignment(HSSFCellStyle.ALIGN_CENTER); // Creamos la cabecera de las columnas fila = hoja.createRow(0); celda = fila.createCell((short) 0); celda.setCellStyle(cs); HSSFRichTextString texto = new HSSFRichTextString("PROVEEDOR"); celda.setCellValue(texto); hoja.setColumnWidth((short) 0, (short) ((220 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 1); celda.setCellStyle(cs); texto = new HSSFRichTextString("ENERO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 1, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 2); celda.setCellStyle(cs); texto = new HSSFRichTextString("FEBRERO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 2, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 3); celda.setCellStyle(cs); texto = new HSSFRichTextString("MARZO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 3, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 4); celda.setCellStyle(cs); texto = new HSSFRichTextString("ABRIL"); celda.setCellValue(texto); hoja.setColumnWidth((short) 4, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 5); celda.setCellStyle(cs); texto = new HSSFRichTextString("MAYO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 5, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 6); celda.setCellStyle(cs); texto = new HSSFRichTextString("JUNIO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 6, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 7); celda.setCellStyle(cs); texto = new HSSFRichTextString("JULIO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 7, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 8); celda.setCellStyle(cs); texto = new HSSFRichTextString("AGOSTO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 8, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 9); celda.setCellStyle(cs); texto = new HSSFRichTextString("SEPTIEMBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 9, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 10); celda.setCellStyle(cs); texto = new HSSFRichTextString("OCTUBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 10, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 11); celda.setCellStyle(cs); texto = new HSSFRichTextString("NOVIEMBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 11, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 12); celda.setCellStyle(cs); texto = new HSSFRichTextString("DICIEMBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 12, (short) ((70 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 13); celda.setCellStyle(cs); texto = new HSSFRichTextString("IMPORTE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 13, (short) ((90 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 14); celda.setCellStyle(cs); texto = new HSSFRichTextString("% TURISMOS"); celda.setCellValue(texto); hoja.setColumnWidth((short) 14, (short) ((90 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 15); celda.setCellStyle(cs); texto = new HSSFRichTextString("% FUNCIONAN"); celda.setCellValue(texto); hoja.setColumnWidth((short) 15, (short) ((90 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 16); celda.setCellStyle(cs); texto = new HSSFRichTextString("%GRA UNITARIA"); celda.setCellValue(texto); hoja.setColumnWidth((short) 16, (short) ((90 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 17); celda.setCellStyle(cs); texto = new HSSFRichTextString("NM.PEDIDOS"); celda.setCellValue(texto); hoja.setColumnWidth((short) 17, (short) ((90 * 2) / ((double) 1 / 20))); }
From source file:neg.JRViewerInformeUnitario.java
License:Open Source License
private void btnExcelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcelActionPerformed String queryInf = this.jasperPrint.getProperty("query"); try {/* w w w. j a va2 s. co m*/ // Se crea el libro excel HSSFWorkbook libro = new HSSFWorkbook(); //Se crea la hoja HSSFSheet hoja = libro.createSheet("Informe"); //Numero de fila de la hoja Excel int num_fila = 1; crearCabeceraHojaExcel(libro, hoja); HSSFCellStyle cs2 = libro.createCellStyle(); cs2.setAlignment(HSSFCellStyle.ALIGN_CENTER); cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs2.setBottomBorderColor(HSSFColor.BLACK.index); cs2.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs2.setLeftBorderColor(HSSFColor.BLACK.index); cs2.setBorderRight(HSSFCellStyle.BORDER_THIN); cs2.setRightBorderColor(HSSFColor.BLACK.index); cs2.setBorderTop(HSSFCellStyle.BORDER_THIN); cs2.setTopBorderColor(HSSFColor.BLACK.index); HSSFCellStyle cs3 = libro.createCellStyle(); cs3.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs3.setBottomBorderColor(HSSFColor.BLACK.index); cs3.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs3.setLeftBorderColor(HSSFColor.BLACK.index); cs3.setBorderRight(HSSFCellStyle.BORDER_THIN); cs3.setRightBorderColor(HSSFColor.BLACK.index); cs3.setBorderTop(HSSFCellStyle.BORDER_THIN); cs3.setTopBorderColor(HSSFColor.BLACK.index); ResultSet rs = CSDesktop.datos.select(queryInf); crearFilaHojaExcel(libro, hoja, num_fila, rs, cs2, cs3); FileOutputStream elFichero = null; elFichero = new FileOutputStream("c:\\informe_unitario.xls"); libro.write(elFichero); elFichero.close(); elFichero.flush(); String property = "java.io.tmpdir"; String tempDir = System.getProperty(property); System.out.println("OS current temporary directory is " + tempDir); String file = new String("C:\\informe_unitario.xls"); Process p = Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file); } catch (SQLException ex) { Logger.getLogger(CSResultBuscarPedidoNew.class.getName()).log(Level.SEVERE, null, ex); } catch (UnknownHostException ex) { Logger.getLogger(CSResultBuscarPedidoNew.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CSResultBuscarPedidoNew.class.getName()).log(Level.SEVERE, null, ex); } //System.out.println("Vamoooooos: "+queryInf); }
From source file:neg.JRViewerInformeUnitario.java
License:Open Source License
private static void crearCabeceraHojaExcel(HSSFWorkbook libro, HSSFSheet hoja) { HSSFRow fila = null;/*from w w w . j av a 2s. c o m*/ HSSFCell celda = null; // Modificamos la fuente por defecto para que salga en negrita HSSFCellStyle cs = libro.createCellStyle(); HSSFFont f = libro.createFont(); f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); f.setColor(HSSFColor.WHITE.index); cs.setFont(f); //cs.setFillBackgroundColor(HSSFColor.GREEN.index); cs.setFillForegroundColor(HSSFColor.GREEN.index); cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cs.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); cs.setBottomBorderColor(HSSFColor.BLACK.index); cs.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); cs.setLeftBorderColor(HSSFColor.BLACK.index); cs.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); cs.setRightBorderColor(HSSFColor.BLACK.index); cs.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); cs.setTopBorderColor(HSSFColor.BLACK.index); cs.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Creamos la cabecera de las columnas fila = hoja.createRow(0); celda = fila.createCell((short) 0); celda.setCellStyle(cs); HSSFRichTextString texto = new HSSFRichTextString("DATOS"); celda.setCellValue(texto); hoja.setColumnWidth((short) 0, (short) ((60 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 1); celda.setCellStyle(cs); texto = new HSSFRichTextString("ENERO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 1, (short) ((60 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 2); celda.setCellStyle(cs); texto = new HSSFRichTextString("FEBRERO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 2, (short) ((80 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 3); celda.setCellStyle(cs); texto = new HSSFRichTextString("MARZO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 3, (short) ((200 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 4); celda.setCellStyle(cs); texto = new HSSFRichTextString("ABRIL"); celda.setCellValue(texto); hoja.setColumnWidth((short) 4, (short) ((130 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 5); celda.setCellStyle(cs); texto = new HSSFRichTextString("MAYO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 5, (short) ((60 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 6); celda.setCellStyle(cs); texto = new HSSFRichTextString("JUNIO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 6, (short) ((130 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 7); celda.setCellStyle(cs); texto = new HSSFRichTextString("JULIO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 7, (short) ((60 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 8); celda.setCellStyle(cs); texto = new HSSFRichTextString("AGOSTO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 8, (short) ((80 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 9); celda.setCellStyle(cs); texto = new HSSFRichTextString("SEPTIEMBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 9, (short) ((40 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 10); celda.setCellStyle(cs); texto = new HSSFRichTextString("OCTUBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 10, (short) ((120 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 11); celda.setCellStyle(cs); texto = new HSSFRichTextString("NOVIEMBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 11, (short) ((110 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 12); celda.setCellStyle(cs); texto = new HSSFRichTextString("DICIEMBRE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 12, (short) ((130 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 13); celda.setCellStyle(cs); texto = new HSSFRichTextString("M.G."); celda.setCellValue(texto); hoja.setColumnWidth((short) 13, (short) ((130 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 14); celda.setCellStyle(cs); texto = new HSSFRichTextString("M.G. PEDIDO"); celda.setCellValue(texto); hoja.setColumnWidth((short) 14, (short) ((130 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 15); celda.setCellStyle(cs); texto = new HSSFRichTextString("NUM.PEDIDOS"); celda.setCellValue(texto); hoja.setColumnWidth((short) 15, (short) ((40 * 2) / ((double) 1 / 20))); celda = fila.createCell((short) 16); celda.setCellStyle(cs); texto = new HSSFRichTextString("IMPORTE"); celda.setCellValue(texto); hoja.setColumnWidth((short) 16, (short) ((200 * 2) / ((double) 1 / 20))); }
From source file:net.chaosserver.timelord.data.ExcelDataReaderWriter.java
License:Open Source License
/** * Builds a map of style name to HSSFCellStyle objects that can be used to * mark cells with similar styles.// ww w . j ava2s. c om * * @param wb the workbook needed to create the objects * @return the map of styles */ protected Map<String, HSSFCellStyle> buildStyleMap(HSSFWorkbook wb) { Map<String, HSSFCellStyle> styleMap = new HashMap<String, HSSFCellStyle>(); HSSFCellStyle style; HSSFFont font; style = wb.createCellStyle(); font = wb.createFont(); // font.setItalic(true); font.setColor((short) 0xc); // blue style.setFont(font); styleMap.put("taskNoteStyle", style); style = wb.createCellStyle(); font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); style.setFont(font); style.setBorderLeft(HSSFCellStyle.BORDER_DOUBLE); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); styleMap.put("taskNameHeaderStyle", style); style = wb.createCellStyle(); style.setBorderLeft(HSSFCellStyle.BORDER_DOUBLE); styleMap.put("taskNameStyle", style); style = wb.createCellStyle(); style.setBorderTop(HSSFCellStyle.BORDER_DOUBLE); style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); styleMap.put("topRowStyle", style); style = wb.createCellStyle(); style.setBorderTop(HSSFCellStyle.BORDER_DOUBLE); style.setBorderLeft(HSSFCellStyle.BORDER_DOUBLE); styleMap.put("topLeftStyle", style); style = wb.createCellStyle(); style.setBorderTop(HSSFCellStyle.BORDER_DOUBLE); style.setBorderRight(HSSFCellStyle.BORDER_DOUBLE); styleMap.put("topRightStyle", style); style = wb.createCellStyle(); font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); style.setFont(font); style.setBorderRight(HSSFCellStyle.BORDER_DOUBLE); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); styleMap.put("totalHeaderStyle", style); style = wb.createCellStyle(); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_DOUBLE); styleMap.put("totalColumnStyle", style); style = wb.createCellStyle(); style.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setFont(font); styleMap.put("boldDateStyle", style); style = wb.createCellStyle(); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE); style.setBorderLeft(HSSFCellStyle.BORDER_DOUBLE); styleMap.put("bottomLeftStyle", style); style = wb.createCellStyle(); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_DOUBLE); styleMap.put("bottomRightStyle", style); style = wb.createCellStyle(); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE); styleMap.put("bottomStyle", style); return styleMap; }
From source file:net.mindengine.oculus.frontend.service.report.ExcelTestSearchReportGenerator.java
License:Open Source License
/** * Generates Excel spreadsheet.//ww w. j av a2 s . c o m * * @param searchResult Search result for test or document (test-case) * @throws Exception */ public void writeExcelReports(BrowseResult<?> searchResult, Long projectId, HttpServletRequest request, HttpServletResponse response) throws Exception { int cellOffset = 5; /* * Customizations which will be exported to XLS spreadsheet. */ Collection<Customization> customizationsExport = new LinkedList<Customization>(); /* * Here will be cell ids stored for each customization. This is needed because there might be a lot of merged cells for list customizations */ Map<Long, Integer> customizationCells = new HashMap<Long, Integer>(); if (projectId != null && projectId > 0) { Collection<Customization> customizations = customizationDAO.getCustomizations(projectId, unit); for (Customization customization : customizations) { //Checking if the user has selected this specific customization for exporting if ("on".equals(request.getParameter("cexport" + customization.getId()))) { customizationCells.put(customization.getId(), cellOffset); //Checking if the customization contains possible values and fetching them all if (customization.getType().equals(Customization.TYPE_CHECKLIST) || customization.getType().equals(Customization.TYPE_LIST)) { customization.setPossibleValues( customizationDAO.getCustomizationPossibleValues(customization.getId())); cellOffset += customization.getPossibleValues().size(); } else { cellOffset += 1; } customizationsExport.add(customization); } } } /* * Generating the Excel spreadsheet */ OutputStream outputStream = response.getOutputStream(); response.setContentType("application/ms-excel"); HSSFWorkbook workBook = new HSSFWorkbook(); HSSFSheet sheet = workBook.createSheet(); HSSFFont fontHeader = workBook.createFont(); fontHeader.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); fontHeader.setColor(HSSFColor.WHITE.index); HSSFCellStyle columnHeaderStyle = workBook.createCellStyle(); columnHeaderStyle.setBorderTop((short) 2); columnHeaderStyle.setBorderLeft((short) 2); columnHeaderStyle.setBorderRight((short) 2); columnHeaderStyle.setBorderBottom((short) 2); columnHeaderStyle.setFillForegroundColor(HSSFColor.GREY_50_PERCENT.index); columnHeaderStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); columnHeaderStyle.setFont(fontHeader); HSSFCellStyle columnRootHeaderStyle = workBook.createCellStyle(); //columnRootHeaderStyle.cloneStyleFrom(columnHeaderStyle); columnRootHeaderStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFCell cell; HSSFRow headerRow = sheet.createRow(0); HSSFRow header2Row = sheet.createRow(1); sheet.addMergedRegion(new Region((short) 0, (short) 0, (short) 0, (short) 4)); cell = headerRow.createCell((short) 0); cell.setCellValue("Common"); cell.setCellStyle(columnRootHeaderStyle); cell = header2Row.createCell((short) 0); cell.setCellValue("Test"); cell.setCellStyle(columnHeaderStyle); cell = header2Row.createCell((short) 1); cell.setCellValue("Project"); cell.setCellStyle(columnHeaderStyle); cell = header2Row.createCell((short) 2); cell.setCellValue("Sub-Project"); cell.setCellStyle(columnHeaderStyle); cell = header2Row.createCell((short) 3); cell.setCellValue("Author"); cell.setCellStyle(columnHeaderStyle); cell = header2Row.createCell((short) 4); cell.setCellValue("Created"); cell.setCellStyle(columnHeaderStyle); for (Customization customization : customizationsExport) { int cellId = customizationCells.get(customization.getId()); if (customization.getPossibleValues() != null) { int size = customization.getPossibleValues().size(); if (size > 1) { sheet.addMergedRegion( new Region((short) 0, (short) 0, (short) cellId, (short) (cellId + size - 1))); } /* * Exporting possible values */ int offset = 0; for (CustomizationPossibleValue cpv : customization.getPossibleValues()) { cell = header2Row.createCell((short) (cellId + offset)); cell.setCellValue(cpv.getPossibleValue()); cell.setCellStyle(columnHeaderStyle); offset++; } } else { cell = header2Row.createCell((short) cellId); cell.setCellStyle(columnHeaderStyle); } cell = headerRow.createCell((short) cellId); cell.setCellValue(customization.getName()); cell.setCellStyle(columnRootHeaderStyle); } HSSFCellStyle cellStyle = workBook.createCellStyle(); HSSFCellStyle checkboxStyle = workBook.createCellStyle(); checkboxStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index); checkboxStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); checkboxStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFFont fontCheckbox = workBook.createFont(); fontCheckbox.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); fontCheckbox.setColor(HSSFColor.BLACK.index); checkboxStyle.setFont(fontCheckbox); HSSFCellStyle boolYesStyle = workBook.createCellStyle(); boolYesStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index); boolYesStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFCellStyle boolNoStyle = workBook.createCellStyle(); boolNoStyle.setFillForegroundColor(HSSFColor.LIGHT_ORANGE.index); boolNoStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); /* * Used in order to cache user names. Key = ID, Value = User name */ Map<Long, String> usersCache = new HashMap<Long, String>(); int j = 2; for (Object object : searchResult.getResults()) { HSSFRow row = sheet.createRow(j); String name, parentProjectName, projectName, authorName; Date date; Long objectId; if (object instanceof Test) { Test test = (Test) object; name = test.getName(); parentProjectName = test.getParentProjectName(); projectName = test.getProjectName(); authorName = test.getAuthorName(); objectId = test.getId(); date = test.getDate(); } else throw new IllegalArgumentException(object.getClass().getName()); cell = row.createCell((short) 0); cell.setCellValue(name); cell.setCellStyle(cellStyle); cell = row.createCell((short) 1); cell.setCellValue(parentProjectName); cell.setCellStyle(cellStyle); cell = row.createCell((short) 2); cell.setCellValue(projectName); cell.setCellStyle(cellStyle); cell = row.createCell((short) 3); cell.setCellValue(authorName); cell.setCellStyle(cellStyle); cell = row.createCell((short) 4); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); cell.setCellValue(sdf.format(date)); cell.setCellStyle(cellStyle); int offset = 5; for (Customization customization : customizationsExport) { UnitCustomizationValue ucv = customizationDAO.getUnitCustomizationValue(customization.getId(), objectId); if (customization.getType().equals(Customization.TYPE_CHECKLIST) || customization.getType().equals(Customization.TYPE_LIST)) { for (CustomizationPossibleValue cpv : customization.getPossibleValues()) { boolean matches = false; if (customization.getType().equals(Customization.TYPE_LIST)) { if (ucv != null && ucv.getValue() != null && ucv.getValue().equals("" + cpv.getId())) { matches = true; } } else { String s = "(" + cpv.getId() + ")"; if (ucv != null && ucv.getValue() != null && ucv.getValue().contains(s)) { matches = true; } } if (matches) { cell = row.createCell((short) offset); cell.setCellValue("X"); cell.setCellStyle(checkboxStyle); } offset++; } } else { if (ucv != null) { cell = row.createCell((short) offset); cell.setCellStyle(cellStyle); if (customization.getType().equals(Customization.TYPE_ASSIGNEE)) { if (ucv.getValue() != null && !ucv.getValue().isEmpty()) { try { Long userId = Long.parseLong(ucv.getValue()); /* * Chaching user names by their ids */ String userName = null; if (!usersCache.containsKey(userId)) { User user = userDAO.getUserById(userId); if (user != null) { userName = user.getName(); } else userName = ""; usersCache.put(userId, userName); } else userName = usersCache.get(userId); cell.setCellValue(userName); } catch (Exception e) { e.printStackTrace(); } } } else if (customization.getType().equals(Customization.TYPE_CHECKBOX)) { if (ucv.getValue() != null) { if (ucv.getValue().equals("true")) { cell.setCellValue("Yes"); cell.setCellStyle(boolYesStyle); } else { cell.setCellValue("No"); cell.setCellStyle(boolNoStyle); } } } else { cell.setCellValue(ucv.getValue()); } } offset++; } } j++; } /* * Making the text to fit in all cells */ for (short i = 0; i < (short) cellOffset + 1; i++) { sheet.autoSizeColumn(i); } workBook.write(outputStream); outputStream.flush(); outputStream.close(); }
From source file:net.sf.jasperreports.engine.export.JRXlsExporter.java
License:Open Source License
protected HSSFCellStyle getLoadedCellStyle(StyleInfo style) { HSSFCellStyle cellStyle = loadedCellStyles.get(style); if (cellStyle == null) { cellStyle = workbook.createCellStyle(); cellStyle.setFillForegroundColor(style.backcolor); cellStyle.setFillPattern(style.mode); cellStyle.setAlignment(style.horizontalAlignment); cellStyle.setVerticalAlignment(style.verticalAlignment); cellStyle.setRotation(style.rotation); cellStyle.setFont(style.font);/* w w w . j a va2 s . c om*/ cellStyle.setWrapText(style.lcWrapText); cellStyle.setLocked(style.lcCellLocked); cellStyle.setHidden(style.lcCellHidden); if (style.hasDataFormat()) { cellStyle.setDataFormat(style.getDataFormat()); } boolean isIgnoreCellBorder = getCurrentItemConfiguration().isIgnoreCellBorder(); if (!isIgnoreCellBorder) { BoxStyle box = style.box; cellStyle.setBorderTop(box.borderStyle[BoxStyle.TOP]); cellStyle.setTopBorderColor(box.borderColour[BoxStyle.TOP]); cellStyle.setBorderLeft(box.borderStyle[BoxStyle.LEFT]); cellStyle.setLeftBorderColor(box.borderColour[BoxStyle.LEFT]); cellStyle.setBorderBottom(box.borderStyle[BoxStyle.BOTTOM]); cellStyle.setBottomBorderColor(box.borderColour[BoxStyle.BOTTOM]); cellStyle.setBorderRight(box.borderStyle[BoxStyle.RIGHT]); cellStyle.setRightBorderColor(box.borderColour[BoxStyle.RIGHT]); } loadedCellStyles.put(style, cellStyle); } return cellStyle; }
From source file:net.sf.jasperreports.engine.export.JRXlsMetadataExporter.java
License:Open Source License
protected HSSFCellStyle getLoadedCellStyle(StyleInfo style) { HSSFCellStyle cellStyle = loadedCellStyles.get(style); if (cellStyle == null) { cellStyle = workbook.createCellStyle(); cellStyle.setFillForegroundColor(style.backcolor); cellStyle.setFillPattern(style.mode); cellStyle.setAlignment(style.horizontalAlignment); cellStyle.setVerticalAlignment(style.verticalAlignment); cellStyle.setRotation(style.rotation); cellStyle.setFont(style.font);// www . ja va 2s.c om cellStyle.setWrapText(style.lcWrapText); cellStyle.setLocked(style.lcCellLocked); cellStyle.setHidden(style.lcCellHidden); if (style.hasDataFormat()) { cellStyle.setDataFormat(style.getDataFormat()); } if (!getCurrentItemConfiguration().isIgnoreCellBorder()) { BoxStyle box = style.box; cellStyle.setBorderTop(box.borderStyle[BoxStyle.TOP]); cellStyle.setTopBorderColor(box.borderColour[BoxStyle.TOP]); cellStyle.setBorderLeft(box.borderStyle[BoxStyle.LEFT]); cellStyle.setLeftBorderColor(box.borderColour[BoxStyle.LEFT]); cellStyle.setBorderBottom(box.borderStyle[BoxStyle.BOTTOM]); cellStyle.setBottomBorderColor(box.borderColour[BoxStyle.BOTTOM]); cellStyle.setBorderRight(box.borderStyle[BoxStyle.RIGHT]); cellStyle.setRightBorderColor(box.borderColour[BoxStyle.RIGHT]); } loadedCellStyles.put(style, cellStyle); } return cellStyle; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.academicAdministration.executionCourseManagement.CourseLoadOverviewBean.java
License:Open Source License
public StyledExcelSpreadsheet getInconsistencySpreadsheet() { final StyledExcelSpreadsheet spreadsheet = new StyledExcelSpreadsheet( BundleUtil.getString(Bundle.ACADEMIC, "label.course.load.inconsistency.filename") + "_" + executionSemester.getExecutionYear().getYear().replace('/', '_') + "_" + executionSemester.getSemester()); HSSFCellStyle normalStyle = spreadsheet.getExcelStyle().getValueStyle(); normalStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFWorkbook wb = spreadsheet.getWorkbook(); HSSFFont font = wb.createFont();//ww w .j a va 2s . co m font.setColor(HSSFColor.BLACK.index); font.setFontHeightInPoints((short) 8); HSSFCellStyle redStyle = wb.createCellStyle(); redStyle.setFont(font); redStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); redStyle.setFillForegroundColor(HSSFColor.ORANGE.index); redStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFCellStyle yellowStyle = wb.createCellStyle(); yellowStyle.setFont(font); yellowStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); yellowStyle.setFillForegroundColor(HSSFColor.YELLOW.index); yellowStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); spreadsheet.newHeaderRow(); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.department")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.degree")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.executionCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shift")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.shiftType")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.competenceCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.curricularCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.executionCourse")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lesson.count")); spreadsheet.addHeader(BundleUtil.getString(Bundle.ACADEMIC, "label.load.lessonInstances.count")); for (final ExecutionCourse executionCourse : executionSemester.getAssociatedExecutionCoursesSet()) { for (final CourseLoad courseLoad : executionCourse.getCourseLoadsSet()) { for (final Shift shift : courseLoad.getShiftsSet()) { spreadsheet.newRow(); spreadsheet.addCell(getDepartmentString(executionCourse)); spreadsheet.addCell(executionCourse.getDegreePresentationString()); spreadsheet.addCell(executionCourse.getName()); spreadsheet.addCell(shift.getNome()); spreadsheet.addCell(courseLoad.getType().getFullNameTipoAula()); final BigDecimal competenceCourseLoad = new BigDecimal(getCompetenceCourseLoad(courseLoad)) .setScale(2, RoundingMode.HALF_EVEN); final BigDecimal curricularCourseLoad = new BigDecimal(getCurricularCourseLoad(courseLoad)) .setScale(2, RoundingMode.HALF_EVEN); final BigDecimal executionLoad = courseLoad.getTotalQuantity().setScale(2, RoundingMode.HALF_EVEN); final BigDecimal shiftCourseLoad = getShiftCourseLoad(shift).setScale(2, RoundingMode.HALF_EVEN); if (competenceCourseLoad.signum() < 0) { spreadsheet.addCell(getCompetenceCourseLoadStrings(courseLoad), redStyle); } else { spreadsheet.addCell(competenceCourseLoad); } if (!competenceCourseLoad.equals(curricularCourseLoad) || curricularCourseLoad.signum() < 0) { spreadsheet.addCell(getCurricularCourseLoadString(courseLoad), redStyle); } else { spreadsheet.addCell(curricularCourseLoad); } if (!executionLoad.equals(curricularCourseLoad)) { spreadsheet.addCell(executionLoad, redStyle); } else { spreadsheet.addCell(executionLoad); } if (!shiftCourseLoad.equals(executionLoad)) { if (isLargeDifference(shiftCourseLoad, executionLoad, competenceCourseLoad.divide(new BigDecimal(14), 2, RoundingMode.HALF_EVEN))) { spreadsheet.addCell(shiftCourseLoad, redStyle); } else { spreadsheet.addCell(shiftCourseLoad, yellowStyle); } } else { spreadsheet.addCell(shiftCourseLoad); } spreadsheet.addCell(shift.getAssociatedLessonsSet().size()); spreadsheet.addCell(getLessonInstanceCount(shift)); } } } final HSSFSheet sheet = wb.getSheetAt(0); sheet.createFreezePane(0, 1, 0, 1); sheet.autoSizeColumn(1, true); sheet.autoSizeColumn(2, true); sheet.autoSizeColumn(3, true); sheet.autoSizeColumn(4, true); sheet.autoSizeColumn(5, true); sheet.autoSizeColumn(6, true); sheet.autoSizeColumn(7, true); sheet.autoSizeColumn(8, true); sheet.autoSizeColumn(9, true); return spreadsheet; }