List of usage examples for org.apache.poi.ss.usermodel Workbook createSheet
Sheet createSheet(String sheetname);
From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.ReviewerLisaQAXlsReportHelper.java
License:Apache License
/** * Create the report//from ww w . j a v a 2s. c om * * @throws Exception */ private void createReport(Workbook p_workbook, String p_dateFormat) throws Exception { // Create Sheet Sheet sheet = p_workbook.createSheet(bundle.getString("lb_icc")); // Add Title addTitle(p_workbook, sheet); // Add Locale Pair Header and Segment Header addLanguageHeader(p_workbook, sheet); addSegmentHeaderICC(p_workbook, sheet); createCategoryFailureNameArea(p_workbook); // Insert Data into Report writeLanguageInfo(p_workbook, sheet); writeSegmentInfoICC(p_workbook, sheet, p_dateFormat); }
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. * // w w w. j ava2 s . co m * @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. * /*from w ww .j a v a 2 s . co 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
/** * Gets the jobs and outputs tasks information. * //w w w . j a va 2 s . c o m * @exception Exception */ private void addJobs(Workbook p_workbook, HttpServletRequest p_request, HttpServletResponse p_response) throws Exception { bundle = PageHandler.getBundle(p_request.getSession()); // print out the request parameters String[] paramJobId = p_request.getParameterValues(JOB_ID); String[] paramTargetLocales = p_request.getParameterValues(TARGET_LOCALES); String[] paramSourceLocales = p_request.getParameterValues(SOURCE_LOCALES); Sheet sheet = p_workbook.createSheet(bundle.getString("lb_lisa_qa")); addTitle(p_workbook, sheet); addLanguageHeader(p_workbook, sheet); addSegmentHeader(p_workbook, sheet); Locale uiLocale = (Locale) p_request.getSession().getAttribute(WebAppConstants.UILOCALE); String srcLang = m_sourceLocale.getDisplayName(uiLocale); String trgLang = m_targetLocale.getDisplayName(uiLocale); writeLanguageInfo(p_workbook, sheet, srcLang, trgLang); // get jobs ArrayList<Job> jobs = new ArrayList<Job>(); if (paramJobId != null && "*".equals(paramJobId[0])) { JobSearchParameters searchParams = getSearchParams(p_request); jobs.addAll(ServerProxy.getJobHandler().getJobs(searchParams)); } else { for (int i = 0; i < paramJobId.length; i++) { if ("*".equals(paramJobId[i]) == false) { long jobId = Long.parseLong(paramJobId[i]); Job j = ServerProxy.getJobHandler().getJobById(jobId); jobs.add(j); } } } m_jobIDS = ReportHelper.getJobIDS(jobs); // Cancel Duplicate Request if (ReportHelper.checkReportsDataInProgressStatus(userId, m_jobIDS, getReportType())) { p_workbook = null; p_response.sendError(HttpServletResponse.SC_NO_CONTENT); return; } // Set ReportsData. ReportHelper.setReportsData(userId, m_jobIDS, getReportType(), 0, ReportsData.STATUS_INPROGRESS); // Separate jobs by Division Hashtable<String, List<Job>> projects = new Hashtable<String, List<Job>>(); String tLocale = paramTargetLocales[0]; for (Job job : jobs) { if (isCancelled()) { return; } boolean containTarLocale = false; for (Workflow wf : job.getWorkflows()) { String wfLocale = Long.toString(wf.getTargetLocale().getId()); if (wfLocale.equals(tLocale)) { containTarLocale = true; break; } } if (!containTarLocale) { continue; } String projectName = job.getL10nProfile().getProject().getName(); List<Job> jobList = null; if (projects.containsKey(projectName)) { jobList = projects.get(projectName); } else { jobList = new ArrayList<Job>(); projects.put(projectName, jobList); } jobList.add(job); } // add jobs into sheet IntHolder row = new IntHolder(7); for (Enumeration<String> e = projects.keys(); e.hasMoreElements();) { String projectName = (String) e.nextElement(); Cell cell_A_ProjectName = getCell(getRow(sheet, row.value), 0); cell_A_ProjectName.setCellValue(projectName); cell_A_ProjectName.setCellStyle(getContentStyle(p_workbook)); List<Job> jobList = projects.get(projectName); for (Job job : jobList) { if (isCancelled()) { p_workbook = null; return; } addJobPages(p_workbook, sheet, job, row, paramSourceLocales, paramTargetLocales); } } // Set ReportsData. ReportHelper.setReportsData(userId, m_jobIDS, getReportType(), 100, ReportsData.STATUS_FINISHED); }
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. * //from ww w . ja v a 2 s .c om * @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.griffinslogistics.document.excel.BDLGenerator.java
private static void generate(Workbook workbook, List<BookBoxModel> bookBoxModels, Pulsiodetails pulsiodetails, String packageNumber) {/*from w w w.ja va 2s .c o m*/ Map<String, CellStyle> styles = createStyles(workbook); Sheet sheet = workbook.createSheet(packageNumber); // 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); // Default sheet styles sheet.setDisplayGridlines(false); sheet.setPrintGridlines(false); sheet.autoSizeColumn(1, true); sheet.autoSizeColumn(2, false); sheet.autoSizeColumn(5, false); sheet.autoSizeColumn(6, false); sheet.autoSizeColumn(7, false); sheet.autoSizeColumn(8, false); sheet.setFitToPage(true); }
From source file:com.griffinslogistics.excel.BDLGenerator.java
public static void generateAll(OutputStream outputStream, Map<String, List<BookBoxModel>> bookBoxModelsForTransportation, Pulsiodetails pulsioDetails, String packageNumber) {// ww w.j av a2s . 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 ww . j av a 2 s . co 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; }
From source file:com.gtwm.pb.servlets.ReportDownloader.java
License:Open Source License
/** * Return the session report as an Excel file * //from www .ja va 2 s . c om * @param sessionData * @return */ private ByteArrayOutputStream getSessionReportAsExcel(CompanyInfo company, AppUserInfo user, SessionDataInfo sessionData) throws AgileBaseException, IOException, SQLException { BaseReportInfo report = sessionData.getReport(); if (report == null) { throw new ObjectNotFoundException("No report found in the session"); } // create Excel spreadsheet Workbook workbook = new SXSSFWorkbook(); // the pane 2 report String reportName = report.getReportName(); // Replace any invalid characters : \ / ? * [ or ] // http://support.microsoft.com/kb/215205 reportName = reportName.replaceAll("[\\/\\:\\\\\\?\\*\\[\\]]", "-"); Sheet reportSheet; try { reportSheet = workbook.createSheet(reportName); } catch (IllegalArgumentException iaex) { reportSheet = workbook.createSheet(reportName + " " + report.getInternalReportName()); } int rowNum = 0; // header CellStyle boldCellStyle = workbook.createCellStyle(); Font font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); boldCellStyle.setFont(font); Row row = reportSheet.createRow(rowNum); int columnNum = 0; Set<ReportFieldInfo> reportFields = report.getReportFields(); for (ReportFieldInfo reportField : reportFields) { Cell cell = row.createCell(columnNum); cell.setCellValue(reportField.getFieldName()); cell.setCellStyle(boldCellStyle); BaseField field = reportField.getBaseField(); if (field.equals(field.getTableContainingField().getPrimaryKey())) { reportSheet.setColumnHidden(columnNum, true); } columnNum++; } // data rowNum++; DataManagementInfo dataManagement = this.databaseDefn.getDataManagement(); List<DataRowInfo> reportDataRows = dataManagement.getReportDataRows(company, report, sessionData.getReportFilterValues(), false, sessionData.getReportSorts(), -1, QuickFilterType.AND, false); String fieldValue = ""; boolean defaultReport = (report.equals(report.getParentTable().getDefaultReport())); for (DataRowInfo dataRow : reportDataRows) { Map<BaseField, DataRowFieldInfo> dataRowFieldMap = dataRow.getDataRowFields(); row = reportSheet.createRow(rowNum); columnNum = 0; for (ReportFieldInfo reportField : reportFields) { BaseField field = reportField.getBaseField(); if (field instanceof TextField) { fieldValue = dataRowFieldMap.get(field).getKeyValue(); } else { fieldValue = dataRowFieldMap.get(field).getDisplayValue(); } if (!fieldValue.equals("")) { Cell cell; DatabaseFieldType dbFieldType = field.getDbType(); if ((defaultReport) && (field instanceof RelationField)) { dbFieldType = ((RelationField) field).getDisplayField().getDbType(); } switch (dbFieldType) { case FLOAT: cell = row.createCell(columnNum, Cell.CELL_TYPE_NUMERIC); try { cell.setCellValue(Double.valueOf(fieldValue.replace(",", ""))); } catch (NumberFormatException nfex) { // Fall back to a string representation cell = row.createCell(columnNum, Cell.CELL_TYPE_STRING); cell.setCellValue(fieldValue); } break; case INTEGER: case SERIAL: cell = row.createCell(columnNum, Cell.CELL_TYPE_NUMERIC); try { cell.setCellValue(Integer.valueOf(fieldValue.replace(",", ""))); } catch (NumberFormatException nfex) { logger.debug(nfex.toString() + ": value " + fieldValue.replace(",", "")); // Fall back to a string representation cell = row.createCell(columnNum, Cell.CELL_TYPE_STRING); cell.setCellValue(fieldValue); logger.debug("Successfully set string instead"); } break; case VARCHAR: default: cell = row.createCell(columnNum, Cell.CELL_TYPE_STRING); cell.setCellValue(Helpers.unencodeHtml(fieldValue)); break; } } columnNum++; } rowNum++; } // Export info worksheet addReportMetaDataWorksheet(company, user, sessionData, report, workbook); // one worksheet for each of the report summaries for (ChartInfo savedChart : report.getSavedCharts()) { this.addSummaryWorksheet(company, sessionData, savedChart, workbook); } // the default summary ChartInfo reportSummary = report.getChart(); Set<ChartAggregateInfo> aggregateFunctions = reportSummary.getAggregateFunctions(); Set<ChartGroupingInfo> groupings = reportSummary.getGroupings(); if ((groupings.size() > 0) || (aggregateFunctions.size() > 0)) { this.addSummaryWorksheet(company, sessionData, reportSummary, workbook); } // write to output ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); workbook.write(outputStream); return outputStream; }
From source file:com.gtwm.pb.servlets.ReportDownloader.java
License:Open Source License
/** * Add a sheet with export information to the workbook *///w w w. ja v a2s. c o m private static void addReportMetaDataWorksheet(CompanyInfo company, AppUserInfo user, SessionDataInfo sessionData, BaseReportInfo report, Workbook workbook) { String title = "Export information"; Sheet infoSheet; try { infoSheet = workbook.createSheet(title); } catch (IllegalArgumentException iaex) { // Just in case there happens to be a report called 'Export // information'. // The sheet name must be unique infoSheet = workbook.createSheet(title + " " + report.getInternalReportName()); } Row row = infoSheet.createRow(0); Cell cell = row.createCell(1); cell.setCellValue("Export from www.agilebase.co.uk"); row = infoSheet.createRow(2); cell = row.createCell(0); cell.setCellValue("Company"); cell = row.createCell(1); cell.setCellValue(company.getCompanyName()); row = infoSheet.createRow(3); cell = row.createCell(0); cell.setCellValue("Module"); cell = row.createCell(1); ModuleInfo module = report.getModule(); if (module != null) { cell.setCellValue(report.getModule().getModuleName()); } else { cell.setCellValue(""); } row = infoSheet.createRow(4); cell = row.createCell(0); cell.setCellValue("Report"); cell = row.createCell(1); cell.setCellValue(report.getReportName()); row = infoSheet.createRow(5); cell = row.createCell(0); cell.setCellValue("Exported by"); cell = row.createCell(1); cell.setCellValue(user.getForename() + " " + user.getSurname()); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Date date = new Date(); String now = dateFormat.format(date); row = infoSheet.createRow(6); cell = row.createCell(0); cell.setCellValue("Export time"); cell = row.createCell(1); cell.setCellValue(now); }