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:com.envision.envservice.common.util.ExcelUtil.java

License:Open Source License

public static void export(String path, XSSFWorkbook workbook) {
    FileOutputStream fos = null;//  ww w  .  ja  va  2 s.  c  o m
    try {
        fos = new FileOutputStream(buildFile(path));
        workbook.write(fos);
    } catch (IOException e) {
        throw new RuntimeException("Excel export fail.", e);
    } finally {
        close(fos);
    }
}

From source file:com.envision.envservice.report.PraiseReporter.java

License:Open Source License

public byte[] report() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XSSFWorkbook workBook = PraiseReportExcel.buildWorkBook(count());
    workBook.write(out);

    return out.toByteArray();
}

From source file:com.envisioncn.it.super_sonic.showcase.evaluation.utils.ExcelUtils.java

License:Open Source License

public static void downFile(HttpServletResponse response, HttpServletRequest request, XSSFWorkbook xssfWorkbook)
        throws IOException {
    // -----//from   w w  w.j  av  a2 s. c o  m
    // ??Content-TypeContent-Disposition
    // ??
    String downFilename = DOWNFILENAME;
    // ?MIME
    String contentType = request.getServletContext().getMimeType(downFilename);
    // MIME?
    response.setContentType(contentType);
    // ?
    String agent = request.getHeader("user-agent");
    // ????
    downFilename = FileUtils.encodeDownloadFilename(downFilename, agent);
    // ????
    String contentDisposition = "attachment;filename=" + downFilename;
    // ?????
    response.setHeader("Content-Disposition", contentDisposition);

    // excel?
    xssfWorkbook.write(response.getOutputStream());
}

From source file:com.frameworkset.platform.sanylog.action.CounterController.java

License:Open Source License

/**
 * Excel//ww w .  j ava 2 s .  c  o m
*/
public void downloadExcel(String time, String type, String appId, HttpServletResponse response) {

    try {
        List<OperRank> datas = counterManager.getExcelDatas(time, type, appId);
        if (null != datas && datas.size() > 0) {
            for (int i = 0; i < datas.size(); i++) {
                int j = i + 1;
                datas.get(i).setAppId("(" + j + ")");
            }
        }
        String colDesc = getExcelColDesc(Dictionary.titles);
        XSSFWorkbook wb = POIExcelUtil2007.createHSSFWorkbook(colDesc, datas);

        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename="
                + new URLCodec().encode(time + "__" + datas.get(0).getAppName() + "__?.xlsx"));
        wb.write(response.getOutputStream());
    } catch (Exception e) {
        e.printStackTrace();

    }

}

From source file:com.grant.report.StockOut.java

public static void main(String[] args) throws SQLException {
    ItemDAO d = new ItemDAO();
    Map<String, Object[]> data = new TreeMap<String, Object[]>();
    //  data =  d.getAllItemOutReport();

    //Blank workbook
    XSSFWorkbook workbook = new XSSFWorkbook();

    //Create a blank sheet
    XSSFSheet sheet = workbook.createSheet("Employee Data");

    //This data needs to be written (Object[])
    /*//w  w w.ja v  a  2 s.  c om
    Map<String, Object[]> data = new TreeMap<String, Object[]>();
    data.put("1", new Object[] {"ID", "NAME", "LASTNAME"});
    data.put("2", new Object[] {1, "Amit", "Shukla"});
    data.put("3", new Object[] {2, "Lokesh", "Gupta"});
    data.put("4", new Object[] {3, "John", "Adwards"});
    data.put("5", new Object[] {4, "Brian", "Schultz"});
            
     */
    //Iterate over data and write to sheet
    Set<String> keyset = data.keySet();
    int rownum = 0;
    for (String key : keyset) {
        Row row = sheet.createRow(rownum++);
        Object[] objArr = data.get(key);
        int cellnum = 0;
        for (Object obj : objArr) {
            Cell cell = row.createCell(cellnum++);
            if (obj instanceof String) {
                cell.setCellValue((String) obj);
            } else if (obj instanceof Integer) {
                cell.setCellValue((Integer) obj);
            }
        }
    }
    try {
        //Write the workbook in file system
        FileOutputStream out = new FileOutputStream(new File("howtodoinjava_demo.xlsx"));
        workbook.write(out);
        out.close();
        System.out.println("howtodoinjava_demo.xlsx written successfully on disk.");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.griffinslogistics.document.excel.BookLabelGenerator.java

public static void generateLabels(OutputStream outputStream, List<BookLabelModel> bookLabelModelList) {
    XSSFWorkbook workbook = new XSSFWorkbook();

    for (BookLabelModel bookLabelModel : bookLabelModelList) {
        generate(workbook, bookLabelModel);
    }//from www  . j a va2  s .c om

    try {
        workbook.write(outputStream);

    } catch (IOException ex) {
        Logger.getLogger(BookLabelGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.griffinslogistics.document.excel.BookLabelGenerator.java

public static void generateLabel(OutputStream outputStream, BookLabelModel bookLabelModel) {
    XSSFWorkbook workbook = new XSSFWorkbook();
    generate(workbook, bookLabelModel);// ww  w.  j  a v  a2s  .c o m
    try {
        workbook.write(outputStream);

    } catch (IOException ex) {
        Logger.getLogger(BookLabelGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.griffinslogistics.document.excel.CMRGenerator.java

public static void generateAll(OutputStream outputStream, List<BookspackageCMRModel> bookspackageCMRModels,
        Pulsiodetails pulsioDetails) {//from   ww  w .j  ava 2  s . c  o m
    try {
        XSSFWorkbook workbook = new XSSFWorkbook();

        for (BookspackageCMRModel bookspackageCMRModel : bookspackageCMRModels) {
            generate(workbook, bookspackageCMRModel, pulsioDetails);
        }

        workbook.write(outputStream);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(CMRGenerator.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(CMRGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.griffinslogistics.document.excel.CMRGenerator.java

public static void generateSingle(OutputStream outputStream, BookspackageCMRModel bookspackageCMRModel,
        Pulsiodetails pulsioDetails) {//from www .j av a 2  s  .  co  m
    XSSFWorkbook workbook = new XSSFWorkbook();
    generate(workbook, bookspackageCMRModel, pulsioDetails);

    try {
        workbook.write(outputStream);
    } catch (IOException ex) {
        Logger.getLogger(CMRGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.griffinslogistics.excel.BookLabelGenerator.java

public static void generateLabel(OutputStream outputStream, BookLabelModel bookLabelModel) {

    try {//from  w w  w  .j  a  va  2  s  .  c  o  m
        XSSFWorkbook workbook = new XSSFWorkbook();
        Map<String, CellStyle> styles = createStyles(workbook);
        String title = bookLabelModel.getTitle().replace("/", "-");
        bookLabelModel.setTitle(title);
        Sheet sheet = workbook.createSheet(bookLabelModel.getBookNumber() + " " + bookLabelModel.getTitle());

        for (int i = 0; i < 20; i++) {
            Row row = sheet.createRow(i);
            if (i != 0 && i != 10) {
                row.setHeightInPoints(25);
            } else {
                row.setHeightInPoints(12);
            }
        }

        //column widths
        sheet.setColumnWidth(0, 5000);
        sheet.setColumnWidth(1, 10000);

        sheet.setColumnWidth(3, 5000);
        sheet.setColumnWidth(4, 10000);

        generateHeaders(sheet, styles);
        generateAddress(sheet, styles, bookLabelModel);
        generateClient(sheet, styles, bookLabelModel);
        generateTransportation(sheet, styles, bookLabelModel);
        generateTitle(sheet, styles, bookLabelModel);
        generateCountPerBox(sheet, styles, bookLabelModel);
        generateCountPerAddress(sheet, styles, bookLabelModel);

        sheet.autoSizeColumn(1);
        sheet.autoSizeColumn(4);

        workbook.write(outputStream);
    } catch (IOException ex) {
        Logger.getLogger(BookLabelGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
}