Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Excel; import interfaceGraficas.Inicio; import interfaces.Transaccionable; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; import javax.mail.MessagingException; import javax.swing.JOptionPane; import objetos.ConeccionLocal; import objetos.Conecciones; import objetos.Mail; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.IndexedColors; /** * * @author mauro */ public class IvaVentas { public void GenerrarInformeIvaVentas(String desde, String hasta) throws SQLException { HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja = libro.createSheet("Iva Ventas"); /* * 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); } } }