Example usage for org.apache.poi.ss.usermodel Workbook write

List of usage examples for org.apache.poi.ss.usermodel Workbook write

Introduction

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

Prototype

void write(OutputStream stream) throws IOException;

Source Link

Document

Write out this workbook to an Outputstream.

Usage

From source file:net.sf.excelutils.ExcelUtils.java

License:Apache License

/**
 * parse the excel template and output excel to outputStream.
 * /*from  ww  w.j  a  v  a  2s  . c  o m*/
 * @param ctx ServletContext
 * @param config Excel Template Name
 * @param context All Data
 * @param out OutputStream
 * @throws ExcelException
 */
public static void export(ServletContext ctx, String config, Object context, OutputStream out)
        throws ExcelException {
    try {
        Workbook wb = WorkbookUtils.openWorkbook(ctx, config);
        parseWorkbook(context, wb);
        wb.write(out);
    } catch (Exception e) {
        throw new ExcelException("export excel error: ", e);
    }
}

From source file:net.sf.excelutils.ExcelUtils.java

License:Apache License

/**
 * parse the excel template in a sheet and output excel to outputStream.
 * // w w w  . j av a2s.c o m
 * @param ctx
 * @param config
 * @param sheetIndex
 * @param context
 * @param out
 * @throws ExcelException
 */
public static void export(ServletContext ctx, String config, int sheetIndex, Object context, OutputStream out)
        throws ExcelException {
    try {
        Workbook wb = WorkbookUtils.openWorkbook(ctx, config);
        parseWorkbook(context, wb, sheetIndex);
        wb.write(out);
    } catch (Exception e) {
        throw new ExcelException("export excel error: ", e);
    }
}

From source file:net.sf.excelutils.ExcelUtils.java

License:Apache License

/**
 * parse excel and export//from  w  ww .j  av a  2 s.  co  m
 * 
 * @param fileName
 * @param context
 * @param out
 * @throws ExcelException
 */
public static void export(String fileName, Object context, OutputStream out) throws ExcelException {
    try {
        Workbook wb = WorkbookUtils.openWorkbook(fileName);
        parseWorkbook(context, wb);
        wb.write(out);
    } catch (Exception e) {
        throw new ExcelException("export excel error: ", e);
    }
}

From source file:net.sf.excelutils.ExcelUtils.java

License:Apache License

/**
 * parse exel and export//from   ww  w  .  j a va 2 s.c  o m
 * 
 * @param fileName
 * @param sheetIndex
 * @param out
 * @throws ExcelException
 */
public static void export(String fileName, int sheetIndex, Object context, OutputStream out)
        throws ExcelException {
    try {
        Workbook wb = WorkbookUtils.openWorkbook(fileName);
        parseWorkbook(context, wb, sheetIndex);
        wb.write(out);
    } catch (Exception e) {
        throw new ExcelException("export excel error: ", e);
    }
}

From source file:net.sf.excelutils.ExcelUtils.java

License:Apache License

/**
 * @param inputStream// www  .j  a  v a 2 s .  c  om
 * @param context
 * @param out
 * @throws ExcelException
 */
public static void export(InputStream inputStream, Object context, OutputStream out) throws ExcelException {
    try {
        Workbook wb = WorkbookUtils.openWorkbook(inputStream);
        parseWorkbook(context, wb);
        wb.write(out);
    } catch (Exception e) {
        throw new ExcelException("export excel error: ", e);
    }
}

From source file:net.sf.excelutils.WorkbookUtils.java

License:Apache License

/**
 * Save the Excel to OutputStream/*  w  w w.j ava 2s  .co m*/
 *
 * @param wb Workbook
 * @param out OutputStream
 * @throws ExcelException
 */
public static void saveWorkbook(Workbook wb, OutputStream out) throws ExcelException {
    try {
        wb.write(out);
    } catch (Exception e) {
        throw new ExcelException(e.getMessage());
    }
}

From source file:no.imr.sea2data.stox.components.table.OutputTopComponent.java

private void jExcelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jExcelActionPerformed
    FileOutputStream out = null;/*  w w  w  .j  a  va  2 s  . c  om*/
    try {
        Workbook wb = new HSSFWorkbook();
        for (int iPage = 0; iPage < jTabbedPane1.getTabCount(); iPage++) {
            OutputPanel panel = (OutputPanel) jTabbedPane1.getComponentAt(iPage);
            String text = panel.getText();
            String[] lines = text.split("\n");
            if (lines.length < 60000) {
                Sheet sh = wb.createSheet(panel.getTabName());
                for (int i = 0; i < lines.length; i++) {
                    String line = lines[i];
                    String[] cells = line.split("\t");
                    for (int j = 0; j < cells.length; j++) {
                        Cell c = safeCell(sh, i, j);
                        String cell = cells[j];
                        Double d = Conversion.safeStringtoDoubleNULL(cell);
                        if (d != null) {
                            c.setCellValue(d);
                        } else {
                            if (cell.length() > 1000) {
                                cell = cell.substring(0, 1000);
                            }
                            c.setCellValue(cell);
                        }
                    } // for
                } // for
            }
        } // for
        String outFile = System.getProperty("java.io.tmpdir") + "/stox_output_"
                + IMRdate.formatDate(new Date(), "dd-MM-yyyy HH-mm-ss", false) + ".xls";
        out = new FileOutputStream(new File(outFile));
        wb.write(out);
        out.close();
        Desktop.getDesktop().open(new File(outFile));
    } catch (FileNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }

}

From source file:NoCongruential.LinealAlgorithm.java

public void calcNumbers(String x0, String a, String c, String m, String cantidad) {
    int y = 0;//  www  .  j ava  2  s.  co  m
    double random;

    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("r");

        for (int i = 0; i < Integer.parseInt(cantidad); i++) {
            fila = (HSSFRow) hoja.createRow(i + 1);
            celda = fila.createCell(0);
            celda.setCellValue(x0);
            x0 = String.valueOf(
                    ((Integer.parseInt(a) * Float.parseFloat(x0)) + Integer.parseInt(c)) % Integer.parseInt(m));
            random = (Float.parseFloat(x0) / (Integer.parseInt(m) - 1));
            System.out.println("rando " + random);
            celda = fila.createCell(1);
            celda.setCellValue(random);
        }

        libro.write(archivo);
        archivo.close();
    } catch (IOException e) {
    }

}

From source file:nz.ac.auckland.abi.formatting.poi.ModelJSONToExcel.java

License:LGPL

public void createXLS(Hashtable<String, String> models, String filename) throws Exception {
    List<FEMModelMeasure> measures = new ArrayList<FEMModelMeasure>();
    int maxTimePoints = 0;
    for (String model : models.keySet()) {
        String json = models.get(model);
        FEMModelMeasure mMeasure = new FEMModelMeasure(json, model);
        if (mMeasure.getTimePoints() > maxTimePoints) {
            maxTimePoints = mMeasure.getTimePoints();
        }//from  w w w. j a v  a2  s. c  o  m
        measures.add(mMeasure);
    }
    File xlFile = new File(filename);
    if (xlFile.exists()) {
        xlFile.delete();
    }

    Workbook wb = new HSSFWorkbook();
    Map<String, CellStyle> styles = createStyles(wb);
    // Create an Aggregate sheet to collate the data across models/measures
    // Create here, so that it is the first sheet
    Sheet dashboard = wb.createSheet("Dashboard");

    // Create a worksheet for each measure type
    String[] names = getMeasureNames(measures);
    for (String name : names) {
        addWorkSheet(wb, name, measures, maxTimePoints, styles);
    }
    // Populate the dashboard
    createDashBoard(dashboard, names, measures, styles);
    createMetaData(wb, styles);
    FileOutputStream out = new FileOutputStream(filename);
    wb.write(out);
    out.close();
}

From source file:ObjectLabEnterpriseSoftware.FileManager.java

public boolean saveReport(String name, Workbook wb) {

    try {/*ww  w .  j av  a  2  s .  c o m*/
        FileOutputStream out = new FileOutputStream(excelFilePath + name + ".xls");
        wb.write(out);
        out.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(FileManager.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    } catch (IOException ex) {
        Logger.getLogger(FileManager.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }

    return true;
}