Example usage for org.apache.poi.hssf.usermodel HSSFWorkbook write

List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook write

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFWorkbook write.

Prototype

private void write(POIFSFileSystem fs) throws IOException 

Source Link

Document

Writes the workbook out to a brand new, empty POIFS

Usage

From source file:excel.FileExcel.java

public File excel_mutation_report(ArrayList<MutationReportData> datamutation, KodeNamaKonter konterinfo,
        Date Start, Date End, Date CurrentDate) {
    if (datamutation.size() != 0) {
        DateFormat time = new SimpleDateFormat("hhmm");
        String fileName = "Mutation_" + konterinfo.nama_konter + "_" + fmt.format(CurrentDate) + "_"
                + time.format(CurrentDate) + ".xls";
        File ExcelMutation = new File(fileName);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();

        // set page
        sheet.getPrintSetup().setLandscape(false);

        //Set Header Information 
        Header headerPage = sheet.getHeader();
        headerPage.setCenter(HeaderFooter.page());
        headerPage.setRight(fileName);//from   w ww.jav  a  2 s  .  co  m

        //Set Footer Information with Page Numbers
        Footer footerPage = sheet.getFooter();
        footerPage.setCenter("Page " + HeaderFooter.page() + " of " + HeaderFooter.numPages());

        // prepare variable to edit the xls
        HSSFRow header;
        HSSFCell cell;
        HSSFCellStyle titlestyle = workbook.createCellStyle();
        HSSFCellStyle headerstyle = workbook.createCellStyle();
        HSSFCellStyle datastyle = workbook.createCellStyle();
        HSSFFont boldfont = workbook.createFont();
        HSSFFont normalfont = workbook.createFont();

        // create the title 
        header = sheet.createRow(1);
        cell = header.createCell(1);
        boldfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        titlestyle.setFont(boldfont);
        titlestyle.setAlignment(CellStyle.ALIGN_CENTER);
        titlestyle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderBottom(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        titlestyle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        cell.setCellStyle(titlestyle);
        cell.setCellValue("TABEL MUTATION REPORT");
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 3));

        // create file info
        // create file info
        header = sheet.createRow(3);
        cell = header.createCell(2);
        cell.setCellValue("Konter : ");
        cell = header.createCell(3);
        cell.setCellValue(konterinfo.nama_konter);

        header = sheet.createRow(4);
        cell = header.createCell(2);
        cell.setCellValue("Tanggal : ");
        cell = header.createCell(3);
        cell.setCellValue(fmt.format(Start));
        cell = header.createCell(4);
        cell.setCellValue("-");
        cell = header.createCell(5);
        cell.setCellValue(fmt.format(End));

        // create the header
        headerstyle.setFont(boldfont);
        headerstyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        headerstyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        header = sheet.createRow(7);
        cell = header.createCell(1);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Tanggal");
        cell = header.createCell(2);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Barang Masuk");
        cell = header.createCell(3);
        cell.setCellStyle(headerstyle);
        cell.setCellValue("Setoran Masuk");
        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(2);
        sheet.autoSizeColumn(3);

        normalfont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
        datastyle.setFont(normalfont);
        datastyle.setAlignment(CellStyle.ALIGN_RIGHT);
        datastyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        datastyle.setBorderRight(HSSFCellStyle.BORDER_THIN);

        int i;
        // fill the data
        for (i = 0; i < datamutation.size(); i++) {
            header = sheet.createRow(8 + i);
            cell = header.createCell(1);
            cell.setCellStyle(datastyle);
            cell.setCellValue(fmt.format(datamutation.get(i).tanggal_mutasi));
            cell = header.createCell(2);
            cell.setCellStyle(datastyle);
            cell.setCellValue(datamutation.get(i).barang_keluar);
            cell = header.createCell(3);
            cell.setCellStyle(datastyle);
            cell.setCellValue(datamutation.get(i).setoran);
        }

        datastyle.setFont(boldfont);
        header = sheet.createRow(i + 10);
        cell = header.createCell(1);
        cell.setCellStyle(datastyle);
        cell.setCellValue("Hutang Konter");
        cell = header.createCell(2);
        cell.setCellStyle(datastyle);
        cell.setCellValue(fmt.format(CurrentDate));
        cell = header.createCell(3);
        cell.setCellStyle(datastyle);
        cell.setCellValue(konterinfo.hutang_konter);
        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(2);
        sheet.autoSizeColumn(3);

        try {
            FileOutputStream out = new FileOutputStream(ExcelMutation);
            workbook.write(out);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            ExcelMutation = null;
        } catch (IOException e) {
            e.printStackTrace();
            ExcelMutation = null;
        }
        return ExcelMutation;
    } else {
        return null;
    }
}

From source file:excel.FileExcel.java

public File create_excel_test() {
    File Testing = new File("ujicoba.xls");
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet();

    // Create header form
    // tanggal// w  ww .j  ava 2  s.  c o  m

    HSSFRow header = sheet.createRow(2);
    HSSFCell cell = header.createCell(3);
    cell.setCellValue("Tanggal Jadi Kerjaan : ");
    sheet.autoSizeColumn(3);
    cell = header.createCell(4);
    cell.setCellValue(" 10 Februari 2016 ");
    sheet.autoSizeColumn(4);

    try {
        FileOutputStream out = new FileOutputStream(Testing);
        workbook.write(out);
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        Testing = null;
    } catch (IOException e) {
        e.printStackTrace();
        Testing = null;
    }
    return Testing;
}

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  .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;
    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   ww w.j a va2s  .  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");

    /*/* w  w  w . j  av a  2s  .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 = "";
    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  ww  . 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;
    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   www.j  a v 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  ww  .  ja  va  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 = "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");
    /*/*from  w w  w .  j av  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
     * 
     */

    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 ww  w . ja va2 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
     * 
     */

    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);
    }

}