List of usage examples for org.apache.poi.hssf.usermodel HSSFCell setCellValue
@SuppressWarnings("fallthrough") public void setCellValue(boolean value)
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 ww w. ja 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; 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"); /*/* ww w . j a v a 2 s . com*/ * 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 ww w . j ava 2s . c om*/ * 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 ww w. j a va2 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 av a2s . c om*/ * 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); } }
From source file:Excel.InformesRemitosInternos.java
public void GenerarInforme(String desde, String hasta) throws SQLException, FileNotFoundException, IOException { HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja = libro.createSheet("Resumen"); /*//from w w w. ja v a2s.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 * */ 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 depositos.descripcion from depositos where depositos.numero=movimientosdesucursales.depOrigen)as depor,(select depositos.descripcion from depositos where depositos.numero=movimientosdesucursales.depDestino)as depod,(select articulos.NOMBRE from articulos where articulos.ID=movimientosdesucursales.idArticulo)as descA FROM movimientosdesucursales where 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; Double total = 0.00; 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("Articulo"); celda2 = fila.createCell(2); celda2.setCellStyle(titulo); celda2.setCellValue("Cantidad"); celda3 = fila.createCell(3); celda3.setCellStyle(titulo); celda3.setCellValue("Costo"); celda4 = fila.createCell(4); celda4.setCellStyle(titulo); celda4.setCellValue("Remito"); celda5 = fila.createCell(5); celda5.setCellStyle(titulo); celda5.setCellValue("Origen"); celda6 = fila.createCell(6); celda6.setCellStyle(titulo); celda6.setCellValue("Destino"); celda7 = fila.createCell(7); celda7.setCellStyle(titulo); celda7.setCellValue("Fecha"); celda8 = fila.createCell(8); celda8.setCellStyle(titulo); celda8.setCellValue("Total"); } 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; total = 0.00; celda.setCellType(HSSFCell.CELL_TYPE_STRING); celda.setCellValue(rs.getString("idArticulo")); 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.getInt("cantidad")); celda3 = fila.createCell(3); celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda3.setCellValue(rs.getDouble("costo")); total = rs.getInt("cantidad") * rs.getDouble("costo"); celda4 = fila.createCell(4); celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda4.setCellValue(rs.getInt("numeroRemito")); celda5 = fila.createCell(5); //celda5.setCellFormula(rs.getString("observaciones")); celda5.setCellType(HSSFCell.CELL_TYPE_STRING); celda5.setCellValue(rs.getString("depor")); //celda5.setCellValue(rs.getDate("fecha")); celda6 = fila.createCell(6); celda6.setCellType(HSSFCell.CELL_TYPE_STRING); celda6.setCellValue(rs.getString("depod")); celda7 = fila.createCell(7); celda7.setCellType(HSSFCell.CELL_TYPE_STRING); celda7.setCellValue(rs.getString("fecha")); celda8 = fila.createCell(8); celda8.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda8.setCellValue(total); } rs.close(); //texto+="\r\n"; String ruta = "C://Informes//informedeRemitosInternos.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(InformesRemitosInternos.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(InformesRemitosInternos.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Excel.IvaVentas.java
public void GenerrarInformeIvaVentas(String desde, String hasta) throws SQLException { HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja = libro.createSheet("Iva Ventas"); /*//w w w.j a va 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 *,round(gravado,2)as gravadoR,round(impuesto,2)as impuestoR,round(total,2)as totalR FROM fiscal where fechaRegistro between '" + desde + "' and '" + hasta + "' group by numero order by numero"; //String sql="SELECT *,round(gravado,2)as gravadoR,round(impuesto,2)as impuestoR,round(total,2)as totalR FROM fiscal where fecha like '201607%' group by numero order by numero"; 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("Fecha"); celda1 = fila.createCell(1); celda1.setCellStyle(titulo); celda1.setCellValue("Tipo comp."); celda2 = fila.createCell(2); celda2.setCellStyle(titulo); celda2.setCellValue("Numero"); celda3 = fila.createCell(3); celda3.setCellStyle(titulo); celda3.setCellValue("Gravado"); celda4 = fila.createCell(4); celda4.setCellStyle(titulo); celda4.setCellValue("Impuesto"); celda5 = fila.createCell(5); celda5.setCellStyle(titulo); celda5.setCellValue("Total"); celda6 = fila.createCell(6); celda6.setCellStyle(titulo); celda6.setCellValue("Razon Social"); } 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.getInt("tipo")); celda2 = fila.createCell(2); celda2.setCellType(HSSFCell.CELL_TYPE_STRING); String numero = rs.getString("numero").replaceFirst("80", "00"); celda2.setCellValue(numero); celda3 = fila.createCell(3); celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda3.setCellValue(rs.getDouble("gravadoR")); celda4 = fila.createCell(4); celda4.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda4.setCellValue(rs.getDouble("impuestoR")); celda5 = fila.createCell(5); //celda5.setCellFormula(rs.getString("observaciones")); celda5.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda5.setCellValue(rs.getDouble("totalR")); //celda5.setCellValue(rs.getDate("fecha")); celda6 = fila.createCell(6); celda6.setCellType(HSSFCell.CELL_TYPE_STRING); celda6.setCellValue(rs.getString("razon")); } rs.close(); //texto+="\r\n"; String ruta = "fiscal/" + desde + "_" + hasta + " Iva Ventas.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.PlanillaStock.java
public void GenerarInforme() throws SQLException { HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja = libro.createSheet("Listado de Articulos"); ArrayList listadoPorSucursal = new ArrayList(); Editables edi = new Articulos(); /*//from w ww . j a 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; titulo.setFont(fuente); //titulo.setFillBackgroundColor((short)22); titulo.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFCellStyle celdas = libro.createCellStyle(); celdas.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); celdas.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); celdas.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); celdas.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); celdas.setBottomBorderColor(IndexedColors.BLACK.getIndex()); celdas.setLeftBorderColor(IndexedColors.BLACK.getIndex()); celdas.setRightBorderColor(IndexedColors.BLACK.getIndex()); celdas.setTopBorderColor(IndexedColors.BLACK.getIndex()); int a = 0; String sql = "select *,(select sum(cantidad) FROM movimientosarticulos where movimientosarticulos.idArticulo=articulos.ID group by idArticulo,numeroDeposito limit 0,1)as sstock,round((articulos.dolar * articulos.PRECIO),2)as pl1,round((articulos.dolar * articulos.lista2),2)as pl2,round((articulos.dolar * articulos.lista3),2)as pl3,round((articulos.lista4 * articulos.dolar),2)as pl4,round((articulos.dolar * articulos.COSTO),2)as pcto from articulos where (select sum(cantidad) FROM movimientosarticulos where movimientosarticulos.idArticulo=articulos.ID group by idArticulo limit 0,1) > 0 order by sstock desc"; Transaccionable tra1 = new ConeccionLocal(); ResultSet rr1 = tra1.leerConjuntoDeRegistros(sql); //Facturar fact=new Articulos(); //ArrayList listadoClientes=fact.listadoBusqueda(""); System.out.println("cantidad registros " + rr1.getRow()); while (rr1.next()) { 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("cod. barras"); celda3 = fila.createCell(3); celda3.setCellStyle(titulo); celda3.setCellValue("Cantidad"); a++; } // cliente=new Articulos(); //cliente=(Articulos)listadoClientes.get(a); fila = hoja.createRow(a); celda = fila.createCell(0); ttx = ttx; celda.setCellStyle(celdas); celda.setCellType(HSSFCell.CELL_TYPE_STRING); celda.setCellValue(rr1.getString("ID")); celda1 = fila.createCell(1); ttx = ttx; celda1.setCellStyle(celdas); celda1.setCellType(HSSFCell.CELL_TYPE_STRING); celda1.setCellValue(rr1.getString("NOMBRE")); celda2 = fila.createCell(2); celda2.setCellStyle(celdas); celda2.setCellType(HSSFCell.CELL_TYPE_STRING); celda2.setCellValue(rr1.getString("BARRAS")); celda3 = fila.createCell(3); celda3.setCellStyle(celdas); celda3.setCellType(HSSFCell.CELL_TYPE_NUMERIC); celda3.setCellValue(rr1.getDouble("sstock")); celda4 = fila.createCell(4); celda4.setCellStyle(celdas); celda4.setCellType(HSSFCell.CELL_TYPE_STRING); celda4.setCellValue(""); celda5 = fila.createCell(5); celda5.setCellStyle(celdas); //celda5.setCellFormula(rs.getString("observaciones")); celda5.setCellType(HSSFCell.CELL_TYPE_STRING); celda5.setCellValue(""); //celda5.setCellValue(rs.getDate("fecha")); celda6 = fila.createCell(6); //celda5.setCellFormula(rs.getString("observaciones")); celda6.setCellStyle(celdas); celda6.setCellType(HSSFCell.CELL_TYPE_STRING); celda6.setCellValue(""); //listadoPorSucursal=edi.ListarPorSucursal(cliente); //Iterator il=listadoPorSucursal.listIterator(); a++; } rr1.close(); String ruta = "Informes\\planillaStock.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.PoiWriteExcelFile.java
public static int generarReporte() { //Calendar cal=Calendar.getInstance(); Calendar cal = WorkMonitorUI.instante; try {/*from w w w. ja v a2s . c o m*/ FileOutputStream fileOut = new FileOutputStream("HH_" + instante.getDisplayName(Calendar.MONTH, Calendar.SHORT_FORMAT, Locale.getDefault()) .toUpperCase() + "_" + persona.getNombre().toUpperCase().charAt(0) + "." + persona.getApellido().toUpperCase() + "_" + instante.get(Calendar.YEAR) + ".xls"); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet worksheet = workbook.createSheet( cal.getDisplayName(Calendar.MONTH, Calendar.SHORT_FORMAT, Locale.getDefault()).toUpperCase() + "-" + cal.get(Calendar.YEAR)); HSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.YELLOW.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont font = workbook.createFont(); font.setFontHeightInPoints((short) 12); font.setFontName("Calibri"); font.setItalic(false); font.setBold(true); font.setColor(HSSFColor.BLACK.index); cellStyle.setFont(font); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFCellStyle diasStyle = workbook.createCellStyle(); diasStyle.setFillForegroundColor(HSSFColor.SEA_GREEN.index); diasStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); font = workbook.createFont(); font.setFontHeightInPoints((short) 11); font.setFontName("Calibri"); font.setItalic(false); font.setBold(true); font.setColor(HSSFColor.WHITE.index); diasStyle.setFont(font); diasStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); diasStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); diasStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); diasStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); diasStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); diasStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFCellStyle schedStyle = workbook.createCellStyle(); schedStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); schedStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont font3 = workbook.createFont(); font3.setFontHeightInPoints((short) 11); font3.setFontName("Calibri"); font3.setItalic(false); font3.setColor(HSSFColor.BLACK.index); schedStyle.setFont(font3); schedStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); schedStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); schedStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); schedStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); schedStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); schedStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFCellStyle workdayStyle = workbook.createCellStyle(); //workdayStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); workdayStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); workdayStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); workdayStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); workdayStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); workdayStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); workdayStyle.setWrapText(true); HSSFFont font2 = workbook.createFont(); font2.setFontHeightInPoints((short) 8); font2.setFontName("Serif"); font2.setItalic(false); //font2.setColor(HSSFColor.YELLOW.index); workdayStyle.setFont(font2); workdayStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFCellStyle weekendStyle = workbook.createCellStyle(); weekendStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); weekendStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); weekendStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); weekendStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); weekendStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); weekendStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); weekendStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); weekendStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFCellStyle horarioStyle = workbook.createCellStyle(); horarioStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); horarioStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); horarioStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); horarioStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); horarioStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); horarioStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); horarioStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); horarioStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font4 = workbook.createFont(); font4.setFontHeightInPoints((short) 10); font4.setFontName("Serif"); font4.setItalic(false); font4.setBold(true); //font2.setColor(HSSFColor.YELLOW.index); horarioStyle.setFont(font4); // index from 0,0... cell A1 is cell(0,0) HSSFRow row1 = worksheet.createRow((short) 0); row1.setHeight((short) 500); //System.out.println("cal.get(Calendar.YEAR)="+cal.get(Calendar.YEAR)); HSSFCell cellA1 = row1.createCell((short) 0); cellA1.setCellValue( cal.getDisplayName(Calendar.MONTH, Calendar.SHORT_FORMAT, Locale.getDefault()).toUpperCase() + "-" + cal.get(Calendar.YEAR)); cellA1.setCellStyle(cellStyle); HSSFRow row2 = worksheet.createRow((short) 1); HSSFCell cellA4 = row2.createCell((short) 0); cellA4.setCellValue("Horario"); cellA4.setCellStyle(horarioStyle); //row2.setHeight((short)500); HSSFRow row3 = worksheet.createRow((short) 2); HSSFCell cellA3 = row3.createCell((short) 0); cellA3.setCellValue("Inicio - Trmino"); cellA3.setCellStyle(diasStyle); Calendar hora = Calendar.getInstance(); hora.set(Calendar.HOUR_OF_DAY, 9); hora.set(Calendar.MINUTE, 0); hora.set(Calendar.SECOND, 0); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); HSSFCell cellXn; for (int i = 0; i < 29; ++i) { HSSFRow row = worksheet.createRow((short) i + 3); row.setHeight((short) 500); cellXn = row.createCell((short) 0); String horaIni = sdf.format(hora.getTime()); hora.add(Calendar.MINUTE, 30); String horaFin = sdf.format(hora.getTime()); cellXn.setCellValue(horaIni + " - " + horaFin); cellXn.setCellStyle(schedStyle); } System.out.println("cal.get(Calendar.MONTH)1=" + cal.get(Calendar.MONTH)); cal.add(Calendar.DAY_OF_MONTH, -cal.get(Calendar.DAY_OF_MONTH) + 1); int diasMes = cal.getActualMaximum(Calendar.DAY_OF_MONTH); System.out.println("cal.get(Calendar.MONTH)2=" + cal.get(Calendar.MONTH)); sdf = new SimpleDateFormat("EEEE d"); System.out.println( "cal.getActualMaximum(Calendar.DAY_OF_MONTH)1=" + cal.getActualMaximum(Calendar.DAY_OF_MONTH)); for (int i = 0; i < diasMes; ++i) { cellXn = row2.createCell((short) i + 1); String dia = sdf.format(cal.getTime()); dia = Character.toUpperCase(dia.charAt(0)) + dia.substring(1); cellXn.setCellValue(dia); cellXn.setCellStyle(horarioStyle); //System.out.println("cal.get(Calendar.DAY_OF_MONTH)="+cal.get(Calendar.DAY_OF_MONTH)); cal.add(Calendar.DAY_OF_MONTH, 1); } for (int i = 0; i < diasMes; ++i) { cellXn = row3.createCell((short) i + 1); cellXn.setCellValue("Descripcin"); cellXn.setCellStyle(diasStyle); } System.out.println( "cal.getActualMaximum(Calendar.DAY_OF_MONTH)2=" + cal.getActualMaximum(Calendar.DAY_OF_MONTH)); // Retroceder mes para que quede como estaba cal.add(Calendar.MONTH, -1); //cal.add(Calendar.DAY_OF_MONTH, -1); System.out.println( "cal.getActualMaximum(Calendar.DAY_OF_MONTH)3=" + cal.getActualMaximum(Calendar.DAY_OF_MONTH)); HhDao hhDao = new HhDao(); Object[][] hh = new Object[29][cal.getActualMaximum(Calendar.DAY_OF_MONTH)]; hh = hhDao.getByMes(WorkMonitorUI.persona.getId(), cal.getTime()); cal.set(Calendar.DAY_OF_MONTH, 1); Sheet sheet = workbook.getSheetAt(0); sdf = new SimpleDateFormat("EEEE"); HSSFPatriarch _drawing = (HSSFPatriarch) sheet.createDrawingPatriarch(); CreationHelper factory = workbook.getCreationHelper(); for (int i = 0; i < 29; ++i) { Row r = sheet.getRow(i + 3); for (int j = 0; j < diasMes; ++j) { if (hh[i][j].toString() != "") { cellXn = (HSSFCell) r.createCell((short) j + 1); Hh _hh = (Hh) hh[i][j]; cellXn.setCellValue( _hh.getTarea().getNombre().trim() + ": " + _hh.getActividad().getNombre().trim()); HSSFAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 4, 2, (short) 6, 5); org.apache.poi.ss.usermodel.Comment comment = _drawing.createComment(anchor); String comentario = _hh.getTarea().getComentario().toLowerCase(); if (_hh.getComentario() != null) comentario = comentario + _hh.getComentario().toLowerCase(); RichTextString str = factory.createRichTextString(comentario); comment.setString(str); cellXn.setCellComment(comment); } else { cellXn = (HSSFCell) r.createCell((short) j + 1); cellXn.setCellValue(""); } //System.out.println("sdf.format(cal.getTime())="+sdf.format(cal.getTime())); if (Arrays.asList("sbado", "domingo").contains(sdf.format(cal.getTime()))) cellXn.setCellStyle(weekendStyle); else cellXn.setCellStyle(workdayStyle); sheet.setColumnWidth(j, 5000); cal.add(Calendar.DAY_OF_MONTH, 1); //sheet.autoSizeColumn(j); } // Retroceder mes para que quede como estaba cal.add(Calendar.MONTH, -1); System.out.println("cal.get(Calendar.MONTH)3=" + cal.get(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, 1); } sheet.setColumnWidth(diasMes, 5000); WorkMonitorUI.instante = Calendar.getInstance(); sheet.setColumnWidth(0, 5000); sheet.createFreezePane(1, 3); // Freeze just one row //sheet.createFreezePane( 0, 1, 0, 1 ); workbook.write(fileOut); fileOut.flush(); fileOut.close(); } catch (FileNotFoundException e) { e.printStackTrace(); return -1; } catch (IOException e) { e.printStackTrace(); return -2; } return 1; }
From source file:exportToExcel.ResultSetToExcel.java
License:Open Source License
private void dumpData(ResultSet resultSet, HSSFSheet sheet, int columnCount, HSSFCellStyle[] dataStyles) throws SQLException { int currentRow = 1; // The result set can have been already browsed resultSet.beforeFirst();/*from w w w . j av a 2s . c o m*/ while (resultSet.next()) { HSSFRow row = sheet.createRow(currentRow++); for (int colIndex = 0; colIndex < columnCount; colIndex++) { Object value = resultSet.getObject(colIndex + 1); final HSSFCell cell = row.createCell(colIndex); if (value == null) { cell.setCellValue(""); } else { cell.setCellStyle(dataStyles[colIndex]); if (value instanceof Calendar) { cell.setCellValue((Calendar) value); } else if (value instanceof Date) { cell.setCellValue((Date) value); } else if (value instanceof String) { cell.setCellValue((String) value); } else if (value instanceof Boolean) { cell.setCellValue((Boolean) value); } else if (value instanceof Double) { cell.setCellValue((Double) value); } else if (value instanceof BigDecimal) { cell.setCellValue(((BigDecimal) value).doubleValue()); } } } } for (int i = 0; i < columnCount; i++) { sheet.autoSizeColumn(i); } }