List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle setFillPattern
@Override public void setFillPattern(FillPatternType fp)
From source file:de.viaboxx.nlstools.formats.MBExcelPersistencer.java
License:Apache License
private void initStyles(HSSFWorkbook wb) { // cache styles used to write text into cells HSSFCellStyle style = wb.createCellStyle(); HSSFFont font = wb.createFont();//from w w w.ja va 2s . c o m font.setBold(true); style.setFont(font); styles.put(STYLE_BOLD, style); style = wb.createCellStyle(); font = wb.createFont(); font.setItalic(true); style.setFont(font); styles.put(STYLE_ITALIC, style); style = wb.createCellStyle(); font = wb.createFont(); font.setItalic(true); font.setColor(Font.COLOR_RED); style.setFont(font); styles.put(STYLE_REVIEW, style); style = wb.createCellStyle(); style.setFillPattern(FillPatternType.FINE_DOTS); style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex()); style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex()); styles.put(STYLE_MISSING, style); style = wb.createCellStyle(); style.setFillPattern(FillPatternType.FINE_DOTS); style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex()); style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex()); style.setFont(font); styles.put(STYLE_MISSING_REVIEW, style); style = wb.createCellStyle(); HSSFCreationHelper createHelper = wb.getCreationHelper(); style.setDataFormat(createHelper.createDataFormat().getFormat("yyyy-dd-mm hh:mm")); styles.put(STYLE_DATETIME, style); }
From source file:demo.poi.BigExample.java
License:Apache License
public static void main(String[] args) throws IOException { int rownum;/* ww w . j a va2 s . c o m*/ // create a new file FileOutputStream out = new FileOutputStream("target/bigworkbook.xls"); // create a new workbook HSSFWorkbook wb = new HSSFWorkbook(); // create a new sheet HSSFSheet s = wb.createSheet(); // declare a row object reference HSSFRow r = null; // declare a cell object reference HSSFCell c = null; // create 3 cell styles HSSFCellStyle cs = wb.createCellStyle(); HSSFCellStyle cs2 = wb.createCellStyle(); HSSFCellStyle cs3 = wb.createCellStyle(); // create 2 fonts objects HSSFFont f = wb.createFont(); HSSFFont f2 = wb.createFont(); //set font 1 to 12 point type f.setFontHeightInPoints((short) 12); //make it red f.setColor(HSSFColor.RED.index); // make it bold //arial is the default font f.setBoldweight(Font.BOLDWEIGHT_BOLD); //set font 2 to 10 point type f2.setFontHeightInPoints((short) 10); //make it the color at palette index 0xf (white) f2.setColor(HSSFColor.WHITE.index); //make it bold f2.setBoldweight(Font.BOLDWEIGHT_BOLD); //set cell stlye cs.setFont(f); //set the cell format see HSSFDataFromat for a full list cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); //set a thin border cs2.setBorderBottom(CellStyle.BORDER_THIN); //fill w fg fill color cs2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // set foreground fill to red cs2.setFillForegroundColor(HSSFColor.RED.index); // set the font cs2.setFont(f2); // set the sheet name to HSSF Test wb.setSheetName(0, "HSSF Test"); // create a sheet with 300 rows (0-299) for (rownum = 0; rownum < 300; rownum++) { // create a row r = s.createRow(rownum); // on every other row if ((rownum % 2) == 0) { // make the row height bigger (in twips - 1/20 of a point) r.setHeight((short) 0x249); } //r.setRowNum(( short ) rownum); // create 50 cells (0-49) (the += 2 becomes apparent later for (int cellnum = 0; cellnum < 50; cellnum += 2) { // create a numeric cell c = r.createCell(cellnum); // do some goofy math to demonstrate decimals c.setCellValue(rownum * 10000 + cellnum + (((double) rownum / 1000) + ((double) cellnum / 10000))); // on every other row if ((rownum % 2) == 0) { // set this cell to the first cell style we defined c.setCellStyle(cs); } // create a string cell (see why += 2 in the c = r.createCell(cellnum + 1); // set the cell's string value to "TEST" c.setCellValue("TEST"); // make this column a bit wider s.setColumnWidth(cellnum + 1, (int) ((50 * 8) / ((double) 1 / 20))); // on every other row if ((rownum % 2) == 0) { // set this to the white on red cell style // we defined above c.setCellStyle(cs2); } } } //draw a thick black border on the row at the bottom using BLANKS // advance 2 rows rownum++; rownum++; r = s.createRow(rownum); // define the third style to be the default // except with a thick black border at the bottom cs3.setBorderBottom(CellStyle.BORDER_THICK); //create 50 cells for (int cellnum = 0; cellnum < 50; cellnum++) { //create a blank type cell (no value) c = r.createCell(cellnum); // set it to the thick black border style c.setCellStyle(cs3); } //end draw thick black border // demonstrate adding/naming and deleting a sheet // create a sheet, set its title then delete it s = wb.createSheet(); wb.setSheetName(1, "DeletedSheet"); wb.removeSheetAt(1); //end deleted sheet // write the workbook to the output stream // close our file (don't blow out our file handles wb.write(out); out.close(); }
From source file:edu.aplic.utilerias.GenerarArchivoXlsUtil.java
public static void crearXslVentasPorTipoProducto(File file, Venta[] aVentas, Usuario oUsuario) throws IOException { FileOutputStream elFichero = null; // Se crea el libro HSSFWorkbook libro = new HSSFWorkbook(); // Se crea una hoja dentro del libro HSSFSheet hoja = libro.createSheet(); HSSFRow fila = null;/*from ww w .j a v a2s .c o m*/ HSSFCell celda = null; fila = hoja.createRow(0); celda = fila.createCell(0); hoja.autoSizeColumn(0); celda.setCellValue(new HSSFRichTextString("Reporte Ventas por tipos")); if (oUsuario != null) { celda = fila.createCell(1); hoja.autoSizeColumn(0); celda.setCellValue(new HSSFRichTextString("Usuario: " + oUsuario.getNombreCompleto())); } // Se crea una fila dentro de la hoja fila = hoja.createRow(1); // Se crea una celda dentro de la fila celda = fila.createCell(0); hoja.autoSizeColumn(0); // Se crea el contenido de la celda y se mete en ella. //HSSFRichTextString texto = new HSSFRichTextString("hola mundo"); celda.setCellValue(new HSSFRichTextString("Fecha")); // Se crea una celda dentro de la fila celda = fila.createCell(1); // Se crea el contenido de la celda y se mete en ella. //HSSFRichTextString texto = new HSSFRichTextString("hola mundo"); celda.setCellValue(new HSSFRichTextString("Total")); // Se crea una celda dentro de la fila celda = fila.createCell(2); // Se crea el contenido de la celda y se mete en ella. //HSSFRichTextString texto = new HSSFRichTextString("hola mundo"); celda.setCellValue(new HSSFRichTextString("Tipo")); // Style Cell 2B HSSFCellStyle cellStyle = libro.createCellStyle(); cellStyle = libro.createCellStyle(); cellStyle.setFillForegroundColor(org.apache.poi.hssf.util.HSSFColor.GREY_25_PERCENT.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cellStyle.setBorderTop((short) 1); // single line border cellStyle.setBorderBottom((short) 1); // single line border ProductoVendido oProductoVendido = new ProductoVendido(); ProductoVendido[] aProductoVendido = null; double nTotal = 0.0D; int rows = 1; String sFechaTemp = null; boolean bColor = true; if (aVentas != null && aVentas.length > 0) { boolean bPrimerFecha = true; for (Venta oVentaTemp : aVentas) { // Contador para inicializar la fecha del primer elemento if (bPrimerFecha) { sFechaTemp = oUtil.ordenarDiaMesAnio(oVentaTemp.getFecha()); bPrimerFecha = false; } else { String sFechaFila = oUtil.ordenarDiaMesAnio(oVentaTemp.getFecha()); if (!sFechaTemp.equals(sFechaFila)) { bColor = !bColor; } if (bColor) { cellStyle = libro.createCellStyle(); cellStyle.setFillForegroundColor(org.apache.poi.hssf.util.HSSFColor.GREY_25_PERCENT.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cellStyle.setBorderTop((short) 1); // single line border cellStyle.setBorderBottom((short) 1); // single line border } else { cellStyle = libro.createCellStyle(); cellStyle.setFillForegroundColor(org.apache.poi.hssf.util.HSSFColor.BLUE_GREY.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cellStyle.setBorderTop((short) 1); // single line border cellStyle.setBorderBottom((short) 1); // single line border } sFechaTemp = sFechaFila; } ++rows; hoja.autoSizeColumn(0); fila = hoja.createRow(rows); // Usuario oUsuario = new Usuario(); // oUsuario = oVentaTemp.getUsuario(); aProductoVendido = oVentaTemp.getProductoVendido(); // Se crea una celda dentro de la fila celda = fila.createCell(0); // Se crea el contenido de la celda y se mete en ella. celda.setCellValue(new HSSFRichTextString(oUtil.ordenarDiaMesAnio(oVentaTemp.getFecha()))); celda.setCellStyle(cellStyle); // Se crea una celda dentro de la fila celda = fila.createCell(1); // Se crea el contenido de la celda y se mete en ella. celda.setCellValue(new HSSFRichTextString(formato.format(aProductoVendido[0].getImporte()))); celda.setCellStyle(cellStyle); // Se crea una celda dentro de la fila celda = fila.createCell(2); // Se crea el contenido de la celda y se mete en ella. celda.setCellValue(new HSSFRichTextString(aProductoVendido[0].getProducto().getTipo())); celda.setCellStyle(cellStyle); nTotal += aProductoVendido[0].getImporte(); } ++rows; fila = hoja.createRow(rows); // Se crea una celda dentro de la fila celda = fila.createCell(0); // Se crea el contenido de la celda y se mete en ella. //HSSFRichTextString texton = new HSSFRichTextString("value"); celda.setCellValue(new HSSFRichTextString("Total")); // Se crea una celda dentro de la fila celda = fila.createCell(1); // Se crea el contenido de la celda y se mete en ella. celda.setCellValue(new HSSFRichTextString(formato.format(nTotal))); //this.campoTotal1.setText(formato.format(nTotal)); } // Se salva el libro. try { //FileOutputStream elFichero = new FileOutputStream("ventas"+new Date().toString()+".xls"); elFichero = new FileOutputStream(file); libro.write(elFichero); JOptionPane.showMessageDialog(null, "Reporte de ventas generado correctamente \n " + file.getPath()); } catch (Exception e) { e.printStackTrace(); } finally { elFichero.close(); } }
From source file:edu.ku.brc.dbsupport.TableModel2Excel.java
License:Open Source License
/** * Converts a tableModel to an Excel Spreadsheet. * @param toFile the file object to write it to. * @param title the title of the spreadsheet. * @param tableModel the table model/*from w w w.ja v a2s. c o m*/ * @return a file to a spreadsheet */ public static File convertToExcel(final File toFile, final String title, final TableModel tableModel) { if (toFile == null) { UIRegistry.showLocalizedMsg("WARNING", "FILE_NO_EXISTS", toFile != null ? toFile.getAbsolutePath() : ""); return null; } if (tableModel != null && tableModel.getRowCount() > 0) { try { // create a new file FileOutputStream out; try { out = new FileOutputStream(toFile); } catch (FileNotFoundException ex) { UIRegistry.showLocalizedMsg("WARNING", "FILE_NO_WRITE", toFile != null ? toFile.getAbsolutePath() : ""); return null; } // create a new workbook HSSFWorkbook wb = new HSSFWorkbook(); // create a new sheet HSSFSheet sheet = wb.createSheet(); // declare a row object reference // Header Captions HSSFFont headerFont = wb.createFont(); headerFont.setFontHeightInPoints((short) 12); headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // create a style for the header cell HSSFCellStyle headerStyle = wb.createCellStyle(); headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headerStyle.setFont(headerFont); setBordersOnStyle(headerStyle, HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_THIN); short numColumns = (short) tableModel.getColumnCount(); HSSFRow headerRow = sheet.createRow(0); for (int i = 0; i < numColumns; i++) { HSSFCell headerCell = headerRow.createCell((short) i); headerCell.setCellStyle(headerStyle); //add the date to the header cell headerCell.setCellValue(tableModel.getColumnName(i)); sheet.setColumnWidth((short) i, (short) (30 * 256)); } //-------------------------- // done header //-------------------------- // create 3 cell styles HSSFCellStyle oddCellStyle = wb.createCellStyle(); HSSFCellStyle evenCellStyle = wb.createCellStyle(); setBordersOnStyle(oddCellStyle, HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_THIN); setBordersOnStyle(evenCellStyle, HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_THIN); // create 2 fonts objects HSSFFont cellFont = wb.createFont(); //set font 1 to 12 point type cellFont.setFontHeightInPoints((short) 11); oddCellStyle.setFont(cellFont); evenCellStyle.setFont(cellFont); evenCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); oddCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); oddCellStyle.setFillForegroundColor(HSSFColor.WHITE.index); evenCellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); oddCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); evenCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // set the sheet name to HSSF Test wb.setSheetName(0, title); for (short rownum = 0; rownum < (short) tableModel.getRowCount(); rownum++) { // create a row HSSFRow row = sheet.createRow(rownum + 1); for (short cellnum = (short) 0; cellnum < numColumns; cellnum++) { // create a numeric cell HSSFCell cell = row.createCell(cellnum); Object dataVal = tableModel.getValueAt(rownum, cellnum); cell.setCellValue(dataVal != null ? dataVal.toString() : ""); // on every other row cell.setCellStyle((rownum % 2) == 0 ? evenCellStyle : oddCellStyle); } } // write the workbook to the output stream // close our file (don't blow out our file handles wb.write(out); out.close(); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TableModel2Excel.class, ex); log.error("convertToExcel", ex); //$NON-NLS-1$ } } return toFile; }
From source file:es.jamisoft.comun.io.excel.ExcelGenerator.java
License:Apache License
/** * Este mtodo gestiona el estilo que se proporcionar a las cabeceras. * * @param wb Objeto Excel./*from w w w. j a v a2 s. c o m*/ */ private void initStylesHeader(HSSFWorkbook wb) { // create instance of HSSFCellStyle HSSFCellStyle headerStyle = wb.createCellStyle(); // Create Font Header createFontCell(wb, headerStyle, ep.getFillFontColorHeader()); headerStyle.getFont(wb).setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // Create style of header cell HSSFPalette palette = wb.getCustomPalette(); HSSFColor colorMapfreHSSF = palette.findColor((byte) ep.getColorMapfre().getRed(), (byte) ep.getColorMapfre().getGreen(), (byte) ep.getColorMapfre().getBlue()); if (colorMapfreHSSF == null) { palette.setColorAtIndex(HSSFColor.LAVENDER.index, (byte) ep.getColorMapfre().getRed(), (byte) ep.getColorMapfre().getGreen(), (byte) ep.getColorMapfre().getBlue()); colorMapfreHSSF = palette.getColor(HSSFColor.LAVENDER.index); } short fillBGColor = colorMapfreHSSF.getIndex(); headerStyle.setFillForegroundColor(fillBGColor); headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // create border of header cell createBorderCells(headerStyle); // set ep.setHeaderStyle(headerStyle); }
From source file:Excel.InformeArticulos.java
public void GenerarInforme(ArrayList listadoClientes) throws SQLException { HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja = libro.createSheet("Listado de Articulos"); ArrayList listadoPorSucursal = new ArrayList(); Editables edi = new Articulos(); /*//from www .ja v a2s . c o m * GENERAR LAS SIGUIENTES HOJAS * 1- DETALLE DE MOVIMIENTOS DE CAJA - LEE EN MOVIMIENTOS CAJA INDENTIFICANDO EL TIPO DE MOVIMIENTO, USUARIOS Y * NUMERO DE CAJA * 2- DETALLE DE ARTICULOS VENDIDOS: LISTADO DE MOVIEMIENTOS DE ARTICULOS, CON USUARIOS Y CAJA * 3- DETALLE DE GASTOS : MOVIMIENTOS DE CAJA DETALLANDO LOS GASTOS * */ String ttx = "celda numero :"; HSSFRow fila = null; HSSFCell celda; HSSFCell celda1; HSSFCell celda2; HSSFCell celda3; HSSFCell celda4; HSSFCell celda5; HSSFCell celda6; HSSFCell celda7; HSSFCell celda8; HSSFCell celda9; HSSFCell celda10; HSSFCell celda11; HSSFFont fuente = libro.createFont(); //fuente.setFontHeight((short)21); fuente.setFontName(fuente.FONT_ARIAL); fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); String form = null; HSSFCellStyle titulo = libro.createCellStyle(); Iterator iCli = listadoClientes.listIterator(); Articulos cliente = new Articulos(); titulo.setFont(fuente); //titulo.setFillBackgroundColor((short)22); titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //for(int a=0;a < 100;a++){ int col = 0; int a = 0; if (a == 0) { fila = hoja.createRow(a); celda = fila.createCell(0); celda.setCellStyle(titulo); celda.setCellValue("Codigo"); celda1 = fila.createCell(1); celda1.setCellStyle(titulo); celda1.setCellValue("Descripcion"); celda2 = fila.createCell(2); celda2.setCellStyle(titulo); celda2.setCellValue("Stock"); celda3 = fila.createCell(3); celda3.setCellStyle(titulo); celda3.setCellValue("Stock Mnimo"); celda4 = fila.createCell(4); celda4.setCellStyle(titulo); celda4.setCellValue("Costo"); celda5 = fila.createCell(5); celda5.setCellStyle(titulo); celda5.setCellValue("Precio de Venta"); celda6 = fila.createCell(6); celda6.setCellStyle(titulo); celda6.setCellValue("Servicio"); } while (iCli.hasNext()) { cliente = (Articulos) iCli.next(); a++; //col=rs.getInt("tipoMovimiento"); switch (col) { case 1: break; default: break; } fila = hoja.createRow(a); celda = fila.createCell(0); ttx = ttx; celda.setCellType(HSSFCell.CELL_TYPE_STRING); celda.setCellValue(cliente.getCodigoAsignado()); celda1 = fila.createCell(1); ttx = ttx; celda1.setCellType(HSSFCell.CELL_TYPE_STRING); celda1.setCellValue(cliente.getDescripcionArticulo()); celda2 = fila.createCell(2); celda2.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda2.setCellValue(cliente.getStockActual()); celda3 = fila.createCell(3); celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda3.setCellValue(cliente.getStockMinimo()); celda4 = fila.createCell(4); celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda4.setCellValue(cliente.getPrecioDeCosto()); celda5 = fila.createCell(5); //celda5.setCellFormula(rs.getString("observaciones")); celda5.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda5.setCellValue(cliente.getPrecioUnitarioNeto()); //celda5.setCellValue(rs.getDate("fecha")); celda6 = fila.createCell(6); //celda5.setCellFormula(rs.getString("observaciones")); celda6.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda6.setCellValue(cliente.getPrecioServicio()); listadoPorSucursal = edi.ListarPorSucursal(cliente); Iterator il = listadoPorSucursal.listIterator(); Articulos arr = new Articulos(); int cont = 0; while (il.hasNext()) { arr = (Articulos) il.next(); cont++; switch (cont) { case 1: celda7 = fila.createCell(7); celda7.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda7.setCellValue(arr.getCantidad()); break; case 2: celda8 = fila.createCell(8); celda8.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda8.setCellValue(arr.getCantidad()); break; case 3: celda9 = fila.createCell(9); celda9.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda9.setCellValue(arr.getCantidad()); break; case 4: celda10 = fila.createCell(10); celda10.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda10.setCellValue(arr.getCantidad()); break; } } } //texto+="\r\n"; String ruta = "C://Informes//listadoDeArticulos.xls"; try { FileOutputStream elFichero = new FileOutputStream(ruta); try { libro.write(elFichero); elFichero.close(); Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + ruta); } catch (IOException ex) { Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Excel.InformeDiarioStock.java
public void GenerrarInformeStock() throws SQLException { HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja = libro.createSheet("Articulos"); /*//from w ww . j av a 2 s .co m * GENERAR LAS SIGUIENTES HOJAS * 1- DETALLE DE MOVIMIENTOS DE CAJA - LEE EN MOVIMIENTOS CAJA INDENTIFICANDO EL TIPO DE MOVIMIENTO, USUARIOS Y * NUMERO DE CAJA * 2- DETALLE DE ARTICULOS VENDIDOS: LISTADO DE MOVIEMIENTOS DE ARTICULOS, CON USUARIOS Y CAJA * 3- DETALLE DE GASTOS : MOVIMIENTOS DE CAJA DETALLANDO LOS GASTOS * */ HSSFSheet hoja1 = libro.createSheet("Movimientos"); HSSFSheet hoja2 = libro.createSheet("Movimientos Caja"); String ttx = "celda numero :"; HSSFRow fila = null; HSSFCell celda; HSSFCell celda1; HSSFCell celda2; HSSFCell celda3; HSSFCell celda4; HSSFCell celda5; HSSFCell celda6; HSSFCell celda7; HSSFCell celda8; HSSFCell celda9; HSSFCell celda10; HSSFFont fuente = libro.createFont(); //fuente.setFontHeight((short)21); fuente.setFontName(fuente.FONT_ARIAL); fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); String form = null; //String sql="select id,nombre,(select sum(movimientosarticulos.cantidad) from movimientosarticulos where movimientosarticulos.idarticulo=articulos.id and movimientosarticulos.numerodeposito="+Inicio.deposito.getNumero()+")as stock,(select sum(movimientosarticulos.cantidad) from movimientosarticulos where movimientosarticulos.idcaja="+Inicio.caja.getNumero()+" and movimientosarticulos.idarticulo=articulos.id)as cantidadVendida from articulos"; String sql = "select *,(select articulos.NOMBRE from articulos where articulos.ID=movimientosarticulos.idArticulo)as descripcion from movimientosarticulos where idcaja=" + Inicio.caja.getNumero(); System.out.println(sql); Transaccionable tra = new ConeccionLocal(); ResultSet rs = tra.leerConjuntoDeRegistros(sql); HSSFCellStyle titulo = libro.createCellStyle(); titulo.setFont(fuente); //titulo.setFillBackgroundColor((short)22); titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //for(int a=0;a < 100;a++){ int col = 0; int a = 0; if (a == 0) { fila = hoja.createRow(a); celda = fila.createCell(0); celda.setCellStyle(titulo); celda.setCellValue("id"); celda1 = fila.createCell(1); celda1.setCellStyle(titulo); celda1.setCellValue("nombre"); celda2 = fila.createCell(2); celda2.setCellStyle(titulo); celda2.setCellValue("Unidades Vendidas"); celda3 = fila.createCell(3); celda3.setCellStyle(titulo); celda3.setCellValue("Fecha"); } while (rs.next()) { a++; //col=rs.getInt("tipoMovimiento"); switch (col) { case 1: break; default: break; } fila = hoja.createRow(a); celda = fila.createCell(0); ttx = ttx; Double anterior = 0.00; Double actual = 0.00; Double vendido = 0.00; celda.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda.setCellValue(rs.getInt("idArticulo")); celda1 = fila.createCell(1); ttx = ttx; celda1.setCellType(HSSFCell.CELL_TYPE_STRING); celda1.setCellValue(rs.getString("descripcion")); celda2 = fila.createCell(2); vendido = (rs.getDouble("cantidad")) * -1; //actual=rs.getDouble("stock"); celda2.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda2.setCellValue(vendido); celda3 = fila.createCell(3); //vendido=(rs.getDouble("cantidadVendida")) * -1; celda3.setCellType(HSSFCell.CELL_TYPE_STRING); celda3.setCellValue(rs.getString("fecha")); } //rs.close(); // hoja 2 form = null; sql = "SELECT id,cantidad,preciodecosto,preciodeventa,precioservicio,fecha,numerocomprobante,(select listcli.RAZON_SOCI from listcli where listcli.codMmd=movimientosarticulos.numeroCliente limit 0,1)as nombreC,(select articulos.NOMBRE from articulos where articulos.ID=movimientosarticulos.idArticulo limit 0,1)as descA,(select usuarios.nombre from usuarios where usuarios.numero=movimientosarticulos.numeroUsuario limit 0,1) as nombreU FROM movimientosarticulos where tipoMovimiento =1 and idcaja=" + Inicio.caja.getNumero(); //System.out.println(sql); //tra=new Conecciones(); rs = tra.leerConjuntoDeRegistros(sql); //HSSFCellStyle titulo=libro.createCellStyle(); titulo.setFont(fuente); //titulo.setFillBackgroundColor((short)22); titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //for(int a=0;a < 100;a++){ col = 0; a = 0; if (a == 0) { fila = hoja1.createRow(a); celda = fila.createCell(0); celda.setCellStyle(titulo); celda.setCellValue("Cajero"); celda1 = fila.createCell(1); celda1.setCellStyle(titulo); celda1.setCellValue("Descripcion Articulo"); celda2 = fila.createCell(2); celda2.setCellStyle(titulo); celda2.setCellValue("Cantidad"); celda3 = fila.createCell(3); celda3.setCellStyle(titulo); celda3.setCellValue("Precio de Costo"); celda4 = fila.createCell(4); celda4.setCellStyle(titulo); celda4.setCellValue("Precio de Venta"); celda5 = fila.createCell(5); celda5.setCellStyle(titulo); celda5.setCellValue("Fecha"); celda6 = fila.createCell(6); celda6.setCellStyle(titulo); celda6.setCellValue("Precio de Servicio"); celda7 = fila.createCell(7); celda7.setCellStyle(titulo); celda7.setCellValue("comprobante"); celda8 = fila.createCell(8); celda8.setCellStyle(titulo); celda8.setCellValue("Cliente"); celda9 = fila.createCell(9); celda9.setCellStyle(titulo); celda9.setCellValue("Total"); celda10 = fila.createCell(10); celda10.setCellStyle(titulo); celda10.setCellValue("idMovimiento"); } while (rs.next()) { a++; //col=rs.getInt("tipoMovimiento"); switch (col) { case 1: break; default: break; } fila = hoja1.createRow(a); celda = fila.createCell(0); ttx = ttx; celda.setCellType(HSSFCell.CELL_TYPE_STRING); celda.setCellValue(rs.getString("nombreU")); celda1 = fila.createCell(1); ttx = ttx; celda1.setCellType(HSSFCell.CELL_TYPE_STRING); celda1.setCellValue(rs.getString("descA")); celda2 = fila.createCell(2); celda2.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda2.setCellValue(rs.getDouble("cantidad")); celda3 = fila.createCell(3); celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda3.setCellValue(rs.getDouble("precioDeCosto")); celda4 = fila.createCell(4); celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda4.setCellValue(rs.getDouble("precioDeVenta")); celda5 = fila.createCell(5); //celda5.setCellFormula(rs.getString("observaciones")); celda5.setCellType(HSSFCell.CELL_TYPE_STRING); celda5.setCellValue(" " + rs.getDate("fecha")); //celda5.setCellValue(rs.getDate("fecha")); celda6 = fila.createCell(6); celda6.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda6.setCellValue(rs.getDouble("precioServicio")); celda7 = fila.createCell(7); celda7.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda7.setCellValue(rs.getInt("numeroComprobante")); celda8 = fila.createCell(8); celda8.setCellType(HSSFCell.CELL_TYPE_STRING); celda8.setCellValue(rs.getString("nombreC")); celda9 = fila.createCell(9); celda9.setCellType(HSSFCell.CELL_TYPE_NUMERIC); Double tto = 0.00; tto = rs.getDouble("precioServicio") + rs.getDouble("precioDeVenta"); celda9.setCellValue(tto); celda10 = fila.createCell(10); celda10.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda10.setCellValue(rs.getInt("id")); } form = null; sql = "SELECT *,(select usuarios.nombre from usuarios where usuarios.numero=movimientoscaja.numeroUsuario)as nombreUsuario,(select listcli.RAZON_SOCI from listcli where listcli.id=movimientoscaja.idCliente)as nombreCliente,(select tipocomprobantes.descripcion from tipocomprobantes where tipocomprobantes.numero=movimientoscaja.tipoComprobante)as nombreComprobante,(select tipomovimientos.DESCRIPCION from tipomovimientos where tipomovimientos.ID=movimientoscaja.tipoMovimiento)as nombreMov FROM movimientoscaja where idcaja=" + Inicio.caja.getNumero() + " order by id"; //System.out.println(sql); //tra=new Conecciones(); rs = tra.leerConjuntoDeRegistros(sql); //HSSFCellStyle titulo=libro.createCellStyle(); titulo.setFont(fuente); //titulo.setFillBackgroundColor((short)22); titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //for(int a=0;a < 100;a++){ col = 0; a = 0; if (a == 0) { fila = hoja2.createRow(a); celda = fila.createCell(0); celda.setCellStyle(titulo); celda.setCellValue("Cajero"); celda1 = fila.createCell(1); celda1.setCellStyle(titulo); celda1.setCellValue("Cliente"); celda2 = fila.createCell(2); celda2.setCellStyle(titulo); celda2.setCellValue("Comprobante Numero"); celda3 = fila.createCell(3); celda3.setCellStyle(titulo); celda3.setCellValue("Tipo Comprobante"); celda4 = fila.createCell(4); celda4.setCellStyle(titulo); celda4.setCellValue("Monto"); celda5 = fila.createCell(5); celda5.setCellStyle(titulo); celda5.setCellValue("Fecha"); celda6 = fila.createCell(6); celda6.setCellStyle(titulo); celda6.setCellValue("Tipo de Movimiento"); celda7 = fila.createCell(7); celda7.setCellStyle(titulo); celda7.setCellValue("Condicion"); celda8 = fila.createCell(8); celda8.setCellStyle(titulo); celda8.setCellValue("idMovimiento"); } while (rs.next()) { a++; //col=rs.getInt("tipoMovimiento"); switch (col) { case 1: break; default: break; } fila = hoja2.createRow(a); celda = fila.createCell(0); ttx = ttx; celda.setCellType(HSSFCell.CELL_TYPE_STRING); celda.setCellValue(rs.getString("nombreUsuario")); celda1 = fila.createCell(1); ttx = ttx; celda1.setCellType(HSSFCell.CELL_TYPE_STRING); celda1.setCellValue(rs.getString("nombreCliente")); celda2 = fila.createCell(2); celda2.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda2.setCellValue(rs.getInt("numeroComprobante")); celda3 = fila.createCell(3); celda3.setCellType(HSSFCell.CELL_TYPE_STRING); celda3.setCellValue(rs.getString("nombreComprobante")); celda4 = fila.createCell(4); celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda4.setCellValue(rs.getDouble("monto")); celda5 = fila.createCell(5); //celda5.setCellFormula(rs.getString("observaciones")); celda5.setCellType(HSSFCell.CELL_TYPE_STRING); celda5.setCellValue(" " + rs.getDate("fecha")); //celda5.setCellValue(rs.getDate("fecha")); celda6 = fila.createCell(6); celda6.setCellType(HSSFCell.CELL_TYPE_STRING); celda6.setCellValue(rs.getString("nombreMov")); celda7 = fila.createCell(7); String pagado = "PAGADO"; if (rs.getInt("pagado") == 0 && rs.getInt("tipoMovimiento") == 1) pagado = "CTA CTE"; celda7.setCellType(HSSFCell.CELL_TYPE_STRING); celda7.setCellValue(pagado); celda8 = fila.createCell(8); celda8.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda8.setCellValue(rs.getInt("id")); } rs.close(); //texto+="\r\n"; String ruta = "C://Informes//" + Inicio.fechaDia + "_" + Inicio.usuario.getNombre() + " - informeDeStock.xls"; String nombree = Inicio.fechaDia + "_" + Inicio.usuario.getNombre() + " - informeDeStock.xls"; try { FileOutputStream elFichero = new FileOutputStream(ruta); try { libro.write(elFichero); elFichero.close(); Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + ruta); Mail mail = new Mail(); String mailRecepcion = Propiedades.getCORREOCIERREDECAJA(); mail.setDetalleListado(nombree); mail.setDireccionFile(ruta); mail.setAsunto("Informe de cierre de caja " + Inicio.fechaDia + " Sucursal: " + Propiedades.getNOMBRECOMERCIO()); mail.enviarMailRepartoCargaCompleta(mailRecepcion); } catch (IOException ex) { Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex); } catch (MessagingException ex) { Logger.getLogger(InformeDiarioStock.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, "NO SE HA PODIDO ENVIAR EL MENSAJE MOTIVO :" + ex); } } catch (FileNotFoundException ex) { Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex); } sql = "select id,nombre,precio,servicio,(select sum(movimientosarticulos.cantidad) from movimientosarticulos where movimientosarticulos.idcaja=" + Inicio.caja.getNumero() + " and movimientosarticulos.idarticulo=articulos.id)as cantidadVendida from articulos order by cantidadVendida desc"; rs = tra.leerConjuntoDeRegistros(sql); System.out.println(sql); Transaccionable tt = new Conecciones(); String sql1; Double cantVend; while (rs.next()) { cantVend = rs.getDouble("cantidadVendida"); if (cantVend < 0) { //sql1="insert into movimientosarticulosF (tipoMovimiento,idArticulo,cantidad,numeroDeposito,tipoComprobante,numeroCliente,numerousuario,precioDeVenta,precioServicio,idcaja) values (1,"+rs.getInt("id")+",floor("+rs.getDouble("cantidadVendida")+" * 0.1),"+Inicio.deposito.getNumero()+",1,1,"+Inicio.usuario.getNumeroId()+","+rs.getDouble("precio")+","+rs.getDouble("servicio")+","+Inicio.caja.getNumero()+")"; //System.out.println(sql1); //tt.guardarRegistro(sql1); } } }
From source file:Excel.InformesClientes.java
public void GenerarInforme(ArrayList listadoClientes, String desde, String hasta) throws SQLException { HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja = libro.createSheet("Saldos de Clientes"); HSSFSheet hoja1 = libro.createSheet("Detalle de Saldos"); /*/*from w w w . j av a 2s . c o m*/ * GENERAR LAS SIGUIENTES HOJAS * 1- DETALLE DE MOVIMIENTOS DE CAJA - LEE EN MOVIMIENTOS CAJA INDENTIFICANDO EL TIPO DE MOVIMIENTO, USUARIOS Y * NUMERO DE CAJA * 2- DETALLE DE ARTICULOS VENDIDOS: LISTADO DE MOVIEMIENTOS DE ARTICULOS, CON USUARIOS Y CAJA * 3- DETALLE DE GASTOS : MOVIMIENTOS DE CAJA DETALLANDO LOS GASTOS * */ String ttx = "celda numero :"; HSSFRow fila = null; HSSFCell celda; HSSFCell celda1; HSSFCell celda2; HSSFCell celda3; HSSFCell celda4; HSSFCell celda5; HSSFCell celda6; HSSFCell celda7; HSSFCell celda8; HSSFFont fuente = libro.createFont(); //fuente.setFontHeight((short)21); fuente.setFontName(fuente.FONT_ARIAL); fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); String form = null; String sql = ""; System.out.println(sql); Transaccionable tra = new Conecciones(); ResultSet rs = null; HSSFCellStyle titulo = libro.createCellStyle(); Iterator iCli = listadoClientes.listIterator(); ClientesTango cliente = new ClientesTango(); titulo.setFont(fuente); //titulo.setFillBackgroundColor((short)22); titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //for(int a=0;a < 100;a++){ int col = 0; int a = 0; if (a == 0) { fila = hoja.createRow(a); celda = fila.createCell(0); celda.setCellStyle(titulo); celda.setCellValue("Cod. Cliente"); celda1 = fila.createCell(1); celda1.setCellStyle(titulo); celda1.setCellValue("Nombre"); celda2 = fila.createCell(2); celda2.setCellStyle(titulo); celda2.setCellValue("Direccion"); celda3 = fila.createCell(3); celda3.setCellStyle(titulo); celda3.setCellValue("Telfono"); celda4 = fila.createCell(4); celda4.setCellStyle(titulo); celda4.setCellValue("Cupo de Crdito"); celda5 = fila.createCell(5); celda5.setCellStyle(titulo); celda5.setCellValue("Saldo"); } while (iCli.hasNext()) { cliente = (ClientesTango) iCli.next(); a++; //col=rs.getInt("tipoMovimiento"); switch (col) { case 1: break; default: break; } fila = hoja.createRow(a); celda = fila.createCell(0); ttx = ttx; celda.setCellType(HSSFCell.CELL_TYPE_STRING); celda.setCellValue(cliente.getCodigoCliente()); celda1 = fila.createCell(1); ttx = ttx; celda1.setCellType(HSSFCell.CELL_TYPE_STRING); celda1.setCellValue(cliente.getRazonSocial()); celda2 = fila.createCell(2); celda2.setCellType(HSSFCell.CELL_TYPE_STRING); celda2.setCellValue(cliente.getDireccion()); celda3 = fila.createCell(3); celda3.setCellType(HSSFCell.CELL_TYPE_STRING); celda3.setCellValue(cliente.getTelefono()); celda4 = fila.createCell(4); celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda4.setCellValue(cliente.getCupoDeCredito()); celda5 = fila.createCell(5); //celda5.setCellFormula(rs.getString("observaciones")); celda5.setCellType(HSSFCell.CELL_TYPE_NUMERIC); if (cliente.getSaldo() != null) { celda5.setCellValue(cliente.getSaldo()); } else { celda5.setCellValue(0.00); } //celda5.setCellValue(rs.getDate("fecha")); } /* * segunda hoja */ Busquedas bus = new ClientesTango(); sql = "select numeroProveedor,fecha,monto,numeroComprobante,idUsuario,idCaja,(select tipomovimientos.descripcion from tipomovimientos where tipomovimientos.ID=movimientosclientes.tipoComprobante)as tipocomprobante1,idSucursal,(select listcli.razon_soci from listcli where listcli.codmmd=numeroProveedor)as nombreP from movimientosclientes where numeroProveedor > 1 and fecha between '" + desde + "' and '" + hasta + "' group by numeroComprobante,tipoComprobante order by numeroProveedor,fecha"; System.out.println(sql); //fuente.setFontHeight((short)21); fuente.setFontName(fuente.FONT_ARIAL); fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); form = null; //String sql="SELECT *,(select proveedores.nombre from proveedores where proveedores.numero=movimientosproveedores.numeroProveedor)as nombreP,if(pagado=0,'pendiente','pagado')as estado FROM movimientosproveedores where fecha between '"+desde+"' and '"+hasta+"'"; //System.out.println(sql); //tra=new Conecciones(); rs = tra.leerConjuntoDeRegistros(sql); titulo.setFont(fuente); //titulo.setFillBackgroundColor((short)22); titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //for(int a=0;a < 100;a++){ col = 0; a = 0; if (a == 0) { fila = hoja1.createRow(a); celda = fila.createCell(0); celda.setCellStyle(titulo); celda.setCellValue("Cliente"); celda1 = fila.createCell(1); celda1.setCellStyle(titulo); celda1.setCellValue("Sucursal"); celda2 = fila.createCell(2); celda2.setCellStyle(titulo); celda2.setCellValue("Fecha"); celda3 = fila.createCell(3); celda3.setCellStyle(titulo); celda3.setCellValue("Monto"); celda4 = fila.createCell(4); celda4.setCellStyle(titulo); celda4.setCellValue("Caja Numero"); celda5 = fila.createCell(5); celda5.setCellStyle(titulo); celda5.setCellValue("tipo de comprobante"); } while (rs.next()) { a++; //col=rs.getInt("tipoMovimiento"); switch (col) { case 1: break; default: break; } fila = hoja1.createRow(a); celda = fila.createCell(0); ttx = ttx; celda.setCellType(HSSFCell.CELL_TYPE_STRING); celda.setCellValue(rs.getString("nombreP")); celda1 = fila.createCell(1); ttx = ttx; celda1.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda1.setCellValue(rs.getInt("idSucursal")); celda2 = fila.createCell(2); celda2.setCellType(HSSFCell.CELL_TYPE_STRING); celda2.setCellValue(" " + rs.getString("fecha")); celda3 = fila.createCell(3); celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda3.setCellValue(rs.getDouble("monto")); celda4 = fila.createCell(4); celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda4.setCellValue(rs.getInt("idCaja")); celda5 = fila.createCell(5); celda5.setCellType(HSSFCell.CELL_TYPE_STRING); //if(rs.getInt("tipoComprobante")==11){ //celda5.setCellValue("Recibo de Pago"); //}else{ celda5.setCellValue(rs.getString("tipocomprobante1")); //} } rs.close(); //texto+="\r\n"; String ruta = "C://Informes//" + desde + "_" + hasta + "_informeDeClientes.xls"; try { FileOutputStream elFichero = new FileOutputStream(ruta); try { libro.write(elFichero); elFichero.close(); Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + ruta); } catch (IOException ex) { Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Excel.InformesClientes.java
public void GenerarInformeIndividual(ClientesTango idCliente) throws SQLException { HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja1 = libro.createSheet("Detalle de Saldos"); //HSSFSheet hoja1=libro.createSheet("Detalle de Saldos"); /*//from w w w.j a v a 2 s .c o m * GENERAR LAS SIGUIENTES HOJAS * 1- DETALLE DE MOVIMIENTOS DE CAJA - LEE EN MOVIMIENTOS CAJA INDENTIFICANDO EL TIPO DE MOVIMIENTO, USUARIOS Y * NUMERO DE CAJA * 2- DETALLE DE ARTICULOS VENDIDOS: LISTADO DE MOVIEMIENTOS DE ARTICULOS, CON USUARIOS Y CAJA * 3- DETALLE DE GASTOS : MOVIMIENTOS DE CAJA DETALLANDO LOS GASTOS * */ String ttx = "celda numero :"; HSSFRow fila = null; HSSFCell celda; HSSFCell celda1; HSSFCell celda2; HSSFCell celda3; HSSFCell celda4; HSSFCell celda5; HSSFCell celda6; HSSFCell celda7; HSSFCell celda8; HSSFFont fuente = libro.createFont(); //fuente.setFontHeight((short)21); fuente.setFontName(fuente.FONT_ARIAL); fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); String form = null; String sql = ""; System.out.println(sql); Transaccionable tra = new Conecciones(); ResultSet rs = null; HSSFCellStyle titulo = libro.createCellStyle(); //Iterator iCli=listadoClientes.listIterator(); ClientesTango cliente = new ClientesTango(); titulo.setFont(fuente); //titulo.setFillBackgroundColor((short)22); titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //for(int a=0;a < 100;a++){ int col = 0; int a = 0; /* * segunda hoja */ //Facturar bus=new ClientesTango(); cliente = idCliente; sql = "select numeroProveedor,fecha,monto,numeroComprobante,idUsuario,idCaja,(select tipomovimientos.descripcion from tipomovimientos where tipomovimientos.ID=movimientosclientes.tipoComprobante)as tipocomprobante1,idSucursal,(select listcli.razon_soci from listcli where listcli.codmmd=numeroProveedor)as nombreP from movimientosclientes where numeroProveedor=" + cliente.getCodigoId() + " group by numeroComprobante,tipoComprobante order by fecha desc"; System.out.println(sql); //fuente.setFontHeight((short)21); fuente.setFontName(fuente.FONT_ARIAL); fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); form = null; //String sql="SELECT *,(select proveedores.nombre from proveedores where proveedores.numero=movimientosproveedores.numeroProveedor)as nombreP,if(pagado=0,'pendiente','pagado')as estado FROM movimientosproveedores where fecha between '"+desde+"' and '"+hasta+"'"; //System.out.println(sql); //tra=new Conecciones(); rs = tra.leerConjuntoDeRegistros(sql); titulo.setFont(fuente); //titulo.setFillBackgroundColor((short)22); titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //for(int a=0;a < 100;a++){ col = 0; a = 0; if (a == 0) { fila = hoja1.createRow(a); celda = fila.createCell(0); celda.setCellStyle(titulo); celda.setCellValue("Cliente"); celda1 = fila.createCell(1); celda1.setCellStyle(titulo); celda1.setCellValue("Sucursal"); celda2 = fila.createCell(2); celda2.setCellStyle(titulo); celda2.setCellValue("Fecha"); celda3 = fila.createCell(3); celda3.setCellStyle(titulo); celda3.setCellValue("Monto"); celda4 = fila.createCell(4); celda4.setCellStyle(titulo); celda4.setCellValue("Caja Numero"); celda5 = fila.createCell(5); celda5.setCellStyle(titulo); celda5.setCellValue("tipo de comprobante"); } while (rs.next()) { a++; //col=rs.getInt("tipoMovimiento"); switch (col) { case 1: break; default: break; } fila = hoja1.createRow(a); celda = fila.createCell(0); ttx = ttx; celda.setCellType(HSSFCell.CELL_TYPE_STRING); celda.setCellValue(rs.getString("nombreP")); celda1 = fila.createCell(1); ttx = ttx; celda1.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda1.setCellValue(rs.getInt("idSucursal")); celda2 = fila.createCell(2); celda2.setCellType(HSSFCell.CELL_TYPE_STRING); celda2.setCellValue(" " + rs.getString("fecha")); celda3 = fila.createCell(3); celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda3.setCellValue(rs.getDouble("monto")); celda4 = fila.createCell(4); celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda4.setCellValue(rs.getInt("idCaja")); celda5 = fila.createCell(5); celda5.setCellType(HSSFCell.CELL_TYPE_STRING); //if(rs.getInt("tipoComprobante")==11){ //celda5.setCellValue("Recibo de Pago"); //}else{ celda5.setCellValue(rs.getString("tipocomprobante1")); //} } rs.close(); //texto+="\r\n"; String clie = cliente.getRazonSocial().replaceAll(" ", "_"); String ruta = "Informes\\" + clie + "_informeDetalleDeSaldo.xls"; try { FileOutputStream elFichero; elFichero = new FileOutputStream(ruta); try { libro.write(elFichero); elFichero.close(); Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + ruta); } catch (IOException ex) { Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(InformeMensual.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Excel.Informesfacturables.java
public void GenerarInforme(String desde, String hasta) throws SQLException, IOException { HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja = libro.createSheet("Resumen"); /*//from w w w . j a v a 2s .c o m * GENERAR LAS SIGUIENTES HOJAS * 1- DETALLE DE MOVIMIENTOS DE CAJA - LEE EN MOVIMIENTOS CAJA INDENTIFICANDO EL TIPO DE MOVIMIENTO, USUARIOS Y * NUMERO DE CAJA * 2- DETALLE DE ARTICULOS VENDIDOS: LISTADO DE MOVIEMIENTOS DE ARTICULOS, CON USUARIOS Y CAJA * 3- DETALLE DE GASTOS : MOVIMIENTOS DE CAJA DETALLANDO LOS GASTOS * */ String ttx = "celda numero :"; HSSFRow fila = null; HSSFCell celda; HSSFCell celda1; HSSFCell celda2; HSSFCell celda3; HSSFCell celda4; HSSFCell celda5; HSSFCell celda6; HSSFCell celda7; HSSFCell celda8; HSSFFont fuente = libro.createFont(); //fuente.setFontHeight((short)21); fuente.setFontName(fuente.FONT_ARIAL); fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); String form = null; String sql = "SELECT *,(select articulos.NOMBRE from articulos where articulos.ID=movimientosarticulosF.idArticulo)as descA,(select depositos.descripcion from depositos where depositos.numero=movimientosarticulosF.numeroDeposito)as depor FROM movimientosarticulosF WHERE idArticulo > 1 and fecha between '" + desde + "' and '" + hasta + "'"; System.out.println(sql); Transaccionable tra = new Conecciones(); ResultSet rs = tra.leerConjuntoDeRegistros(sql); HSSFCellStyle titulo = libro.createCellStyle(); titulo.setFont(fuente); //titulo.setFillBackgroundColor((short)22); titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //for(int a=0;a < 100;a++){ int col = 0; int a = 0; Integer cantidad = 0; Double total = 0.00; if (a == 0) { fila = hoja.createRow(a); celda = fila.createCell(0); celda.setCellStyle(titulo); celda.setCellValue("Fecha"); celda1 = fila.createCell(1); celda1.setCellStyle(titulo); celda1.setCellValue("Codigo"); celda2 = fila.createCell(2); celda2.setCellStyle(titulo); celda2.setCellValue("Articulo"); celda3 = fila.createCell(3); celda3.setCellStyle(titulo); celda3.setCellValue("Cantidad"); celda4 = fila.createCell(4); celda4.setCellStyle(titulo); celda4.setCellValue("Precio Unitario"); celda5 = fila.createCell(5); celda5.setCellStyle(titulo); celda5.setCellValue("Total"); celda6 = fila.createCell(6); celda6.setCellStyle(titulo); celda6.setCellValue("idCaja"); celda7 = fila.createCell(7); celda7.setCellStyle(titulo); celda7.setCellValue("Sucursal"); } while (rs.next()) { a++; //col=rs.getInt("tipoMovimiento"); switch (col) { case 1: break; default: break; } fila = hoja.createRow(a); celda = fila.createCell(0); ttx = ttx; celda.setCellType(HSSFCell.CELL_TYPE_STRING); celda.setCellValue(rs.getString("fecha")); celda1 = fila.createCell(1); ttx = ttx; celda1.setCellType(HSSFCell.CELL_TYPE_STRING); celda1.setCellValue(rs.getString("idArticulo")); celda2 = fila.createCell(2); celda2.setCellType(HSSFCell.CELL_TYPE_STRING); celda2.setCellValue(rs.getString("descA")); celda3 = fila.createCell(3); cantidad = 0; total = 0.00; cantidad = rs.getInt("cantidad") * -1; total = rs.getDouble("precioDeVenta") * cantidad; celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda3.setCellValue(cantidad); celda4 = fila.createCell(4); celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda4.setCellValue(rs.getDouble("precioDeVenta")); celda5 = fila.createCell(5); //celda5.setCellFormula(rs.getString("observaciones")); celda5.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda5.setCellValue(total); //celda5.setCellValue(rs.getDate("fecha")); celda6 = fila.createCell(6); celda6.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda6.setCellValue(rs.getInt("idcaja")); celda7 = fila.createCell(7); celda7.setCellType(HSSFCell.CELL_TYPE_STRING); celda7.setCellValue(rs.getString("depor")); } rs.close(); //texto+="\r\n"; String ruta = "C://Informes//informeFacturables.xls"; try { FileOutputStream elFichero = new FileOutputStream(ruta); try { libro.write(elFichero); elFichero.close(); Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + ruta); } catch (IOException ex) { Logger.getLogger(Informesfacturables.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(Informesfacturables.class.getName()).log(Level.SEVERE, null, ex); } }