List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle setDataFormat
@Override public void setDataFormat(short fmt)
From source file:io.vertigo.quarto.plugins.export.xls.XLSExporter.java
License:Apache License
private void initHssfStyle(final HSSFWorkbook workbook) { // default:/*from w w w.j a va 2 s . c o m*/ final HSSFCellStyle oddCellStyle = createRowCellStyle(workbook, true); final HSSFCellStyle evenCellStyle = createRowCellStyle(workbook, true); oddHssfStyleCache.put(DataType.Boolean, oddCellStyle); oddHssfStyleCache.put(DataType.String, oddCellStyle); evenHssfStyleCache.put(DataType.Boolean, evenCellStyle); evenHssfStyleCache.put(DataType.String, evenCellStyle); // Nombre sans dcimal final HSSFCellStyle oddLongCellStyle = createRowCellStyle(workbook, true); final HSSFCellStyle evenLongCellStyle = createRowCellStyle(workbook, true); oddLongCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0")); evenLongCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0")); oddHssfStyleCache.put(DataType.Long, oddLongCellStyle); oddHssfStyleCache.put(DataType.Integer, oddLongCellStyle); evenHssfStyleCache.put(DataType.Long, evenLongCellStyle); evenHssfStyleCache.put(DataType.Integer, evenLongCellStyle); // Nombre a dcimal final HSSFCellStyle oddDoubleCellStyle = createRowCellStyle(workbook, true); final HSSFCellStyle evenDoubleCellStyle = createRowCellStyle(workbook, true); oddDoubleCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00")); evenDoubleCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00")); oddHssfStyleCache.put(DataType.Double, oddDoubleCellStyle); oddHssfStyleCache.put(DataType.BigDecimal, oddDoubleCellStyle); evenHssfStyleCache.put(DataType.Double, evenDoubleCellStyle); evenHssfStyleCache.put(DataType.BigDecimal, evenDoubleCellStyle); // Date final HSSFCellStyle oddDateCellStyle = createRowCellStyle(workbook, true); final HSSFCellStyle evenDateCellStyle = createRowCellStyle(workbook, true); oddDateCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy" /* "m/d/yy h:mm" */)); evenDateCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy" /* "m/d/yy h:mm" */)); oddHssfStyleCache.put(DataType.LocalDate, oddDateCellStyle); evenHssfStyleCache.put(DataType.LocalDate, evenDateCellStyle); // Instant final HSSFCellStyle oddDateTimeCellStyle = createRowCellStyle(workbook, true); final HSSFCellStyle evenDateTimeCellStyle = createRowCellStyle(workbook, true); oddDateTimeCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm")); evenDateTimeCellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm")); oddHssfStyleCache.put(DataType.Instant, oddDateTimeCellStyle); evenHssfStyleCache.put(DataType.Instant, evenDateTimeCellStyle); }
From source file:jp.co.opentone.bsol.framework.core.generator.excel.strategy.PoiWorkbookGeneratorStrategy.java
License:Apache License
private HSSFCellStyle initializeDateCellStyle(HSSFWorkbook workbook, HSSFCellStyle baseStyle) { HSSFCellStyle dateStyle = workbook.createCellStyle(); dateStyle.cloneStyleFrom(baseStyle); dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("d-mmm-yy")); return dateStyle; }
From source file:neg.JRViewerComercial.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 va 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.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.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.JRViewerComercial.java
License:Open Source License
private static void crearFilaHojaExcel(HSSFWorkbook libro, HSSFSheet hoja, int num_fila, ResultSet rs, HSSFCellStyle cs2, HSSFCellStyle cs3) throws SQLException, UnknownHostException { HSSFRow fila = null;/*from w w w . j a va 2s . c o m*/ HSSFCell celda = null; HSSFRichTextString texto = null; int num_fila_aux = 2; while (rs.next()) { // Se crea una fila dentro de la hoja fila = hoja.createRow(num_fila); //Celda del Tarifa Cliente HSSFDataFormat format = libro.createDataFormat(); HSSFCellStyle style = libro.createCellStyle(); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBottomBorderColor(HSSFColor.BLACK.index); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setLeftBorderColor(HSSFColor.BLACK.index); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setRightBorderColor(HSSFColor.BLACK.index); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setTopBorderColor(HSSFColor.BLACK.index); style.setDataFormat(format.getFormat("#,##0")); //Celda de cliente celda = fila.createCell((short) 0); celda.setCellStyle(cs2); String cliente = rs.getString("cl_nombre"); texto = new HSSFRichTextString(cliente); celda.setCellStyle(cs3); celda.setCellValue(texto); celda.setCellStyle(style); //Celda de enero celda = fila.createCell((short) 1); celda.setCellStyle(cs3); double enero = rs.getDouble("enero"); celda.setCellStyle(cs3); celda.setCellValue(enero); style.setDataFormat(format.getFormat("00")); //Celda de febrero celda = fila.createCell((short) 2); double febrero = rs.getDouble("febrero"); celda.setCellStyle(cs3); celda.setCellValue(febrero); style.setDataFormat(format.getFormat("00")); //Celda de marzo celda = fila.createCell((short) 3); celda.setCellStyle(cs2); double marzo = rs.getDouble("marzo"); celda.setCellStyle(cs3); celda.setCellValue(marzo); style.setDataFormat(format.getFormat("00")); //Celda de abril celda = fila.createCell((short) 4); double abril = rs.getDouble("abril"); celda.setCellStyle(cs3); celda.setCellValue(abril); style.setDataFormat(format.getFormat("00")); //Celda de mayo celda = fila.createCell((short) 5); double mayo = rs.getDouble("mayo"); celda.setCellStyle(cs3); celda.setCellValue(mayo); style.setDataFormat(format.getFormat("00")); //Celda de junio celda = fila.createCell((short) 6); double junio = rs.getDouble("junio"); celda.setCellStyle(cs3); celda.setCellValue(junio); //Celda del julio celda = fila.createCell((short) 7); double julio = rs.getDouble("julio"); celda.setCellStyle(cs3); celda.setCellValue(julio); style.setDataFormat(format.getFormat("00")); //Celda de agosto celda = fila.createCell((short) 8); celda.setCellStyle(cs2); double agosto = rs.getDouble("agosto"); celda.setCellStyle(cs3); celda.setCellValue(agosto); style.setDataFormat(format.getFormat("00")); //Celda de septiembre celda = fila.createCell((short) 9); double septiembre = rs.getDouble("septiembre"); celda.setCellStyle(cs3); celda.setCellValue(septiembre); style.setDataFormat(format.getFormat("00")); //Celda de octubre celda = fila.createCell((short) 10); celda.setCellStyle(cs2); double octubre = rs.getDouble("octubre"); celda.setCellStyle(cs3); celda.setCellValue(octubre); style.setDataFormat(format.getFormat("00")); //Celda de noviembre celda = fila.createCell((short) 11); double noviembre = rs.getDouble("noviembre"); celda.setCellStyle(cs3); celda.setCellValue(noviembre); style.setDataFormat(format.getFormat("00")); //Celda de diciembre celda = fila.createCell((short) 12); celda.setCellStyle(cs2); double diciembre = rs.getDouble("diciembre"); celda.setCellStyle(cs3); celda.setCellValue(diciembre); style.setDataFormat(format.getFormat("00")); //Celda de la tarifa de cliente celda = fila.createCell((short) 13); celda.setCellValue(rs.getDouble("ta_cliente")); //Celda de margen celda = fila.createCell((short) 14); double t_cliente = Double.parseDouble(rs.getString("ta_cliente")); double t_proveedor = Double.parseDouble(rs.getString("ta_proveedor")); double margen = t_cliente - t_proveedor; style.setDataFormat(format.getFormat("00.00")); celda.setCellValue(margen); //Celda de MG % celda = fila.createCell((short) 15); String porCientoPedido = (!rs.getString("ta_cliente").equals("0")) ? new java.text.DecimalFormat("#,##0").format(((t_cliente - t_proveedor) / t_cliente) * 100) .concat("% ") : "0% "; texto = new HSSFRichTextString(porCientoPedido); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de mg pedido celda = fila.createCell((short) 16); double num_pedidos = Double.parseDouble(rs.getString("num_pedido")); style.setDataFormat(format.getFormat("00")); double mg_pedido = ((t_cliente - t_proveedor) / num_pedidos); celda.setCellStyle(cs3); celda.setCellValue(mg_pedido); //Celda del num. pedido celda = fila.createCell((short) 17); int num_pedido = rs.getInt("num_pedido"); celda.setCellStyle(cs3); celda.setCellValue(num_pedido); //Se incrementa el numero de fila num_fila++; num_fila_aux++; } }
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 {/* w ww . j av 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 crearFilaHojaExcel(HSSFWorkbook libro, HSSFSheet hoja, int num_fila, ResultSet rs, HSSFCellStyle cs2, HSSFCellStyle cs3) throws SQLException, UnknownHostException { HSSFRow fila = null;//from w w w.j a v a2 s . c om HSSFCell celda = null; HSSFRichTextString texto = null; int num_fila_aux = 2; while (rs.next()) { // Se crea una fila dentro de la hoja fila = hoja.createRow(num_fila); //Celda del Tarifa Cliente HSSFDataFormat format = libro.createDataFormat(); HSSFCellStyle style = libro.createCellStyle(); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBottomBorderColor(HSSFColor.BLACK.index); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setLeftBorderColor(HSSFColor.BLACK.index); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setRightBorderColor(HSSFColor.BLACK.index); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setTopBorderColor(HSSFColor.BLACK.index); style.setDataFormat(format.getFormat("#,##0")); //Celda de Proveedor celda = fila.createCell((short) 0); celda.setCellStyle(cs2); String proveedor = rs.getString("pr_nombre_fiscal"); texto = new HSSFRichTextString(proveedor); celda.setCellStyle(cs3); celda.setCellValue(texto); celda.setCellStyle(style); //Celda de enero celda = fila.createCell((short) 1); celda.setCellStyle(cs3); double enero = rs.getDouble("enero_pr"); celda.setCellStyle(cs3); celda.setCellValue(enero); style.setDataFormat(format.getFormat("00")); //Celda de febrero celda = fila.createCell((short) 2); double febrero = rs.getDouble("febrero_pr"); celda.setCellStyle(cs3); celda.setCellValue(febrero); style.setDataFormat(format.getFormat("00")); //Celda de marzo celda = fila.createCell((short) 3); celda.setCellStyle(cs2); double marzo = rs.getDouble("marzo_pr"); celda.setCellStyle(cs3); celda.setCellValue(marzo); style.setDataFormat(format.getFormat("00")); //Celda de abril celda = fila.createCell((short) 4); double abril = rs.getDouble("abril_pr"); celda.setCellStyle(cs3); celda.setCellValue(abril); style.setDataFormat(format.getFormat("00")); //Celda de mayo celda = fila.createCell((short) 5); double mayo = rs.getDouble("mayo_pr"); celda.setCellStyle(cs3); celda.setCellValue(mayo); style.setDataFormat(format.getFormat("00")); //Celda de junio celda = fila.createCell((short) 6); double junio = rs.getDouble("junio_pr"); celda.setCellStyle(cs3); celda.setCellValue(junio); //Celda del julio celda = fila.createCell((short) 7); double julio = rs.getDouble("julio_pr"); celda.setCellStyle(cs3); celda.setCellValue(julio); style.setDataFormat(format.getFormat("00")); //Celda de agosto celda = fila.createCell((short) 8); celda.setCellStyle(cs2); double agosto = rs.getDouble("agosto_pr"); celda.setCellStyle(cs3); celda.setCellValue(agosto); style.setDataFormat(format.getFormat("00")); //Celda de septiembre celda = fila.createCell((short) 9); double septiembre = rs.getDouble("septiembre_pr"); celda.setCellStyle(cs3); celda.setCellValue(septiembre); style.setDataFormat(format.getFormat("00")); //Celda de octubre celda = fila.createCell((short) 10); celda.setCellStyle(cs2); double octubre = rs.getDouble("octubre_pr"); celda.setCellStyle(cs3); celda.setCellValue(octubre); style.setDataFormat(format.getFormat("00")); //Celda de noviembre celda = fila.createCell((short) 11); double noviembre = rs.getDouble("noviembre_pr"); celda.setCellStyle(cs3); celda.setCellValue(noviembre); style.setDataFormat(format.getFormat("00")); //Celda de diciembre celda = fila.createCell((short) 12); celda.setCellStyle(cs2); double diciembre = rs.getDouble("diciembre_pr"); celda.setCellStyle(cs3); celda.setCellValue(diciembre); style.setDataFormat(format.getFormat("00")); //Celda de la tarifa de Proveedor celda = fila.createCell((short) 13); celda.setCellValue(rs.getDouble("ta_proveedor")); //Celda de % turismo celda = fila.createCell((short) 14); celda.setCellStyle(cs3); double t_proveedor = Double.parseDouble(rs.getString("ta_proveedor")); double factor = Integer.parseInt(rs.getString("factor")); int num_pedido = Integer.parseInt(rs.getString("num_pedido")); String turismo = (!rs.getString("factor").equals("0")) ? new java.text.DecimalFormat("#,##0").format((factor / num_pedido) * 100).concat(" % ") : "0 % "; style.setDataFormat(format.getFormat("00.00")); celda.setCellValue(turismo); //Celda de % funciona celda = fila.createCell((short) 15); celda.setCellStyle(cs3); double funciona = Integer.parseInt(rs.getString("estado_ve")); String estado_ve = (!rs.getString("estado_ve").equals("0")) ? new java.text.DecimalFormat("#,##0").format((funciona / num_pedido) * 100).concat(" % ") : "0 % "; celda.setCellStyle(cs3); celda.setCellValue(estado_ve); //Celda % Gra Unitaria celda = fila.createCell((short) 16); celda.setCellStyle(cs3); double soporte = Integer.parseInt(rs.getString("soporte")); String grua = (!rs.getString("soporte").equals("0")) ? new java.text.DecimalFormat("#,##0").format((soporte / num_pedido) * 100).concat(" % ") : "0 % "; celda.setCellStyle(cs3); celda.setCellValue(grua); //Celda del num. pedido celda = fila.createCell((short) 17); celda.setCellStyle(cs3); celda.setCellValue(num_pedido); //Se incrementa el numero de fila num_fila++; num_fila_aux++; } }
From source file:neg.JRViewerInformeUnitario.java
License:Open Source License
private static void crearFilaHojaExcel(HSSFWorkbook libro, HSSFSheet hoja, int num_fila, ResultSet rs, HSSFCellStyle cs2, HSSFCellStyle cs3) throws SQLException, UnknownHostException { HSSFRow fila = null;/*from w w w . j a va 2 s .com*/ HSSFCell celda = null; HSSFRichTextString texto = null; int num_fila_aux = 2; for (int i = 0; i < 4; i++) { //System.out.println(); /*} while (rs.next()) {*/ if (i == 0) { // Se crea una fila dentro de la hoja fila = hoja.createRow(num_fila); //Celda de ttulo celda = fila.createCell((short) 0); celda.setCellStyle(cs2); texto = new HSSFRichTextString("Facturacin"); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de enero celda = fila.createCell((short) 1); String enero = rs.getString("enero"); texto = new HSSFRichTextString(enero); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de febrero celda = fila.createCell((short) 2); String febrero = rs.getString("febrero"); texto = new HSSFRichTextString(febrero); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de marzo celda = fila.createCell((short) 3); celda.setCellStyle(cs2); String marzo = rs.getString("marzo"); texto = new HSSFRichTextString(marzo); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de abril celda = fila.createCell((short) 4); String abril = rs.getString("abril"); texto = new HSSFRichTextString(abril); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de mayo celda = fila.createCell((short) 5); celda.setCellStyle(cs2); String mayo = rs.getString("mayo"); texto = new HSSFRichTextString(mayo); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de junio celda = fila.createCell((short) 6); String junio = rs.getString("junio"); texto = new HSSFRichTextString(junio); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda del julio celda = fila.createCell((short) 7); String julio = rs.getString("julio"); texto = new HSSFRichTextString(julio); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de agosto celda = fila.createCell((short) 8); celda.setCellStyle(cs2); String agosto = rs.getString("agosto"); texto = new HSSFRichTextString(agosto); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de septiembre celda = fila.createCell((short) 9); String septiembre = rs.getString("septiembre"); texto = new HSSFRichTextString(septiembre); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de octubre celda = fila.createCell((short) 10); celda.setCellStyle(cs2); String octubre = rs.getString("octubre"); texto = new HSSFRichTextString(octubre); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de noviembre celda = fila.createCell((short) 11); String noviembre = rs.getString("noviembre"); texto = new HSSFRichTextString(noviembre); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de diciembre celda = fila.createCell((short) 12); celda.setCellStyle(cs2); String diciembre = rs.getString("diciembre"); texto = new HSSFRichTextString(diciembre); celda.setCellStyle(cs3); celda.setCellValue(texto); } else if (i == 1) { // Se crea una fila dentro de la hoja fila = hoja.createRow(num_fila); //Celda de ttulo celda = fila.createCell((short) 0); celda.setCellStyle(cs2); texto = new HSSFRichTextString("Margen pedido"); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de enero celda = fila.createCell((short) 1); String enero = rs.getString("mg_pe_enero"); texto = new HSSFRichTextString(enero); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de febrero celda = fila.createCell((short) 2); String febrero = rs.getString("mg_pe_febrero"); texto = new HSSFRichTextString(febrero); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de marzo celda = fila.createCell((short) 3); celda.setCellStyle(cs2); String marzo = rs.getString("mg_pe_marzo"); texto = new HSSFRichTextString(marzo); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de abril celda = fila.createCell((short) 4); String abril = rs.getString("mg_pe_abril"); texto = new HSSFRichTextString(abril); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de mayo celda = fila.createCell((short) 5); celda.setCellStyle(cs2); String mayo = rs.getString("mg_pe_mayo"); texto = new HSSFRichTextString(mayo); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de junio celda = fila.createCell((short) 6); String junio = rs.getString("mg_pe_junio"); texto = new HSSFRichTextString(junio); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda del julio celda = fila.createCell((short) 7); String julio = rs.getString("mg_pe_julio"); texto = new HSSFRichTextString(julio); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de agosto celda = fila.createCell((short) 8); celda.setCellStyle(cs2); String agosto = rs.getString("mg_pe_agosto"); texto = new HSSFRichTextString(agosto); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de septiembre celda = fila.createCell((short) 9); String septiembre = rs.getString("mg_pe_septiembre"); texto = new HSSFRichTextString(septiembre); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de octubre celda = fila.createCell((short) 10); celda.setCellStyle(cs2); String octubre = rs.getString("mg_pe_octubre"); texto = new HSSFRichTextString(octubre); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de noviembre celda = fila.createCell((short) 11); String noviembre = rs.getString("mg_pe_noviembre"); texto = new HSSFRichTextString(noviembre); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de diciembre celda = fila.createCell((short) 12); celda.setCellStyle(cs2); String diciembre = rs.getString("mg_pe_diciembre"); texto = new HSSFRichTextString(diciembre); celda.setCellStyle(cs3); celda.setCellValue(texto); } else if (i == 2) { // Se crea una fila dentro de la hoja fila = hoja.createRow(num_fila); //Celda de ttulo celda = fila.createCell((short) 0); celda.setCellStyle(cs2); texto = new HSSFRichTextString(""); celda.setCellStyle(cs3); celda.setCellValue(texto); } else if (i == 3) { // Se crea una fila dentro de la hoja fila = hoja.createRow(num_fila); //Celda de ttulo celda = fila.createCell((short) 0); celda.setCellStyle(cs2); texto = new HSSFRichTextString("NM. PEDIDOS"); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de enero celda = fila.createCell((short) 1); String enero = rs.getString("num_enero"); texto = new HSSFRichTextString(enero); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de febrero celda = fila.createCell((short) 1); String febrero = rs.getString("num_febrero"); texto = new HSSFRichTextString(febrero); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de marzo celda = fila.createCell((short) 2); celda.setCellStyle(cs2); String marzo = rs.getString("num_marzo"); texto = new HSSFRichTextString(marzo); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de abril celda = fila.createCell((short) 3); String abril = rs.getString("num_abril"); texto = new HSSFRichTextString(abril); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de mayo celda = fila.createCell((short) 4); celda.setCellStyle(cs2); String mayo = rs.getString("num_mayo"); texto = new HSSFRichTextString(mayo); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de junio celda = fila.createCell((short) 5); String junio = rs.getString("num_junio"); texto = new HSSFRichTextString(junio); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda del julio celda = fila.createCell((short) 6); String julio = rs.getString("num_julio"); texto = new HSSFRichTextString(julio); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de agosto celda = fila.createCell((short) 7); celda.setCellStyle(cs2); String agosto = rs.getString("num_agosto"); texto = new HSSFRichTextString(agosto); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de septiembre celda = fila.createCell((short) 8); String septiembre = rs.getString("num_septiembre"); texto = new HSSFRichTextString(septiembre); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de octubre celda = fila.createCell((short) 9); celda.setCellStyle(cs2); String octubre = rs.getString("num_octubre"); texto = new HSSFRichTextString(octubre); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de noviembre celda = fila.createCell((short) 10); String noviembre = rs.getString("num_noviembre"); texto = new HSSFRichTextString(noviembre); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de diciembre celda = fila.createCell((short) 11); celda.setCellStyle(cs2); String diciembre = rs.getString("num_diciembre"); texto = new HSSFRichTextString(diciembre); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de MG celda = fila.createCell((short) 12); double t_cliente = Double.parseDouble(rs.getString("ta_cliente")); double t_proveedor = Double.parseDouble(rs.getString("ta_proveedor")); String porCientoPedido = new java.text.DecimalFormat("#,##0") .format(((t_cliente - t_proveedor) / t_cliente) * 100).concat("% "); texto = new HSSFRichTextString(porCientoPedido); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda de mg pedido celda = fila.createCell((short) 13); String mg_pedido = rs.getString("mg_pedido"); texto = new HSSFRichTextString(mg_pedido); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda del num. pedido celda = fila.createCell((short) 14); String num_pedido = rs.getString("num_pedido"); texto = new HSSFRichTextString(num_pedido); celda.setCellStyle(cs3); celda.setCellValue(texto); //Celda del ta cliente celda = fila.createCell((short) 15); String ta_cliente = rs.getString("ta_cliente"); texto = new HSSFRichTextString(ta_cliente); celda.setCellStyle(cs3); celda.setCellValue(texto); } //Celda de Tarifa Cliente HSSFDataFormat format = libro.createDataFormat(); HSSFCellStyle style = libro.createCellStyle(); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBottomBorderColor(HSSFColor.BLACK.index); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setLeftBorderColor(HSSFColor.BLACK.index); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setRightBorderColor(HSSFColor.BLACK.index); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setTopBorderColor(HSSFColor.BLACK.index); style.setDataFormat(format.getFormat("00")); celda.setCellStyle(style); //Se incrementa el numero de fila num_fila++; num_fila_aux++; } }
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.// w ww . j av a 2s . 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.chaosserver.timelord.data.ExcelUglyDataReaderWriter.java
License:Open Source License
/** * Generates the workbook that contains all of the data for the excel * document.//from w ww . ja v a 2s .c om * * @param timelordData the data object to generate the workbook for * @return the workbook of data */ protected HSSFWorkbook generateWorkbook(TimelordData timelordData) { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); sheet.setColumnWidth((short) 1, (short) 10000); HSSFCellStyle dateStyle = wb.createCellStyle(); dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); List<TimelordTask> taskCollection = timelordData.getTaskCollection(); Iterator<TimelordTask> taskIterator = taskCollection.iterator(); // Calendar weekStart = Calendar.getInstance(); // Make the headers HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell((short) 0); cell.setCellValue("Date"); cell = row.createCell((short) 1); cell.setCellValue("Task Name"); cell = row.createCell((short) 2); cell.setCellValue("Hours"); cell = row.createCell((short) 3); cell.setCellValue("Note"); int rowNum = 1; while (taskIterator.hasNext()) { TimelordTask timelordTask = (TimelordTask) taskIterator.next(); if (timelordTask.isExportable()) { String taskName = timelordTask.getTaskName(); List<TimelordTaskDay> taskDayList = timelordTask.getTaskDayList(); Iterator<TimelordTaskDay> taskDayIterator = taskDayList.iterator(); while (taskDayIterator.hasNext()) { TimelordTaskDay timelordTaskDay = (TimelordTaskDay) taskDayIterator.next(); if (timelordTaskDay.getHours() > 0) { row = sheet.createRow(rowNum); cell = row.createCell((short) 0); cell.setCellStyle(dateStyle); cell.setCellValue(timelordTaskDay.getDate()); cell = row.createCell((short) 1); cell.setCellValue(taskName); cell = row.createCell((short) 2); cell.setCellValue(timelordTaskDay.getHours()); cell = row.createCell((short) 3); cell.setCellValue(timelordTaskDay.getNote()); rowNum++; } } } } return wb; }
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.ja 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; }