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:com.globalsight.everest.webapp.pagehandler.administration.reports.ReviewerLisaQAXlsReportHelper.java

License:Apache License

/**
 * Generates Excel report/*from  ww w .  j ava  2 s .  co  m*/
 * 
 * @throws Exception
 */
public void generateReport() throws Exception {
    bundle = PageHandler.getBundle(request.getSession());

    Workbook workbook = new SXSSFWorkbook();
    String dateFormat = request.getParameter(WebAppConstants.DATE_FORMAT);
    if (dateFormat == null) {
        dateFormat = DEFAULT_DATE_FORMAT;
    }

    createReport(workbook, dateFormat);

    ServletOutputStream out = response.getOutputStream();
    workbook.write(out);
    out.close();
    ((SXSSFWorkbook) workbook).dispose();
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.ReviewerVendorPoXlsReportHelper.java

License:Apache License

/**
 * Generates the Excel report as a temp file and returns the temp file.
 * //  ww  w.j  ava 2s.  com
 * @return File
 * @exception Exception
 */
public void generateReport() throws Exception {
    bundle = PageHandler.getBundle(request.getSession());

    Workbook p_workbook = new SXSSFWorkbook();

    HashMap projectMap = data.projectMap;

    data.dellSheet = p_workbook.createSheet(bundle.getString("lb_globalsight_matches"));
    data.tradosSheet = p_workbook.createSheet(bundle.getString("jobinfo.tradosmatches"));

    addTitle(p_workbook, data.dellSheet);
    addHeaderForDellMatches(p_workbook);
    addTitle(p_workbook, data.tradosSheet);
    addHeaderForTradosMatches(p_workbook);

    IntHolder row = new IntHolder(4);
    writeProjectDataForDellMatches(p_workbook, projectMap, row);
    row = new IntHolder(4);
    writeProjectDataForTradosMatches(p_workbook, projectMap, row);

    Sheet paramsSheet = p_workbook.createSheet(bundle.getString("lb_criteria"));
    writeParamsSheet(p_workbook, paramsSheet);
    List<Long> reportJobIDS = new ArrayList(data.jobIdList);
    // Cancel Duplicate Request
    if (ReportHelper.checkReportsDataInProgressStatus(userId, reportJobIDS, getReportType())) {
        String message = "Cancle Review Vendor Report: " + userId + ", " + reportJobIDS;
        s_logger.info(message);
        response.sendError(response.SC_NO_CONTENT);
        return;
    }
    // Set ReportsData.
    ReportHelper.setReportsData(userId, reportJobIDS, getReportType(), 0, ReportsData.STATUS_INPROGRESS);

    ServletOutputStream out = response.getOutputStream();
    p_workbook.write(out);
    out.close();
    ((SXSSFWorkbook) p_workbook).dispose();

    // Set ReportsData.
    ReportHelper.setReportsData(userId, reportJobIDS, getReportType(), 100, ReportsData.STATUS_FINISHED);
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.SlaXlsReportHelper.java

License:Apache License

/**
 * Generates the Excel report as a temp file and returns the temp file.
 * //  w  w w  .j  a v  a2  s .  c  o  m
 * @return File
 * @exception Exception
 */
public void generateReport() throws Exception {
    userId = (String) request.getSession(false).getAttribute(WebAppConstants.USER_NAME);
    List<Long> reportJobIDS = new ArrayList<Long>(data.jobIdList);
    // Cancel Duplicate Request
    if (ReportHelper.checkReportsDataInProgressStatus(userId, reportJobIDS, getReportType())) {
        response.sendError(response.SC_NO_CONTENT);
        return;
    }
    // Set ReportsData.
    ReportHelper.setReportsData(userId, reportJobIDS, getReportType(), 0, ReportsData.STATUS_INPROGRESS);

    Workbook workbook = new SXSSFWorkbook();

    HashMap projectMap = data.projectMap;

    data.generalSheet = workbook.createSheet(bundle.getString("lb_sheet") + "1");

    addTitle(workbook);

    addHeader(workbook);

    IntHolder row = new IntHolder(4);
    writeProjectData(workbook, projectMap, row);

    ServletOutputStream out = response.getOutputStream();
    workbook.write(out);
    out.close();
    ((SXSSFWorkbook) workbook).dispose();

    // Set ReportsData.
    ReportHelper.setReportsData(userId, reportJobIDS, getReportType(), 100, ReportsData.STATUS_FINISHED);
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.TranslationProgressReportHelper.java

License:Apache License

/**
 * Generates the Excel report and spits it to the outputstream The report
 * consists of all in progress tasks//  w w  w.  j  av  a2s  . co  m
 * 
 * @return File
 * @exception Exception
 */
public void generateReport(HttpServletRequest p_request, HttpServletResponse p_response) throws Exception {
    String companyName = UserUtil.getCurrentCompanyName(p_request);
    CompanyThreadLocal.getInstance().setValue(companyName);

    setLocale(p_request);

    p_request.setCharacterEncoding("UTF-8");
    HttpSession session = p_request.getSession(false);
    userId = (String) session.getAttribute(WebAppConstants.USER_NAME);
    percent = NumberFormat.getPercentInstance((Locale) session.getAttribute(WebAppConstants.UILOCALE));

    Workbook p_workbook = new SXSSFWorkbook();
    addJobs(p_workbook, p_request, p_response);
    // Cancelled the report, return nothing.
    if (isCancelled()) {
        p_response.sendError(p_response.SC_NO_CONTENT);
        return;
    }

    ServletOutputStream out = p_response.getOutputStream();
    p_workbook.write(out);
    out.close();
    ((SXSSFWorkbook) p_workbook).dispose();
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.VendorPOXlsReport.java

License:Apache License

/**
 * Generates the Excel report as a temp file and returns the temp file.
 * // w  ww . j a v a  2  s.  co  m
 * @return File
 * @exception Exception
 */
private void generateReport(HttpServletRequest p_request, HttpServletResponse p_response, MyData p_data)
        throws Exception {
    bundle = PageHandler.getBundle(p_request.getSession());
    String EMEA = CompanyWrapper.getCurrentCompanyName();
    s_logger.debug("generateReport---, company name: " + EMEA);

    Workbook p_workbook = new SXSSFWorkbook();
    boolean recalculateFinishedWorkflow = false;
    String recalcParam = p_request.getParameter("recalc");
    if (recalcParam != null && recalcParam.length() > 0) {
        recalculateFinishedWorkflow = java.lang.Boolean.valueOf(recalcParam).booleanValue();
    }

    // get all the jobs that were originally imported with the wrong project
    // the users want to pretend that these jobs are in this project
    getJobsInWrongProject(p_data);
    HashMap projectMap = getProjectData(p_request, p_response, recalculateFinishedWorkflow, p_data);

    if (projectMap != null) {
        p_data.dellSheet = p_workbook.createSheet(EMEA + " " + bundle.getString("lb_matches"));
        p_data.tradosSheet = p_workbook.createSheet(bundle.getString("jobinfo.tradosmatches"));
        addTitle(p_workbook, p_data.dellSheet);
        addHeaderForDellMatches(p_workbook, p_data);
        addTitle(p_workbook, p_data.tradosSheet);
        addHeaderForTradosMatches(p_workbook, p_data);
        IntHolder row = new IntHolder(4);
        writeProjectDataForDellMatches(p_workbook, projectMap, row, p_data);
        row = new IntHolder(4);
        writeProjectDataForTradosMatches(p_workbook, projectMap, row, p_data);

        Sheet paramsSheet = p_workbook.createSheet(bundle.getString("lb_criteria"));
        writeParamsSheet(p_workbook, paramsSheet, p_data, p_request);

        ServletOutputStream out = p_response.getOutputStream();
        p_workbook.write(out);
        out.close();
        ((SXSSFWorkbook) p_workbook).dispose();

        // Set ReportsData.
        ReportHelper.setReportsData(userId, m_jobIDS, getReportType(), 100, ReportsData.STATUS_FINISHED);
    }
}

From source file:com.google.gdt.handler.impl.ExcelHandler.java

License:Open Source License

/**
 * /*from w ww.j a v  a 2  s.  co m*/
 * @param inputFile
 * @throws IOException
 * @throws InvalidFormatException
 */
@Override
public void handle(String inputFile, ProgressLevel pLevel) throws IOException, InvalidFormatException {
    String outPutFile = getOuputFileName(inputFile);
    OutputStream outputStream = new FileOutputStream(outPutFile);
    InputStream is = new FileInputStream(inputFile);

    Workbook wb = WorkbookFactory.create(is);
    List<Sheet> sheets = getSheets(wb);

    pLevel.setTrFileName(outPutFile);

    //iterate over sheet
    for (int index = 0; index < sheets.size(); index++) {
        Sheet sheet = sheets.get(index);

        if (sheets.size() > 1) {
            pLevel.setString("Translating sheet " + (index + 1) + "/" + sheets.size());
        }

        int firstRowNum = sheet.getFirstRowNum();
        int lastRowNum = sheet.getLastRowNum();
        int rowCount = lastRowNum - firstRowNum;
        // check for empty sheet, don't perform any operation
        if (rowCount == 0) {
            continue;
        }
        pLevel.setValue(0);
        pLevel.setMaxValue(rowCount);
        pLevel.setStringPainted(true);

        int pBarUpdate = 0;
        //iterate over row
        for (Row row : sheet) {
            //iterate over cells
            for (Cell cell : row) {
                if (isInterrupted) {
                    outputStream.close();
                    new File(outPutFile).delete();
                    pLevel.setString("cancelled");
                    return;
                }

                if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                    String inputText = cell.getStringCellValue();
                    String translatedTxt = inputText;
                    try {
                        translatedTxt = translator.translate(inputText);
                        cell.setCellValue(translatedTxt);
                    } catch (Exception e) {
                        logger.log(Level.SEVERE,
                                "Input File : " + inputFile + " cannot translate the text : " + inputText, e);
                        continue;
                    }
                }
            } //cell iteration ends
            pBarUpdate++;
            pLevel.setValue(pBarUpdate);
        } //row iteration ends
        pLevel.setValue(rowCount);
    }
    pLevel.setString("done");

    wb.write(outputStream);
    outputStream.close();
}

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

public static void generateAll(OutputStream outputStream,
        Map<String, List<BookBoxModel>> bookBoxModelsForTransportation, Pulsiodetails pulsioDetails,
        String packageNumber) {/* ww  w  .ja va  2 s .  c  o m*/
    try {
        Workbook workbook = new XSSFWorkbook();

        for (String bookspackageNumber : bookBoxModelsForTransportation.keySet()) {
            List<BookBoxModel> bookBoxModels = bookBoxModelsForTransportation.get(bookspackageNumber);

            generate(workbook, bookBoxModels, pulsioDetails, bookspackageNumber);
        }

        workbook.write(outputStream);
    } catch (FileNotFoundException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
}

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

public static void generateSingle(OutputStream outputStream, List<BookBoxModel> bookBoxModels,
        Pulsiodetails pulsiodetails, String packageNumber) {

    try {//from ww w . ja v  a2s.  c  o m
        Workbook workbook = new XSSFWorkbook();
        generate(workbook, bookBoxModels, pulsiodetails, packageNumber);
        workbook.write(outputStream);
    } catch (FileNotFoundException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
}

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

public static void generateAll(OutputStream outputStream,
        Map<String, List<BookBoxModel>> bookBoxModelsForTransportation, Pulsiodetails pulsioDetails,
        String packageNumber) {/*from www .j  a  v a2  s.  c  om*/
    try {
        Workbook workbook = new HSSFWorkbook();
        Map<String, CellStyle> styles = createStyles(workbook);

        for (String bookspackageNumber : bookBoxModelsForTransportation.keySet()) {

            Sheet sheet = workbook.createSheet(bookspackageNumber);

            //Default sheet styles
            sheet.setDisplayGridlines(false);
            sheet.setPrintGridlines(false);
            sheet.getPrintSetup().setLandscape(true);
            sheet.setFitToPage(true);
            sheet.setHorizontallyCenter(true);
            sheet.setDefaultRowHeight((short) 300);
            sheet.setDefaultColumnWidth(15);

            sheet.setColumnWidth(1, 6000);
            sheet.setColumnWidth(5, 3000);
            sheet.setColumnWidth(6, 3000);
            sheet.setColumnWidth(7, 3000);
            sheet.setColumnWidth(8, 3000);

            // Generate header part
            insertPulsioImage(workbook, sheet, pulsioDetails);
            insertDate(sheet, styles.get("title"));
            insertContacts(sheet, styles.get("pulsioName"), styles.get("contacts"), pulsioDetails);
            insertTitle(sheet, styles.get("title"));

            // Generate table part
            insertTableHeaders(sheet, styles.get("tableHeadersLeft"), styles.get("tableHeadersMiddle"),
                    styles.get("tableHeadersRight"));
            List<BookBoxModel> bookBoxModels = bookBoxModelsForTransportation.get(bookspackageNumber);
            int index = insertTableBody(sheet, styles.get("tableBodyLeft"), styles.get("tableBodyMiddle"),
                    styles.get("tableBodyRight"), styles.get("tableFooters"), bookBoxModels);

            String deliveryAddress = bookBoxModels.get(0).getDeliveryAddress();
            String client = bookBoxModels.get(0).getClient();
            insertFooter(sheet, styles.get("footer"), index, bookspackageNumber, deliveryAddress, client);
        }

        workbook.write(outputStream);
    } catch (FileNotFoundException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
}

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

public static OutputStream generateSingle(OutputStream outputStream, List<BookBoxModel> bookBoxModels,
        Pulsiodetails pulsiodetails, String packageNumber) {

    try {//from   w w w  .ja va  2  s.  c  o m
        Workbook workbook = new HSSFWorkbook();
        Map<String, CellStyle> styles = createStyles(workbook);
        Sheet sheet = workbook.createSheet("Bon de livraison");

        //Default sheet styles
        sheet.setDisplayGridlines(false);
        sheet.setPrintGridlines(false);
        sheet.getPrintSetup().setLandscape(true);
        sheet.setFitToPage(true);
        sheet.setHorizontallyCenter(true);
        sheet.setDefaultRowHeight((short) 300);
        sheet.setDefaultColumnWidth(15);

        sheet.setColumnWidth(1, 6000);
        sheet.setColumnWidth(5, 3000);
        sheet.setColumnWidth(6, 3000);
        sheet.setColumnWidth(7, 3000);
        sheet.setColumnWidth(8, 3000);

        // Generate header part
        insertPulsioImage(workbook, sheet, pulsiodetails);
        insertDate(sheet, styles.get("title"));
        insertContacts(sheet, styles.get("pulsioName"), styles.get("contacts"), pulsiodetails);
        insertTitle(sheet, styles.get("title"));

        // Generate table part
        insertTableHeaders(sheet, styles.get("tableHeadersLeft"), styles.get("tableHeadersMiddle"),
                styles.get("tableHeadersRight"));
        int index = insertTableBody(sheet, styles.get("tableBodyLeft"), styles.get("tableBodyMiddle"),
                styles.get("tableBodyRight"), styles.get("tableFooters"), bookBoxModels);

        String deliveryAddress = bookBoxModels.get(0).getDeliveryAddress();
        String client = bookBoxModels.get(0).getClient();

        insertFooter(sheet, styles.get("footer"), index, packageNumber, deliveryAddress, client);

        workbook.write(outputStream);
    } catch (FileNotFoundException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    }

    return outputStream;
}