Example usage for org.apache.poi.xssf.usermodel XSSFWorkbook write

List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook write

Introduction

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

Prototype

@SuppressWarnings("resource")
public final void write(OutputStream stream) throws IOException 

Source Link

Document

Write out this document to an Outputstream.

Usage

From source file:VentanaJava.ConsultarCosechaCortoExportar.java

private void ExportarPlanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExportarPlanActionPerformed
    DefaultTableModel model = (DefaultTableModel) TablaPlanesCosechaCorto.getModel();
    int filas = TablaPlanesCosechaCorto.getRowCount();
    JFileChooser GuardarArchivo = new JFileChooser();
    int opcion = GuardarArchivo.showSaveDialog(this);
    if (opcion == JFileChooser.APPROVE_OPTION) {
        String direccion = GuardarArchivo.getSelectedFile().toString();
        XSSFWorkbook libro = new XSSFWorkbook();
        XSSFSheet hoja = libro.createSheet();
        XSSFRow fila = hoja.createRow(0);
        fila.createCell(0).setCellValue("Secuencia");
        fila.createCell(1).setCellValue("Fecha de Cosecha");
        fila.createCell(2).setCellValue("Granja");
        fila.createCell(3).setCellValue("Galera");
        fila.createCell(4).setCellValue("Cantidad a Cosechar");
        fila.createCell(5).setCellValue("Peso Promedio");

        XSSFRow hileras;//from w  w w . j av a  2 s. c  o m
        for (int i = 0; i < filas; i++) {
            hileras = hoja.createRow((i + 1));
            for (int e = 0; e < 6; e++) {
                hileras.createCell(e).setCellValue(model.getValueAt(i, e).toString());
            }
        }
        try {
            libro.write(new FileOutputStream(new File(direccion + ".xlsx")));
            Desktop.getDesktop().open(new File(direccion + ".xlsx"));
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    this.dispose();
}

From source file:VentanaJava.ConsultarCosechaMedianoExportar.java

private void ExportarPlanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExportarPlanActionPerformed
    DefaultTableModel model = (DefaultTableModel) TablaCosechaMedianoConsulta.getModel();
    int filas = TablaCosechaMedianoConsulta.getRowCount();
    JFileChooser GuardarArchivo = new JFileChooser();
    int opcion = GuardarArchivo.showSaveDialog(this);
    if (opcion == JFileChooser.APPROVE_OPTION) {
        String direccion = GuardarArchivo.getSelectedFile().toString();
        XSSFWorkbook libro = new XSSFWorkbook();
        XSSFSheet hoja = libro.createSheet();
        XSSFRow fila = hoja.createRow(0);
        fila.createCell(0).setCellValue("Secuencia");
        fila.createCell(1).setCellValue("Fecha de Cosecha");
        fila.createCell(2).setCellValue("Granja");
        fila.createCell(3).setCellValue("Galera");
        fila.createCell(4).setCellValue("Cantidad a Cosechar");
        fila.createCell(5).setCellValue("Peso Promedio");

        XSSFRow hileras;//from w w  w.j  a v  a  2 s.  co  m
        for (int i = 0; i < filas; i++) {
            hileras = hoja.createRow((i + 1));
            for (int e = 0; e < 6; e++) {
                hileras.createCell(e).setCellValue(model.getValueAt(i, e).toString());
            }
        }
        try {
            libro.write(new FileOutputStream(new File(direccion + ".xlsx")));
            Desktop.getDesktop().open(new File(direccion + ".xlsx"));
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        this.dispose();
    }
}

From source file:VentanaJava.ConsultarIngresoCortoExportar.java

private void ExportarPlanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExportarPlanActionPerformed
    DefaultTableModel model = (DefaultTableModel) TablaPlanesIngresoCortoPlazo.getModel();
    int filas = TablaPlanesIngresoCortoPlazo.getRowCount();
    JFileChooser GuardarArchivo = new JFileChooser();
    int opcion = GuardarArchivo.showSaveDialog(this);
    if (opcion == JFileChooser.APPROVE_OPTION) {
        String direccion = GuardarArchivo.getSelectedFile().toString();
        XSSFWorkbook libro = new XSSFWorkbook();
        XSSFSheet hoja = libro.createSheet();
        XSSFRow fila = hoja.createRow(0);
        fila.createCell(0).setCellValue("Granja");
        fila.createCell(1).setCellValue("Galera");
        fila.createCell(2).setCellValue("Fecha de Ingreso");
        fila.createCell(3).setCellValue("Cantidad a Ingresar");

        XSSFRow hileras;//from   ww w  .  j  a v  a 2s . c o m
        for (int i = 0; i < filas; i++) {
            hileras = hoja.createRow((i + 1));
            for (int e = 0; e < 4; e++) {
                hileras.createCell(e).setCellValue(model.getValueAt(i, e).toString());
            }
        }
        try {
            libro.write(new FileOutputStream(new File(direccion + ".xlsx")));
            Desktop.getDesktop().open(new File(direccion + ".xlsx"));
            this.dispose();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:VentanaJava.ConsultarIngresoMedianoExportar.java

private void ExportarPlanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExportarPlanActionPerformed
    DefaultTableModel model = (DefaultTableModel) TablaConsultaIngresoLargo.getModel();
    int filas = TablaConsultaIngresoLargo.getRowCount();
    JFileChooser GuardarArchivo = new JFileChooser();
    int opcion = GuardarArchivo.showSaveDialog(this);
    if (opcion == JFileChooser.APPROVE_OPTION) {
        String direccion = GuardarArchivo.getSelectedFile().toString();
        XSSFWorkbook libro = new XSSFWorkbook();
        XSSFSheet hoja = libro.createSheet();
        XSSFRow fila = hoja.createRow(0);
        fila.createCell(0).setCellValue("Granja");
        fila.createCell(1).setCellValue("Galera");
        fila.createCell(2).setCellValue("Fecha de Ingreso");
        fila.createCell(3).setCellValue("Cantidad a Ingresar");
        fila.createCell(4).setCellValue("Rol");

        XSSFRow hileras;/*from ww w .  j  av  a 2s.c om*/
        for (int i = 0; i < filas; i++) {
            hileras = hoja.createRow((i + 1));
            for (int e = 0; e < 5; e++) {
                hileras.createCell(e).setCellValue(model.getValueAt(i, e).toString());
            }
        }
        try {
            libro.write(new FileOutputStream(new File(direccion + ".xlsx")));
            Desktop.getDesktop().open(new File(direccion + ".xlsx"));
            this.dispose();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:vistas.MantenedorReportes.java

private void btnExportarGastosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarGastosActionPerformed
    Thread t;//from ww w  .  ja v  a  2 s .  c  o m
    t = new Thread() {
        @Override
        public void run() {
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet hoja = workbook.createSheet();

            XSSFRow fila = hoja.createRow(0);
            fila.createCell(0).setCellValue("N");
            fila.createCell(1).setCellValue("Vendedor");
            fila.createCell(2).setCellValue("Fecha (Ao-Mes-Da)");
            fila.createCell(3).setCellValue("Descripcin");
            fila.createCell(4).setCellValue("Valor");

            pbGastosExtras.setMaximum(tbGastosExtras.getRowCount());

            XSSFRow filas;
            Rectangle rect;

            for (int i = 0; i < tbGastosExtras.getRowCount(); i++) {
                rect = tbGastosExtras.getCellRect(i, 0, true);

                tbGastosExtras.scrollRectToVisible(rect);

                tbGastosExtras.setRowSelectionInterval(i, i);

                pbGastosExtras.setValue((i + 1));

                filas = hoja.createRow((i + 1));

                filas.createCell(0).setCellValue(tbGastosExtras.getValueAt(i, 0).toString());
                filas.createCell(1).setCellValue(tbGastosExtras.getValueAt(i, 1).toString());
                filas.createCell(2).setCellValue(tbGastosExtras.getValueAt(i, 2).toString());
                filas.createCell(3).setCellValue(tbGastosExtras.getValueAt(i, 3).toString());
                filas.createCell(4).setCellValue(tbGastosExtras.getValueAt(i, 4).toString());

            }

            pbGastosExtras.setValue(0);

            try {

                workbook.write(new FileOutputStream(new File("Excel.xlsx")));
                Desktop.getDesktop().open(new File("Excel.xlsx"));

            } catch (Exception e) {

            }

        }
    };
    t.start();

}

From source file:vistas.MantenedorReportes.java

private void btnExportarProductosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarProductosActionPerformed
    // TODO add your handling code here:
    Thread t;// ww  w .  j a  v a  2s.c om
    t = new Thread() {
        @Override
        public void run() {
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet hoja = workbook.createSheet();

            XSSFRow fila = hoja.createRow(0);
            fila.createCell(0).setCellValue("N");
            fila.createCell(1).setCellValue("Codigo");
            fila.createCell(2).setCellValue("Nombre");
            fila.createCell(3).setCellValue("Marca");
            fila.createCell(4).setCellValue("Precio Compra");
            fila.createCell(5).setCellValue("Precio Venta");
            fila.createCell(6).setCellValue("Utilidad Unitaria");
            fila.createCell(7).setCellValue("Cantidad vendida");
            fila.createCell(8).setCellValue("Utilidad Final");
            fila.createCell(9).setCellValue("Periodo anterior");

            pbProductos.setMaximum(tbGastosExtras.getRowCount());
            XSSFRow filas;
            Rectangle rect;

            for (int i = 0; i < tbProductos.getRowCount(); i++) {
                rect = tbProductos.getCellRect(i, 0, true);

                tbProductos.scrollRectToVisible(rect);

                tbProductos.setRowSelectionInterval(i, i);

                pbProductos.setValue((i + 1));
                filas = hoja.createRow((i + 1));

                filas.createCell(0).setCellValue(tbProductos.getValueAt(i, 0).toString());
                filas.createCell(1).setCellValue(tbProductos.getValueAt(i, 1).toString());
                filas.createCell(2).setCellValue(tbProductos.getValueAt(i, 2).toString());
                filas.createCell(3).setCellValue(tbProductos.getValueAt(i, 3).toString());
                filas.createCell(4).setCellValue(tbProductos.getValueAt(i, 4).toString());
                filas.createCell(5).setCellValue(tbProductos.getValueAt(i, 5).toString());
                filas.createCell(6).setCellValue(tbProductos.getValueAt(i, 6).toString());
                filas.createCell(7).setCellValue(tbProductos.getValueAt(i, 7).toString());
                filas.createCell(8).setCellValue(tbProductos.getValueAt(i, 8).toString());
                filas.createCell(9).setCellValue(tbProductos.getValueAt(i, 9).toString());

            }

            pbProductos.setValue(0);
            try {

                workbook.write(new FileOutputStream(new File("Excel.xlsx")));
                Desktop.getDesktop().open(new File("Excel.xlsx"));

            } catch (Exception e) {

            }

        }
    };
    t.start();

}

From source file:vistas.MantenedorReportes.java

private void btnExportarVendedoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarVendedoresActionPerformed
    // TODO add your handling code here:
    Thread t;// w w  w  . j a  v  a 2  s  . c o  m
    t = new Thread() {
        @Override
        public void run() {
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet hoja = workbook.createSheet();

            XSSFRow fila = hoja.createRow(0);
            fila.createCell(0).setCellValue("N");
            fila.createCell(1).setCellValue("Vendedor");
            fila.createCell(2).setCellValue("Ventas totales");
            fila.createCell(3).setCellValue("Utilidades");
            fila.createCell(4).setCellValue("Das trabajados");
            fila.createCell(5).setCellValue("Horas trabajadas");

            pbVendedores.setMaximum(tbVendedores.getRowCount());
            XSSFRow filas;
            Rectangle rect;

            for (int i = 0; i < tbVendedores.getRowCount(); i++) {
                rect = tbVendedores.getCellRect(i, 0, true);

                tbVendedores.scrollRectToVisible(rect);

                tbVendedores.setRowSelectionInterval(i, i);

                pbVendedores.setValue((i + 1));
                filas = hoja.createRow((i + 1));

                filas.createCell(0).setCellValue(tbVendedores.getValueAt(i, 0).toString());
                filas.createCell(1).setCellValue(tbVendedores.getValueAt(i, 1).toString());
                filas.createCell(2).setCellValue(tbVendedores.getValueAt(i, 2).toString());
                filas.createCell(3).setCellValue(tbVendedores.getValueAt(i, 3).toString());
                filas.createCell(4).setCellValue(tbVendedores.getValueAt(i, 4).toString());
                filas.createCell(5).setCellValue(tbVendedores.getValueAt(i, 5).toString());

            }

            pbVendedores.setValue(0);
            try {

                workbook.write(new FileOutputStream(new File("Excel.xlsx")));
                Desktop.getDesktop().open(new File("Excel.xlsx"));

            } catch (Exception e) {

            }

        }
    };
    t.start();
}

From source file:vistas.MantenedorReportes.java

private void btnExportarInventarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarInventarioActionPerformed
    // TODO add your handling code here:
    Thread t;/* w w  w . j  ava2s . c  o m*/
    t = new Thread() {
        @Override
        public void run() {
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet hoja = workbook.createSheet();

            XSSFRow fila = hoja.createRow(0);
            fila.createCell(0).setCellValue("N");
            fila.createCell(1).setCellValue("Codigo");
            fila.createCell(2).setCellValue("Nombre");
            fila.createCell(3).setCellValue("Marca");
            fila.createCell(4).setCellValue("Stock");

            pbInventario.setMaximum(tbInventario.getRowCount());
            XSSFRow filas;
            Rectangle rect;

            for (int i = 0; i < tbInventario.getRowCount(); i++) {
                rect = tbInventario.getCellRect(i, 0, true);

                tbInventario.scrollRectToVisible(rect);

                tbInventario.setRowSelectionInterval(i, i);

                pbInventario.setValue((i + 1));
                filas = hoja.createRow((i + 1));

                filas.createCell(0).setCellValue(tbInventario.getValueAt(i, 0).toString());
                filas.createCell(1).setCellValue(tbInventario.getValueAt(i, 1).toString());
                filas.createCell(2).setCellValue(tbInventario.getValueAt(i, 2).toString());
                filas.createCell(3).setCellValue(tbInventario.getValueAt(i, 3).toString());
                filas.createCell(4).setCellValue(tbInventario.getValueAt(i, 4).toString());

            }

            pbInventario.setValue(0);
            try {

                workbook.write(new FileOutputStream(new File("Excel.xlsx")));
                Desktop.getDesktop().open(new File("Excel.xlsx"));

            } catch (Exception e) {

            }

        }
    };
    t.start();
}