Example usage for org.apache.poi.hssf.usermodel HSSFRow createCell

List of usage examples for org.apache.poi.hssf.usermodel HSSFRow createCell

Introduction

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

Prototype

@Override
public HSSFCell createCell(int column) 

Source Link

Document

Use this to create new cells within the row and return it.

Usage

From source file:Congruential.ScuareMedios.java

public String calcNumbers(String semilla, String d, int f, Sheet hoja) {

    int num = 0, y0 = 0, longitudX0 = 0, corte = 0;
    String temp = "", sem = "", centro = "", printSemilla = semilla;

    try {//from  w  w  w  .  ja  v  a2 s  . c  o m
        num = Integer.parseInt(semilla);
        if (semilla.length() > 2) {
            y0 = (int) Math.pow(num, 2);
            longitudX0 = (String.valueOf(y0)).length();
            if (longitudX0 % 2 == 0 && Integer.parseInt(d) % 2 == 0) {
                semilla = "" + y0;
            } else {
                corte = longitudX0 - Integer.parseInt(d);
                semilla = (corte % 2 == 0) ? "" + y0 : "0" + y0;
            }

            sem = semilla;
            corte = (semilla.length() - Integer.parseInt(d)) / 2;
            semilla = semilla.substring(corte, semilla.length() - corte);
            centro = semilla;
            semilla = "0." + semilla;
            sql.Agregar(sem, String.valueOf(y0), centro, semilla);
            HSSFRow fila = (HSSFRow) hoja.createRow(f + 1);
            Cell celda = fila.createCell(0);
            celda.setCellValue(printSemilla);
            celda = fila.createCell(1);
            celda.setCellValue(sem);
            celda = fila.createCell(2);
            celda.setCellValue(centro);
            celda = fila.createCell(3);
            celda.setCellValue(semilla);
            System.out.println("aleatorio " + semilla + "  inicial: " + sem);
            System.out.println("Prueba " + txtconsole.getText());

        } else {
            System.out.println("La semilla debe ser mayor a 3 Digitos");
        }

    } catch (Exception e) {
        System.out.println("Solo se permite numeros, vuelva a intentarlo! " + e);
    }

    return centro;
}

From source file:Congruential.ScuareMedios.java

public void getAleatory(String semilla, String d, String cantidad) {
    ScuareMedios obj = new ScuareMedios();
    String sem = semilla;//from   w w  w  .  j  av a 2s . c  o  m

    try {
        if (archivoXLS.exists()) {
            archivoXLS.delete();
        }
        archivoXLS.createNewFile();
        Workbook libro = new HSSFWorkbook();

        FileOutputStream archivo = new FileOutputStream(archivoXLS);
        Sheet hoja = libro.createSheet("Mi hoja de trabajo 1");

        HSSFRow fila = (HSSFRow) hoja.createRow(0);
        Cell celda = fila.createCell(0);
        celda.setCellValue("X");
        celda = fila.createCell(1);
        celda.setCellValue("Y");
        celda = fila.createCell(2);
        celda.setCellValue("Xnext");
        celda = fila.createCell(3);
        celda.setCellValue("r");

        for (int i = 0; i < Integer.parseInt(cantidad); i++) {
            sem = obj.calcNumbers(String.valueOf(sem), d, i, hoja);
        }
        libro.write(archivo);
        archivo.close();

    } catch (Exception e) {
    }

}

From source file:control.listaEquipos.java

private boolean generaExcel(String path) {
    // Se crea el libro
    HSSFWorkbook libro = new HSSFWorkbook();

    // Se crea una hoja dentro del libro
    HSSFSheet hoja = libro.createSheet("Equipos");

    // Se crea una fila dentro de la hoja
    HSSFRow fila = hoja.createRow(0);

    // Se crea una celda dentro de la fila
    HSSFCell celda = fila.createCell((short) 0);
    HSSFRichTextString texto = new HSSFRichTextString("Id ");
    celda.setCellValue(texto);/*www  . j ava 2s  .  c o  m*/
    celda = fila.createCell((short) 1);
    texto = new HSSFRichTextString("Nombre");
    celda.setCellValue(texto);
    celda = fila.createCell((short) 2);
    texto = new HSSFRichTextString("Categoria");
    celda.setCellValue(texto);
    celda = fila.createCell((short) 3);
    texto = new HSSFRichTextString("Accesorios");
    celda.setCellValue(texto);
    celda = fila.createCell((short) 4);
    texto = new HSSFRichTextString("Descripcion");
    celda.setCellValue(texto);
    celda = fila.createCell((short) 5);
    texto = new HSSFRichTextString("Marca");
    celda.setCellValue(texto);
    celda = fila.createCell((short) 6);
    texto = new HSSFRichTextString("Estado");
    celda.setCellValue(texto);

    int nr = 1;
    Object[][] tabla = this.getTableData(tabEquipo);
    for (Object[] o : tabla) {
        fila = hoja.createRow(nr);
        int i = 0;
        for (Object e : o) {
            celda = fila.createCell((short) i);
            if (i <= 6) {
                if (e != null) {
                    texto = new HSSFRichTextString((String) e.toString());
                } else {
                    texto = new HSSFRichTextString("");

                }
                celda.setCellValue(texto);
            }
            i++;
        }
        nr++;
    }

    // Se salva el libro.
    try {
        FileOutputStream elFichero = new FileOutputStream(path);
        libro.write(elFichero);
        elFichero.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}

From source file:Controlador.ControladorCargueMasivo.java

public static HSSFWorkbook obtenerExcel(DataModel contenidoCeldas, DataModel cabecerasCeldas,
        String nombreHoja) {// w w  w . j ava  2 s .  com

    HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
    HSSFSheet hssfSheet = hssfWorkbook.createSheet(nombreHoja);
    int numeroFila = 0;
    int numeroColumna = 0;
    HSSFRow hssfRow = hssfSheet.createRow(numeroFila++);
    HSSFCellStyle hssfCellStyleCabecera = hssfWorkbook.createCellStyle();
    hssfCellStyleCabecera.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    hssfCellStyleCabecera.setFillBackgroundColor(new HSSFColor.BLACK().getIndex());
    HSSFFont hssfFont = hssfWorkbook.createFont();
    hssfFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    hssfFont.setColor(HSSFColor.WHITE.index);
    hssfCellStyleCabecera.setFont(hssfFont);
    String columnaCabecera;
    HSSFCell hssfCell = null;
    List cabecerasExcel = (List) cabecerasCeldas.getWrappedData();
    for (int i = 0; i < cabecerasExcel.size(); i++) {
        columnaCabecera = (String) cabecerasExcel.get(i);
        hssfCell = hssfRow.createCell((short) numeroColumna++);
        hssfCell.setCellValue(columnaCabecera);
        hssfCell.setCellStyle(hssfCellStyleCabecera);
    }
    List contenidoExcel = (List) contenidoCeldas.getWrappedData();
    List fila = null;
    Object valor;
    for (int i = 0; i < contenidoExcel.size(); i++) {
        fila = (List) contenidoExcel.get(i);
        hssfRow = hssfSheet.createRow(numeroFila++);
        numeroColumna = 0;
        for (int x = 0; x < fila.size(); x++) {
            valor = fila.get(x);
            hssfCell = hssfRow.createCell((short) numeroColumna++);
            hssfCell.setCellValue((String) valor);
        }
    }
    return hssfWorkbook;
}

From source file:Controlador.jControlador.java

public boolean imprimirExcel(File archivo, JTable table) {
        try {//ww  w. jav  a  2s . c  o m
            HSSFWorkbook libro = new HSSFWorkbook();
            HSSFSheet hoja = libro.createSheet();
            for (int i = 0; i <= table.getRowCount(); i++) {
                HSSFRow fila = hoja.createRow(i);
                if (i == 0) {
                    for (int j = 0; j < table.getColumnCount(); j++) {
                        HSSFCell celda = fila.createCell(j);
                        celda.setCellValue(new HSSFRichTextString(
                                table.getColumnModel().getColumn(j).getHeaderValue().toString()));
                    }
                }
                if (i != 0) {
                    for (int j = 0; j < table.getColumnCount(); j++) {
                        HSSFCell celda = fila.createCell(j);
                        if (table.getValueAt(i - 1, j) != null)
                            celda.setCellValue(new HSSFRichTextString(table.getValueAt(i - 1, j).toString()));
                    }
                }
            }
            FileOutputStream elFichero = new FileOutputStream(archivo.getAbsolutePath() + ".xls");
            libro.write(elFichero);
            elFichero.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

From source file:controladores.controladorPrincipal.java

public boolean generarReporte() {
    try {//from  w ww  . j  a v  a 2  s  . c o m
        modeloCobranzas cobranza = new modeloCobranzas();
        Object[][] facturas = cobranza.listarFacturadasGestion();
        String file = "Reporte_cobranza_" + formatDate.format(new Date()) + ".xls";
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("FirstSheet");
        HSSFRow rowhead = sheet.createRow((short) 0);
        rowhead.createCell(0).setCellValue("Folio");
        rowhead.createCell(1).setCellValue("Rut");
        rowhead.createCell(2).setCellValue("Razn social");
        rowhead.createCell(3).setCellValue("Fecha emisin");
        rowhead.createCell(4).setCellValue("Das emisin");
        rowhead.createCell(5).setCellValue("Neto");
        rowhead.createCell(6).setCellValue("Iva");
        rowhead.createCell(7).setCellValue("Total");
        rowhead.createCell(8).setCellValue("Forma de pago");
        rowhead.createCell(9).setCellValue("Medio de pago");
        rowhead.createCell(10).setCellValue("Abono");
        rowhead.createCell(11).setCellValue("Monto abono");
        rowhead.createCell(12).setCellValue("Saldo");
        rowhead.createCell(13).setCellValue("Contacto");
        rowhead.createCell(14).setCellValue("Telfono");
        rowhead.createCell(15).setCellValue("N de gestiones");
        rowhead.createCell(16).setCellValue("Tipo gestin");
        rowhead.createCell(17).setCellValue("Resultado");
        rowhead.createCell(18).setCellValue("Fecha gestin");
        rowhead.createCell(19).setCellValue("Observaciones");
        int i = 1;
        for (Object[] fac : facturas) {
            rowhead = sheet.createRow(i);
            i++;
            rowhead.createCell(0).setCellValue(fac[0].toString());
            rowhead.createCell(1).setCellValue(fac[1].toString());
            rowhead.createCell(2).setCellValue(fac[2].toString());
            rowhead.createCell(3).setCellValue(fac[3].toString());
            rowhead.createCell(4).setCellValue(fac[4].toString());
            rowhead.createCell(5).setCellValue(fac[5].toString());
            rowhead.createCell(6).setCellValue(fac[6].toString());
            rowhead.createCell(7).setCellValue(fac[7].toString());
            rowhead.createCell(8).setCellValue(fac[8].toString());
            rowhead.createCell(9).setCellValue(fac[9].toString());
            rowhead.createCell(10).setCellValue(fac[10].toString());
            rowhead.createCell(11).setCellValue(fac[11].toString());
            rowhead.createCell(12).setCellValue(fac[12].toString());
            rowhead.createCell(13).setCellValue(fac[13].toString());
            rowhead.createCell(14).setCellValue(fac[14].toString());
            rowhead.createCell(15).setCellValue(fac[15].toString());
            rowhead.createCell(16).setCellValue(fac[16].toString());
            rowhead.createCell(17).setCellValue(fac[17].toString());
            rowhead.createCell(18).setCellValue(fac[18].toString());
            rowhead.createCell(19).setCellValue(fac[19].toString());
            FileOutputStream fileOut;
            fileOut = new FileOutputStream(file);
            workbook.write(fileOut);
            fileOut.close();
        }
    } catch (IOException ex) {
        Logger.getLogger(controladorPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR", JOptionPane.INFORMATION_MESSAGE);
        System.out.println(ex.getMessage());
        return false;
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.getMessage(), "ERROR", JOptionPane.INFORMATION_MESSAGE);
        e.printStackTrace();
        return false;
    }
    JOptionPane.showMessageDialog(null, "Reporte generado con xito", "Operacin exitosa",
            JOptionPane.INFORMATION_MESSAGE);
    return true;
}

From source file:controladores.controladorPrincipal.java

public boolean generarReporteTrabajador() {
    DateFormat perDate = new SimpleDateFormat("MMMM-yyyy");
    DateFormat numDate = new SimpleDateFormat("yyyy-MM");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MONTH, 1);//from  w  w w.  ja  v  a2 s .  c  om
    cal.set(Calendar.DATE, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
    String mes = "" + (cal.get(Calendar.MONTH) - 1);
    String per = perDate.format(new Date());
    String fec = numDate.format(new Date());
    String fecIn = "2017-" + mes + "-26";
    String fecFin = fec + "-25";
    //        System.out.println(fecIn + " " + fecFin);
    NumberFormat FORMAT = NumberFormat.getCurrencyInstance();
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    try {
        String path = "Reporte trabajadores-" + per;
        File dir = new File(path);
        dir.mkdir();
        modeloEmpleados empleado = new modeloEmpleados();
        Object[] ruts = empleado.listarRutEmpleados();
        int numEmp = ruts.length;
        for (int i = 0; i < numEmp; i++) {
            String file = path + "/Reporte_trabajador_" + ruts[i] + "_" + formatDate.format(new Date())
                    + ".xls";
            Object[][] ots = empleado.obtenerReporteEmpleados(ruts[i].toString(), fecIn, fecFin);
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet("FirstSheet");
            HSSFRow rowhead = sheet.createRow((short) 0);
            rowhead.createCell(0).setCellValue("GRUAS HORQUILLA SANTA TERESITA F.M.LTDA");
            rowhead = sheet.createRow(1);
            rowhead.createCell(3).setCellValue("1 Fecha de informe: " + formatDate.format(new Date()));
            rowhead = sheet.createRow(2);
            rowhead.createCell(3).setCellValue("Servicios de operador " + formatDate2.format(new Date()));
            rowhead = sheet.createRow(4);
            rowhead.createCell(0).setCellValue("O.T.");
            rowhead.createCell(1).setCellValue("FECHA.");
            rowhead.createCell(2).setCellValue("CLIENTE");
            //                rowhead.createCell(3).setCellValue("O.T.");
            //                rowhead.createCell(4).setCellValue("O.T.");
            rowhead.createCell(5).setCellValue("SALE");
            rowhead.createCell(6).setCellValue("TERMINA");
            rowhead.createCell(7).setCellValue("OFICINA");
            rowhead.createCell(8).setCellValue("HORAS EXTRA");
            rowhead.createCell(8).setCellValue("HORAS ARRIENDO");
            rowhead = sheet.createRow(5);
            rowhead.createCell(0).setCellValue("*** " + ruts[i].toString());
            int j = 0;
            for (Object[] ot : ots) {
                rowhead = sheet.createRow(j + 6);
                rowhead.createCell(0).setCellValue(ot[2].toString());
                rowhead.createCell(1).setCellValue(ot[3].toString());
                rowhead.createCell(2).setCellValue(ot[4].toString());
                //                    rowhead.createCell(3).setCellValue(ot[3].toString());
                //                    rowhead.createCell(4).setCellValue(ot[4].toString());
                rowhead.createCell(5).setCellValue(ot[5].toString());
                rowhead.createCell(6).setCellValue(ot[6].toString());
                rowhead.createCell(7).setCellValue(ot[7].toString());
                rowhead.createCell(8).setCellValue("0");
                rowhead.createCell(8).setCellValue(ot[9].toString());
                j++;
            }
            FileOutputStream fileOut;
            fileOut = new FileOutputStream(file);
            workbook.write(fileOut);
            fileOut.close();
        }
    } catch (IOException ex) {
        ex.printStackTrace();
        Logger.getLogger(controladorPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR", JOptionPane.INFORMATION_MESSAGE);
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, e.getMessage(), "ERROR", JOptionPane.INFORMATION_MESSAGE);
        return false;
    }
    JOptionPane.showMessageDialog(null, "Reporte generado con xito", "Operacin exitosa",
            JOptionPane.INFORMATION_MESSAGE);
    return true;
}

From source file:controladores.controladorPrincipal.java

public boolean generarReporteTrabajador(String year, String month) {
    DateFormat perDate = new SimpleDateFormat("MMMM-yyyy");
    DateFormat numDate = new SimpleDateFormat("yyyy-MM");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MONTH, 1);/*from  ww  w  .java2  s  .c  om*/
    cal.set(Calendar.DATE, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
    String mes = "" + (Integer.parseInt(month) - 1);
    //        String per = perDate.format(new Date());
    String per = month + "-" + year;
    String fec = numDate.format(new Date());
    String fecIn = "2017-" + mes + "-26";
    String fecFin = year + "-" + month + "-25";
    //        System.out.println(fecIn + " " + fecFin);
    NumberFormat FORMAT = NumberFormat.getCurrencyInstance();
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    try {
        String path = "Reporte trabajadores-" + per;
        File dir = new File(path);
        dir.mkdir();
        modeloEmpleados empleado = new modeloEmpleados();
        Object[] ruts = empleado.listarRutEmpleados();
        int numEmp = ruts.length;
        for (int i = 0; i < numEmp; i++) {
            String file = path + "/Reporte_trabajador_" + ruts[i] + "_" + formatDate.format(new Date())
                    + ".xls";
            Object[][] ots = empleado.obtenerReporteEmpleados(ruts[i].toString(), fecIn, fecFin);
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet("FirstSheet");
            HSSFRow rowhead = sheet.createRow((short) 0);
            rowhead.createCell(0).setCellValue("GRUAS HORQUILLA SANTA TERESITA F.M.LTDA");
            rowhead = sheet.createRow(1);
            rowhead.createCell(3).setCellValue("1 Fecha de informe: " + formatDate.format(new Date()));
            rowhead = sheet.createRow(2);
            rowhead.createCell(3).setCellValue("Servicios de operador " + formatDate2.format(new Date()));
            rowhead = sheet.createRow(4);
            rowhead.createCell(0).setCellValue("O.T.");
            rowhead.createCell(1).setCellValue("FECHA.");
            rowhead.createCell(2).setCellValue("CLIENTE");
            //                rowhead.createCell(3).setCellValue("O.T.");
            //                rowhead.createCell(4).setCellValue("O.T.");
            rowhead.createCell(5).setCellValue("SALE");
            rowhead.createCell(6).setCellValue("TERMINA");
            rowhead.createCell(7).setCellValue("OFICINA");
            rowhead.createCell(8).setCellValue("HORAS EXTRA");
            rowhead.createCell(8).setCellValue("HORAS ARRIENDO");
            rowhead = sheet.createRow(5);
            rowhead.createCell(0).setCellValue("*** " + ruts[i].toString());
            int j = 0;
            for (Object[] ot : ots) {
                rowhead = sheet.createRow(j + 6);
                rowhead.createCell(0).setCellValue(ot[2].toString());
                rowhead.createCell(1).setCellValue(ot[3].toString());
                rowhead.createCell(2).setCellValue(ot[4].toString());
                //                    rowhead.createCell(3).setCellValue(ot[3].toString());
                //                    rowhead.createCell(4).setCellValue(ot[4].toString());
                rowhead.createCell(5).setCellValue(ot[5].toString());
                rowhead.createCell(6).setCellValue(ot[6].toString());
                rowhead.createCell(7).setCellValue(ot[7].toString());
                rowhead.createCell(8).setCellValue("0");
                rowhead.createCell(8).setCellValue(ot[9].toString());
                j++;
            }
            FileOutputStream fileOut;
            fileOut = new FileOutputStream(file);
            workbook.write(fileOut);
            fileOut.close();
        }
    } catch (IOException ex) {
        ex.printStackTrace();
        Logger.getLogger(controladorPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR", JOptionPane.INFORMATION_MESSAGE);
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, e.getMessage(), "ERROR", JOptionPane.INFORMATION_MESSAGE);
        return false;
    }
    JOptionPane.showMessageDialog(null, "Reporte generado con xito", "Operacin exitosa",
            JOptionPane.INFORMATION_MESSAGE);
    return true;
}

From source file:controladores4.controladorReportes.java

public void generarReporteClientes() {
    Thread runnable = new Thread() {
        public void run() {
            modeloFacturas rutas = new modeloFacturas();
            String per = perDate.format(new Date());
            String fec = numDate.format(new Date());
            NumberFormat FORMAT = NumberFormat.getCurrencyInstance();
            DecimalFormatSymbols dfs = new DecimalFormatSymbols();
            try {
                String path = "Reportes clientes";
                File dir = new File(path);
                dir.mkdir();//from ww w  .ja v  a 2  s .c om
                modeloClientes clientes = new modeloClientes();
                Object[][] data = clientes.listarReporteClientes();
                int numClientes = data.length;
                String file = path + "/Reporte clientes - " + per + ".xls";
                HSSFWorkbook workbook = new HSSFWorkbook();
                HSSFSheet sheet = workbook.createSheet("FirstSheet");
                HSSFRow rowhead = sheet.createRow((short) 0);
                rowhead.createCell(0).setCellValue("GRUAS HORQUILLA SANTA TERESITA F.M.LTDA");
                rowhead = sheet.createRow(1);
                rowhead.createCell(3).setCellValue("1 Fecha de informe: " + formatDate.format(new Date()));
                rowhead = sheet.createRow(2);
                rowhead = sheet.createRow(4);
                rowhead.createCell(0).setCellValue("RUT");
                rowhead.createCell(1).setCellValue("RAZN SOCIAL");
                rowhead.createCell(2).setCellValue("GIRO");
                rowhead.createCell(3).setCellValue("TELFONO");
                rowhead.createCell(4).setCellValue("CELULAR");
                rowhead.createCell(5).setCellValue("CORREO");
                rowhead.createCell(6).setCellValue("DIRECCIN");
                rowhead.createCell(7).setCellValue("REGIN");
                rowhead.createCell(8).setCellValue("CIUDAD");
                rowhead.createCell(9).setCellValue("COMUNA");
                rowhead.createCell(10).setCellValue("OBSERVACIONES");
                rowhead.createCell(11).setCellValue("CONTACTO");
                rowhead = sheet.createRow(5);
                int j = 0;
                for (Object[] cliente : data) {
                    rowhead = sheet.createRow(j + 6);
                    rowhead.createCell(0).setCellValue(cliente[0].toString());
                    rowhead.createCell(1).setCellValue(cliente[1].toString());
                    rowhead.createCell(2).setCellValue(cliente[2].toString());
                    rowhead.createCell(3).setCellValue(cliente[3].toString());
                    rowhead.createCell(4).setCellValue(cliente[4].toString());
                    rowhead.createCell(5).setCellValue(cliente[5].toString());
                    rowhead.createCell(6).setCellValue(cliente[6].toString());
                    rowhead.createCell(7).setCellValue(cliente[7].toString());
                    rowhead.createCell(8).setCellValue(cliente[8].toString());
                    rowhead.createCell(9).setCellValue(cliente[9].toString());
                    rowhead.createCell(10).setCellValue(cliente[10].toString());
                    rowhead.createCell(11).setCellValue(cliente[11].toString());
                    j++;
                }
                FileOutputStream fileOut;
                fileOut = new FileOutputStream(file);
                workbook.write(fileOut);
                fileOut.close();
            } catch (IOException ex) {
                ex.printStackTrace();
                Logger.getLogger(controladorPrincipal.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR", JOptionPane.INFORMATION_MESSAGE);
            } catch (Exception e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(null, e.getMessage(), "ERROR", JOptionPane.INFORMATION_MESSAGE);
            }
            JOptionPane.showMessageDialog(null, "Reporte clientes generado con xito", "Operacin exitosa",
                    JOptionPane.INFORMATION_MESSAGE);

        }
    };
    runnable.start();

}

From source file:controladores4.controladorReportes.java

public void generarReporteGruas() {
    Thread runnable = new Thread() {
        public void run() {
            modeloFacturas rutas = new modeloFacturas();
            String per = perDate.format(new Date());
            String fec = numDate.format(new Date());
            NumberFormat FORMAT = NumberFormat.getCurrencyInstance();
            DecimalFormatSymbols dfs = new DecimalFormatSymbols();
            try {
                String path = "Reportes gruas";
                File dir = new File(path);
                dir.mkdir();/*  w w w  .j  av  a  2s .  co m*/
                modeloGruas gruas = new modeloGruas();
                Object[][] data = gruas.listarReporteGruas();
                int numGruas = data.length;
                String file = path + "/Reporte gruas - " + per + ".xls";
                HSSFWorkbook workbook = new HSSFWorkbook();
                HSSFSheet sheet = workbook.createSheet("FirstSheet");
                HSSFRow rowhead = sheet.createRow((short) 0);
                rowhead.createCell(0).setCellValue("GRUAS HORQUILLA SANTA TERESITA F.M.LTDA");
                rowhead = sheet.createRow(1);
                rowhead.createCell(3).setCellValue("1 Fecha de informe: " + formatDate.format(new Date()));
                rowhead = sheet.createRow(4);
                rowhead.createCell(0).setCellValue("PATENTE");
                rowhead.createCell(1).setCellValue("AO");
                rowhead.createCell(2).setCellValue("DESCRIPCIN");
                rowhead.createCell(3).setCellValue("MARCA");
                rowhead.createCell(4).setCellValue("MODELO");
                rowhead.createCell(5).setCellValue("TONELAJE");
                rowhead.createCell(6).setCellValue("PESO");
                rowhead.createCell(7).setCellValue("TIPO NEUM?TICOS");
                rowhead.createCell(8).setCellValue("TIPO NEUM?TICOS 2");
                rowhead.createCell(9).setCellValue("NMERO DE CHASIS");
                rowhead.createCell(10).setCellValue("TIPO DE COMBUSTIBLE");
                rowhead.createCell(11).setCellValue("M?STIL");
                rowhead.createCell(12).setCellValue("ALTURA M?STIL");
                rowhead.createCell(13).setCellValue("ANCHO");
                rowhead.createCell(14).setCellValue("LARGO");
                rowhead.createCell(15).setCellValue("LARGO UAS");
                rowhead.createCell(16).setCellValue("ALTURA LEVANTE");
                rowhead.createCell(17).setCellValue("MEDIDA NEUM?TICOS DELANTEROS");
                rowhead.createCell(18).setCellValue("MEDIDA NEUM?TICOS TRASEROS");
                rowhead.createCell(19).setCellValue("NMERO DE MOTOR");
                rowhead.createCell(20).setCellValue("NMERO DE SERIE");
                rowhead.createCell(21).setCellValue("FECHA REVISIN TCNICA");
                rowhead.createCell(22).setCellValue("FECHA LTIMA MANTENCIN");
                rowhead.createCell(23).setCellValue("KM/H LTIMA MANTENCIN");
                rowhead.createCell(24).setCellValue("FECHA DE BAJA");
                rowhead.createCell(25).setCellValue("OBSERVACIONES");
                rowhead.createCell(26).setCellValue("FECHA DE INGRESO");
                rowhead.createCell(27).setCellValue("HORMETRO");
                rowhead = sheet.createRow(5);
                int j = 0;
                for (Object[] grua : data) {
                    rowhead = sheet.createRow(j + 6);
                    rowhead.createCell(0).setCellValue(grua[0].toString());
                    rowhead.createCell(1).setCellValue(grua[1].toString());
                    rowhead.createCell(2).setCellValue(grua[2].toString());
                    rowhead.createCell(3).setCellValue(grua[3].toString());
                    rowhead.createCell(4).setCellValue(grua[4].toString());
                    rowhead.createCell(5).setCellValue(grua[5].toString());
                    rowhead.createCell(6).setCellValue(grua[6].toString());
                    rowhead.createCell(7).setCellValue(grua[7].toString());
                    rowhead.createCell(8).setCellValue(grua[8].toString());
                    rowhead.createCell(9).setCellValue(grua[9].toString());
                    rowhead.createCell(10).setCellValue(grua[10].toString());
                    rowhead.createCell(11).setCellValue(grua[11].toString());
                    rowhead.createCell(12).setCellValue(grua[12].toString());
                    rowhead.createCell(13).setCellValue(grua[13].toString());
                    rowhead.createCell(14).setCellValue(grua[14].toString());
                    rowhead.createCell(15).setCellValue(grua[15].toString());
                    rowhead.createCell(16).setCellValue(grua[16].toString());
                    rowhead.createCell(17).setCellValue(grua[17].toString());
                    rowhead.createCell(18).setCellValue(grua[18].toString());
                    rowhead.createCell(19).setCellValue(grua[19].toString());
                    rowhead.createCell(20).setCellValue(grua[20].toString());
                    rowhead.createCell(21).setCellValue(grua[21].toString());
                    rowhead.createCell(22).setCellValue(grua[22].toString());
                    rowhead.createCell(23).setCellValue(grua[23].toString());
                    rowhead.createCell(24).setCellValue(grua[24].toString());
                    rowhead.createCell(25).setCellValue(grua[25].toString());
                    rowhead.createCell(26).setCellValue(grua[26].toString());
                    rowhead.createCell(27).setCellValue(grua[27].toString());
                    j++;
                }
                FileOutputStream fileOut;
                fileOut = new FileOutputStream(file);
                workbook.write(fileOut);
                fileOut.close();
            } catch (IOException ex) {
                ex.printStackTrace();
                Logger.getLogger(controladorPrincipal.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR", JOptionPane.INFORMATION_MESSAGE);
            } catch (Exception e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(null, e.getMessage(), "ERROR", JOptionPane.INFORMATION_MESSAGE);
            }
            JOptionPane.showMessageDialog(null, "Reporte gras generado con xito", "Operacin exitosa",
                    JOptionPane.INFORMATION_MESSAGE);

        }
    };
    runnable.start();
}