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.generator.ImplementedCommentsCheckReportGenerator.java

License:Apache License

/**
 * Generates Excel report// w w  w . j  a v  a  2 s  .c  o m
 * 
 * @param p_jobIDS
 *            Job ID List
 * @param p_targetLocales
 *            Target Locales List
 * @param p_companyName
 *            Company Name
 * @throws Exception
 */
public File[] generateReports(List<Long> p_jobIDS, List<GlobalSightLocale> p_targetLocales) throws Exception {
    ArrayList<String> stateList = ReportHelper.getAllJobStatusList();
    stateList.remove(Job.PENDING);

    if (p_jobIDS == null || p_jobIDS.size() == 0) {
        p_jobIDS = m_jobIDS;
        p_targetLocales = m_targetLocales;
    } else if (m_jobIDS == null || m_jobIDS.size() == 0) {
        m_jobIDS = p_jobIDS;
    }
    List<File> workBooks = new ArrayList<File>();
    String dateFormat = request.getParameter(WebAppConstants.DATE_FORMAT);
    Set<String> stateSet = new HashSet<String>();
    Set<String> projectSet = new HashSet<String>();
    if (dateFormat == null) {
        dateFormat = DEFAULT_DATE_FORMAT;
    }

    int finishedJobNum = 0;
    for (long jobID : p_jobIDS) {
        // Cancel generate reports.
        if (isCancelled())
            return null;

        Job job = ServerProxy.getJobHandler().getJobById(jobID);
        if (job == null || !stateList.contains(job.getState()))
            continue;

        stateSet.add(job.getDisplayState());
        projectSet.add(job.getProject().getName());

        setAllCellStyleNull();
        Workbook workBook = new SXSSFWorkbook();
        createReport(workBook, job, p_targetLocales, dateFormat);
        File file = getFile(reportType, job, workBook);
        FileOutputStream out = new FileOutputStream(file);
        workBook.write(out);
        out.close();
        ((SXSSFWorkbook) workBook).dispose();
        workBooks.add(file);

        // Sets Reports Percent.
        setPercent(++finishedJobNum);
    }

    return ReportHelper.moveReports(workBooks, m_userId);
}

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

License:Apache License

@Override
public File[] generateReports(List<Long> p_jobIDS, List<GlobalSightLocale> p_targetLocales) throws Exception {
    // Generate Report from HttpServletRequest.
    if (p_jobIDS == null || p_jobIDS.size() == 0) {
        return generateReport(m_request);
    }/*from   ww w.j a  v a2 s.  c  o  m*/

    File file = ReportHelper.getXLSReportFile(getReportType(), null);
    Workbook workbook = new SXSSFWorkbook();
    HashSet<Job> jobs = new HashSet<Job>(ReportHelper.getJobListByIDS(p_jobIDS));
    m_data.wantsAllLocales = true;
    m_data.wantsAllProjects = true;
    m_data.setDateFormatString("MM/dd/yy hh:mm:ss a z");
    m_data.jobIds = p_jobIDS;
    HashMap<String, HashMap<String, ProjectWorkflowData>> projectMap = reportDataMap(jobs, false, false);
    if (projectMap != null && projectMap.size() > 0) {
        // Create sheets in Workbook.
        createSheets(workbook, projectMap, false);
        FileOutputStream out = new FileOutputStream(file);
        workbook.write(out);
        out.close();
        ((SXSSFWorkbook) workbook).dispose();
        List<File> workBooks = new ArrayList<File>();
        workBooks.add(file);
        return ReportHelper.moveReports(workBooks, m_userId);
    } else {
        return new File[0];
    }
}

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

License:Apache License

/**
 * Generates the Excel report as a temp file and returns the temp file. The
 * report consists of all jobs for the given PM, this year, on a month by
 * month basis./*from  w  w w  .j  ava 2s .  co m*/
 * 
 * @return File
 * @exception Exception
 */
private File[] generateReport(HttpServletRequest p_request) throws Exception {
    String[] months = getMonths();
    File file = ReportHelper.getXLSReportFile(getReportType(), null);
    Workbook p_workbook = new SXSSFWorkbook();
    int currentMonth = m_calendar.get(Calendar.MONTH);
    int year;
    if (p_request.getParameter("year") != null) {
        year = Integer.parseInt(p_request.getParameter("year"));
    } else {
        year = m_calendar.get(Calendar.YEAR);
    }
    if (year != m_calendar.get(Calendar.YEAR))
        currentMonth = 11;

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

    // For "Dell Review Report Issue"
    // Gets the tag that marks whether needs to separates "Dell_Review" or
    // not.
    // Default value is "false".
    boolean includeExReview = false;

    String reviewParam = p_request.getParameter("review");
    if ((reviewParam != null) && (reviewParam.length() > 0)) {
        includeExReview = java.lang.Boolean.valueOf(reviewParam).booleanValue();
    }

    // For "Add Job Id into online job report" issue
    isJobIdVisible = isJobIdVisible(p_request);
    String isReportForYear = p_request.getParameter("reportForThisYear");
    String isReportForDetail = p_request.getParameter("reportForDetail");
    // Generate Report By Year
    if (isReportForYear != null && isReportForYear.equals("on")) {
        int i = 0;
        for (i = 0; i <= currentMonth; i++) {
            // For "Dell Review Report Issue"
            // Add new parameter "includeExReview" to the signature.
            HashMap<String, HashMap<String, ProjectWorkflowData>> projectMap = getProjectDataForMonth(p_request,
                    i, recalculateFinishedWorkflow, includeExReview);

            // Cancel the report.
            if (isCancelled())
                return new File[0];

            if (projectMap.size() > 0) {
                // This sheets array has two elements.
                // sheets[MONTH_SHEET], the original monthSheet.
                // sheets[MONTH_REVIEW_SHEET], new monthly Dell_Review
                // sheet.
                Sheet[] sheets = new Sheet[2];
                IntHolder[] rows = new IntHolder[2];

                String sheetTitle = months[i] + " " + year;
                sheets[MONTH_SHEET] = p_workbook.createSheet(sheetTitle);

                // m_data.isTradosStyle by default is true, matches trados for UI is hidden
                if (m_data.isTradosStyle()) {
                    addTitle(p_workbook, sheets[MONTH_SHEET]);
                    addHeaderTradosStyle(p_workbook, sheets[MONTH_SHEET], MONTH_SHEET);
                } else {
                    addTitle(p_workbook, sheets[MONTH_SHEET]);
                    addHeader(p_workbook, sheets[MONTH_SHEET], MONTH_SHEET);
                }

                rows[MONTH_SHEET] = new IntHolder(4);

                if (includeExReview) {
                    String sheetReviewTitle = m_bundle.getString("lb_review") + " " + months[i] + " " + year;
                    sheets[MONTH_REVIEW_SHEET] = p_workbook.createSheet(sheetReviewTitle);
                    if (m_data.isTradosStyle()) {
                        addTitle(p_workbook, sheets[MONTH_REVIEW_SHEET]);
                        addHeaderTradosStyle(p_workbook, sheets[MONTH_REVIEW_SHEET], MONTH_REVIEW_SHEET);
                    } else {
                        addTitle(p_workbook, sheets[MONTH_REVIEW_SHEET]);
                        addHeader(p_workbook, sheets[MONTH_REVIEW_SHEET], MONTH_REVIEW_SHEET);
                    }
                    rows[MONTH_REVIEW_SHEET] = new IntHolder(4);
                }

                if (m_data.isTradosStyle()) {
                    writeProjectDataTradosStyle(projectMap, p_workbook, sheets, includeExReview, rows);
                } else {
                    writeProjectData(projectMap, p_workbook, sheets, includeExReview, rows);
                }
                wroteSomething = true;
            }
        }

        if (!wroteSomething) {
            // just write out the first sheet to avoid Excel problems
            i = 0;
            String sheetTitle = months[currentMonth] + " " + year;
            Sheet monthSheet = p_workbook.createSheet(sheetTitle);
            if (m_data.isTradosStyle()) {
                addTitle(p_workbook, monthSheet);
                addHeaderTradosStyle(p_workbook, monthSheet, MONTH_SHEET);
            } else {
                addTitle(p_workbook, monthSheet);
                addHeader(p_workbook, monthSheet, MONTH_SHEET);
            }

            if (includeExReview) {
                String sheetReviewTitle = "Review " + months[currentMonth] + " " + year;
                Sheet monthReviewSheet = p_workbook.createSheet(sheetReviewTitle);
                if (m_data.isTradosStyle()) {
                    addTitle(p_workbook, monthReviewSheet);
                    addHeaderTradosStyle(p_workbook, monthReviewSheet, MONTH_REVIEW_SHEET);
                } else {
                    addTitle(p_workbook, monthReviewSheet);
                    addHeader(p_workbook, monthReviewSheet, MONTH_REVIEW_SHEET);
                }
            }
        }

        // Create "Criteria" Sheet
        addParamsSheet(p_workbook, (String) p_request.getParameter("year"), recalculateFinishedWorkflow);

        FileOutputStream out = new FileOutputStream(file);
        p_workbook.write(out);
        out.close();
        ((SXSSFWorkbook) p_workbook).dispose();
    }
    // Generate Report by Creation Date Range.
    else if (isReportForDetail != null && isReportForDetail.endsWith("on")) {
        // For "Dell Review Report Issue"
        // Add new parameter "includeExReview" to the signature.
        HashMap<String, HashMap<String, ProjectWorkflowData>> projectMap = getProjectDataForMonth(p_request, 0,
                recalculateFinishedWorkflow, includeExReview);

        // Cancel the report.
        if (isCancelled())
            return new File[0];

        // Create sheets in Workbook.
        createSheets(p_workbook, projectMap, includeExReview);

        // Create "Criteria" Sheet  
        addParamsSheet(p_workbook, (String) p_request.getParameter("year"), recalculateFinishedWorkflow);

        FileOutputStream out = new FileOutputStream(file);
        p_workbook.write(out);
        out.close();
        ((SXSSFWorkbook) p_workbook).dispose();
    }

    List<File> workBooks = new ArrayList<File>();
    workBooks.add(file);
    return ReportHelper.moveReports(workBooks, m_userId);
}

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

License:Apache License

/**
 * Generates the Excel report as a temp file and returns the temp file. The
 * report consists of all jobs for the given PM, this year, on a month by
 * month basis.//from  w  ww .  j  a va  2s . com
 * 
 * @return File
 * @exception Exception
 */
private File[] generateReport(HttpServletRequest p_request) throws Exception {
    String[] months = getMonths();
    File file = ReportHelper.getXLSReportFile(getReportType(), null);
    Workbook p_workbook = new SXSSFWorkbook();
    int currentMonth = m_calendar.get(Calendar.MONTH);
    int year;
    if (p_request.getParameter("year") != null) {
        year = Integer.parseInt(p_request.getParameter("year"));
    } else {
        year = m_calendar.get(Calendar.YEAR);
    }
    if (year != m_calendar.get(Calendar.YEAR))
        currentMonth = 11;

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

    // For "Dell Review Report Issue"
    // Gets the tag that marks whether needs to separates "Dell_Review" or
    // not.
    // Default value is "false".
    boolean includeExReview = false;

    String reviewParam = p_request.getParameter("review");
    if ((reviewParam != null) && (reviewParam.length() > 0)) {
        includeExReview = java.lang.Boolean.valueOf(reviewParam).booleanValue();
    }

    // For "Add Job Id into online job report" issue
    isJobIdVisible = isJobIdVisible(p_request);
    String isReportForYear = p_request.getParameter("reportForThisYear");
    String isReportForDetail = p_request.getParameter("reportForDetail");
    // Generate Report By Year
    if (isReportForYear != null && isReportForYear.equals("on")) {
        int i = 0;
        for (i = 0; i <= currentMonth; i++) {
            // For "Dell Review Report Issue"
            // Add new parameter "includeExReview" to the signature.
            HashMap<String, HashMap<String, ProjectWorkflowData>> projectMap = getProjectDataForMonth(p_request,
                    i, recalculateFinishedWorkflow, includeExReview);

            // Cancel the report.
            if (isCancelled())
                return new File[0];

            if (projectMap.size() > 0) {
                // This sheets array has two elements.
                // sheets[MONTH_SHEET], the original monthSheet.
                // sheets[MONTH_REVIEW_SHEET], new monthly Dell_Review
                // sheet.
                Sheet[] sheets = new Sheet[2];
                IntHolder[] rows = new IntHolder[2];

                String sheetTitle = months[i] + " " + year;
                sheets[MONTH_SHEET] = p_workbook.createSheet(sheetTitle);
                if (m_data.isTradosStyle()) {
                    addTitle(p_workbook, sheets[MONTH_SHEET]);
                    addHeaderTradosStyle(p_workbook, sheets[MONTH_SHEET], MONTH_SHEET);
                } else {
                    addTitle(p_workbook, sheets[MONTH_SHEET]);
                    addHeader(p_workbook, sheets[MONTH_SHEET], MONTH_SHEET);
                }

                rows[MONTH_SHEET] = new IntHolder(4);

                if (includeExReview) {
                    String sheetReviewTitle = m_bundle.getString("lb_review") + " " + months[i] + " " + year;
                    sheets[MONTH_REVIEW_SHEET] = p_workbook.createSheet(sheetReviewTitle);
                    if (m_data.isTradosStyle()) {
                        addTitle(p_workbook, sheets[MONTH_REVIEW_SHEET]);
                        addHeaderTradosStyle(p_workbook, sheets[MONTH_REVIEW_SHEET], MONTH_REVIEW_SHEET);
                    } else {
                        addTitle(p_workbook, sheets[MONTH_REVIEW_SHEET]);
                        addHeader(p_workbook, sheets[MONTH_REVIEW_SHEET], MONTH_REVIEW_SHEET);
                    }
                    rows[MONTH_REVIEW_SHEET] = new IntHolder(4);
                }

                if (m_data.isTradosStyle()) {
                    writeProjectDataTradosStyle(projectMap, p_workbook, sheets, includeExReview, rows);
                } else {
                    writeProjectData(projectMap, p_workbook, sheets, includeExReview, rows);
                }
                wroteSomething = true;
            }
        }

        if (!wroteSomething) {
            // just write out the first sheet to avoid Excel problems
            i = 0;
            String sheetTitle = months[currentMonth] + " " + year;
            Sheet monthSheet = p_workbook.createSheet(sheetTitle);
            if (m_data.isTradosStyle()) {
                addTitle(p_workbook, monthSheet);
                addHeaderTradosStyle(p_workbook, monthSheet, MONTH_SHEET);
            } else {
                addTitle(p_workbook, monthSheet);
                addHeader(p_workbook, monthSheet, MONTH_SHEET);
            }

            if (includeExReview) {
                String sheetReviewTitle = "Review " + months[currentMonth] + " " + year;
                Sheet monthReviewSheet = p_workbook.createSheet(sheetReviewTitle);
                if (m_data.isTradosStyle()) {
                    addTitle(p_workbook, monthReviewSheet);
                    addHeaderTradosStyle(p_workbook, monthReviewSheet, MONTH_REVIEW_SHEET);
                } else {
                    addTitle(p_workbook, monthReviewSheet);
                    addHeader(p_workbook, monthReviewSheet, MONTH_REVIEW_SHEET);
                }
            }
        }

        // Create "Criteria" Sheet
        addParamsSheet(p_workbook, (String) p_request.getParameter("year"), recalculateFinishedWorkflow);

        FileOutputStream out = new FileOutputStream(file);
        p_workbook.write(out);
        out.close();
        ((SXSSFWorkbook) p_workbook).dispose();
    }
    // Generate Report by Creation Date Range.
    else if (isReportForDetail != null && isReportForDetail.endsWith("on")) {
        // For "Dell Review Report Issue"
        // Add new parameter "includeExReview" to the signature.
        HashMap<String, HashMap<String, ProjectWorkflowData>> projectMap = getProjectDataForMonth(p_request, 0,
                recalculateFinishedWorkflow, includeExReview);

        // Cancel the report.
        if (isCancelled())
            return new File[0];

        // Create sheets in Workbook.
        createSheets(p_workbook, projectMap, includeExReview);

        // Create "Criteria" Sheet
        addParamsSheet(p_workbook, (String) p_request.getParameter("year"), recalculateFinishedWorkflow);

        FileOutputStream out = new FileOutputStream(file);
        p_workbook.write(out);
        out.close();
        ((SXSSFWorkbook) p_workbook).dispose();
    }

    List<File> workBooks = new ArrayList<File>();
    workBooks.add(file);
    return ReportHelper.moveReports(workBooks, m_userId);
}

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

License:Apache License

@Override
public File[] generateReports(List<Long> p_jobIDS, List<GlobalSightLocale> p_targetLocales) throws Exception {

    List<File> workBooks = new ArrayList<File>();
    for (long jobID : p_jobIDS) {
        if (cancel)
            return new File[0];

        Job job = ServerProxy.getJobHandler().getJobById(jobID);
        if (job == null)
            continue;

        Workbook workBook = new SXSSFWorkbook();
        createReport(workBook, job, p_targetLocales, m_dateFormat);
        File file = getFile(getReportType(), job, workBook);
        FileOutputStream out = new FileOutputStream(file);
        workBook.write(out);
        out.close();/*from   w  w w .  ja  v  a 2 s .  c  o m*/
        ((SXSSFWorkbook) workBook).dispose();

        workBooks.add(file);
    }

    return ReportHelper.moveReports(workBooks, m_userId);
}

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

License:Apache License

/**
 * Create Reports for download/*from   ww  w . ja va  2 s .  c o  m*/
 * 
 * @param p_jobIDS
 *            Job ID List
 * @param p_targetLocales
 *            Target Locales List
 */
public File[] generateReports(List<Long> p_jobIDS, List<GlobalSightLocale> p_targetLocales) throws Exception {
    if (p_jobIDS == null || p_jobIDS.size() == 0) {
        p_jobIDS = m_jobIDS;
        p_targetLocales = m_targetLocales;
    } else if (m_jobIDS == null || m_jobIDS.size() == 0) {
        m_jobIDS = p_jobIDS;
    }
    List<File> workBooks = new ArrayList<File>();
    int finishedJobNum = 0;
    for (long jobID : m_jobIDS) {
        // Cancel generate reports.
        if (isCancelled())
            return null;

        if (cancel)
            return null;

        // Sets Reports Percent.
        setPercent(++finishedJobNum);

        Job job = ServerProxy.getJobHandler().getJobById(jobID);

        if (job == null)
            continue;

        if (m_userId == null) {
            m_userId = job.getCreateUserId();
        }

        setAllCellStyleNull();

        Workbook workBook = new SXSSFWorkbook();
        createReport(workBook, job, p_targetLocales, m_dateFormat);
        File file = getFile(getReportType(), job, workBook);
        FileOutputStream out = new FileOutputStream(file);
        workBook.write(out);
        out.close();
        ((SXSSFWorkbook) workBook).dispose();

        workBooks.add(file);
    }

    return ReportHelper.moveReports(workBooks, m_userId);
}

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

License:Apache License

/**
 * Generates Excel report//from  w  w w . j a v a  2  s  .c  om
 * 
 * @param p_jobIDS
 *            Job ID List
 * @param p_targetLocales
 *            Target Locales List
 * @param p_companyName
 *            Company Name
 * @throws Exception
 */
public File[] generateReports(List<Long> p_jobIDS, List<GlobalSightLocale> p_targetLocales) throws Exception {
    ArrayList<String> stateList = ReportHelper.getAllJobStatusList();
    stateList.remove(Job.PENDING);

    if (p_jobIDS == null || p_jobIDS.size() == 0) {
        p_jobIDS = m_jobIDS;
        p_targetLocales = m_targetLocales;
    } else if (m_jobIDS == null || m_jobIDS.size() == 0) {
        m_jobIDS = p_jobIDS;
    }

    List<File> workBooks = new ArrayList<File>();
    Workbook workBook = new SXSSFWorkbook();

    createReport(workBook, p_jobIDS, p_targetLocales, stateList);

    File file = getFile(reportType, null, workBook);
    FileOutputStream out = new FileOutputStream(file);
    workBook.write(out);
    out.close();
    ((SXSSFWorkbook) workBook).dispose();
    workBooks.add(file);

    return ReportHelper.moveReports(workBooks, m_userId);
}

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

License:Apache License

/**
 * Generates the Excel report as a temp file and returns the temp file.
 * /*from   w  w  w .j av a  2  s .  co  m*/
 * @return File
 * @exception Exception
 */
public File[] generateReports(ReportSearchOptions p_searchOptions) throws Exception {
    bundle = p_searchOptions.getBundle();
    moneyFormatString = ReportUtil.getCurrencySymbol(p_searchOptions.getCurrency()) + MONEY_FORMAT;
    File file = ReportHelper.getXLSReportFile(getReportType(), null);
    Workbook workbook = new SXSSFWorkbook();
    String monthlySheetName = bundle.getString("lb_monthly");
    String leveragingSheetName = bundle.getString("lb_state_leveraging");
    String costsSheetName = bundle.getString("lb_costs");
    String criteriaSheetName = bundle.getString("lb_criteria");

    // Generates Summary Word Count Data.
    Map<String, ReportWordCount> summaryWordCount = getSummaryWordCount(p_searchOptions);

    // Create Monthly Sheet
    Sheet monthlySheet = workbook.createSheet(monthlySheetName);
    createMonthlySheet(workbook, monthlySheet, p_searchOptions, summaryWordCount);

    // Create Leveraging Sheet
    Sheet leveragingSheet = workbook.createSheet(leveragingSheetName);
    createLeveragingSheet(workbook, leveragingSheet, summaryWordCount);

    // Create Costs Sheet
    Sheet costsSheet = workbook.createSheet(costsSheetName);
    createLeveragingSheet(workbook, costsSheet, summaryWordCount);
    createCostsSheet(workbook, costsSheet, p_searchOptions, summaryWordCount);
    costsSheet.setZoom(9, 10);

    // Create Criteria Sheet
    Sheet criteriaSheet = workbook.createSheet(criteriaSheetName);
    createCriteriaSheet(workbook, criteriaSheet, p_searchOptions, summaryWordCount);

    FileOutputStream out = new FileOutputStream(file);
    workbook.write(out);
    out.close();
    ((SXSSFWorkbook) workbook).dispose();

    List<File> workBooks = new ArrayList<File>();
    workBooks.add(file);
    return ReportHelper.moveReports(workBooks, p_searchOptions.getUserId());
}

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

License:Apache License

@Override
public File[] generateReports(List<Long> p_jobIDS, List<GlobalSightLocale> p_targetLocales) throws Exception {
    List<File> workBooks = new ArrayList<File>();
    for (long jobID : p_jobIDS) {
        if (cancel)
            return new File[0];

        Job job = ServerProxy.getJobHandler().getJobById(jobID);
        if (job == null)
            continue;

        Workbook workBook = new SXSSFWorkbook();
        createReport(workBook, job, p_targetLocales, m_dateFormat);
        File file = getFile(getReportType(), job, workBook);
        FileOutputStream out = new FileOutputStream(file);
        workBook.write(out);
        out.close();//from   w w w . ja  va 2  s .co  m
        ((SXSSFWorkbook) workBook).dispose();

        workBooks.add(file);
    }

    return ReportHelper.moveReports(workBooks, m_userId);
}

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

License:Apache License

public void generateReport(HttpServletRequest p_request, HttpServletResponse p_response) throws Exception {
    dateFormat = new SimpleDateFormat(p_request.getParameter(PARAM_DATE_FORMAT));
    uiLocale = (Locale) p_request.getSession().getAttribute(WebAppConstants.UILOCALE);
    bundle = PageHandler.getBundle(p_request.getSession());
    userId = (String) p_request.getSession(false).getAttribute(WebAppConstants.USER_NAME);
    String companyName = UserUtil.getCurrentCompanyName(p_request);
    if (!UserUtil.isBlank(companyName)) {
        CompanyThreadLocal.getInstance().setValue(companyName);
    }//  www . j a  va  2s  .c  o m

    Workbook p_workbook = new SXSSFWorkbook();
    Sheet sheet = p_workbook.createSheet(bundle.getString("lb_job_status"));

    // Add Title
    addTitle(p_workbook, sheet);

    // add header
    addHeader(p_workbook, sheet);

    //
    addJobs(p_workbook, sheet, 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();
}