@Override protected void executeGenerateOutputFile(ExportReport exportReport) throws Exception { OrganisationUnitGroup organisationUnitGroup = organisationUnitGroupService.getOrganisationUnitGroup(organisationGroupId); Set<OrganisationUnit> organisationList = organisationUnitGroup.getMembers(); ExportReportNormal exportReportInstance = (ExportReportNormal) exportReport; Collection<ExportItem> exportItems = exportReportInstance.getExportItems(); this.installReadTemplateFile(exportReportInstance, organisationUnitGroup); for (ExportItem exportItem : exportItems) { double value = 0; Iterator<OrganisationUnit> iter = organisationList.iterator(); while (iter.hasNext()) { OrganisationUnit organisationUnit = iter.next(); value += getDataValue(exportItem, organisationUnit); } Sheet sheet = this.templateWorkbook.getSheetAt(exportItem.getSheetNo() - 1); ExcelUtils.writeValueByPOI( exportItem.getRow(), exportItem.getColumn(), String.valueOf(value), ExcelUtils.NUMBER, sheet, this.csNumber); } for (Integer sheetNo : exportReportService.getSheets(selectionManager.getSelectedReportId())) { Sheet sheet = this.templateWorkbook.getSheetAt(sheetNo - 1); this.recalculatingFormula(sheet); } }
private void generateOutPutFile( Set<PeriodColumn> periodColumns, Collection<ExportItem> exportReportItems, OrganisationUnit organisationUnit, Sheet sheet) { for (ExportItem reportItem : exportReportItems) { for (PeriodColumn p : periodColumns) { if (p.getPeriodType().equals(reportItem.getPeriodType())) { double value = 0.0; if (reportItem.getItemType().equalsIgnoreCase(ExportItem.TYPE.DATAELEMENT)) { // value = this.getDataValue( reportItem, organisationUnit ); value = MathUtils.calculateExpression( ExpressionUtils.generateExpression( reportItem, p.getStartdate(), p.getEnddate(), organisationUnit, dataElementService, categoryService, aggregationService)); } else if (reportItem .getItemType() .equalsIgnoreCase(ExportItem.TYPE.DATAELEMENT_VALUETYPE_TEXT)) { String result = this.getTextValue(reportItem, organisationUnit, p.getStartdate(), p.getEnddate()); ExcelUtils.writeValueByPOI( reportItem.getRow(), reportItem.getColumn(), result, ExcelUtils.TEXT, sheet, this.csText); } else if (reportItem.getItemType().equalsIgnoreCase(ExportItem.TYPE.INDICATOR)) { // value = this.getIndicatorValue( reportItem, organisationUnit ); value = MathUtils.calculateExpression( ExpressionUtils.generateIndicatorExpression( reportItem, p.getStartdate(), p.getEnddate(), organisationUnit, indicatorService, aggregationService)); } ExcelUtils.writeValueByPOI( reportItem.getRow(), p.getColumn(), String.valueOf(value), ExcelUtils.NUMBER, sheet, this.csNumber); } } } }