=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java 2009-10-21 06:52:27 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java 2009-11-09 06:59:22 +0000 @@ -40,7 +40,10 @@ import jxl.format.Colour; import jxl.format.Pattern; +import org.apache.poi.hssf.usermodel.HSSFCellStyle; +import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.hisp.dhis.reportexcel.utils.ExcelUtils; /** * Simple demo class which uses the api to present the contents of an excel 97 @@ -89,7 +92,7 @@ private static final String MERGEDCELL_CLOSETAG = ""; private static final String PRINT_END_LINE = "\n"; - + public static final String NUMBER_OF_ZERO = "0"; // ------------------------------------------------ @@ -214,8 +217,18 @@ { FileInputStream fis = new FileInputStream( this.PATH_FILE_NAME ); org.apache.poi.ss.usermodel.Workbook wb = new HSSFWorkbook( fis ); - org.apache.poi.ss.usermodel.FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + if ( sheetId > 0 ) { + + this.recalculatedValueForCellFormula( wb, sheetId ); + } + else { + for ( int sheet = 0; sheet < WORKBOOK.getNumberOfSheets(); sheet++ ) + { + this.recalculatedValueForCellFormula( wb, sheetId -1); + } + } + if ( bWriteDescription ) { this.writeXMLDescription( sheetId ); @@ -239,13 +252,13 @@ if ( sheetId > 0 ) { - writeBySheetNo( wb, (sheetId - 1), evaluator, bDetailed ); + writeBySheetNo( wb, (sheetId - 1), bDetailed ); } else { for ( int sheet = 0; sheet < WORKBOOK.getNumberOfSheets(); sheet++ ) { - writeBySheetNo( wb, sheet, evaluator, bDetailed ); + writeBySheetNo( wb, sheet, bDetailed ); } } @@ -256,12 +269,10 @@ // ------------------------------------------------------------------------- // Sub-methods // ------------------------------------------------------------------------- - - private void writeBySheetNo( org.apache.poi.ss.usermodel.Workbook wb, int sheetNo, - org.apache.poi.ss.usermodel.FormulaEvaluator evaluator, boolean bDetailed ) + + private void writeBySheetNo( org.apache.poi.ss.usermodel.Workbook wb, int sheetNo, boolean bDetailed ) { Sheet s = WORKBOOK.getSheet( sheetNo ); - org.apache.poi.ss.usermodel.Sheet sheetPOI = wb.getSheetAt( sheetNo ); STRUCTURE_DATA_RESPONSE.append( " " ); STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE ); @@ -271,9 +282,6 @@ Cell[] cell = null; CellFormat format = null; - boolean bFormula = false; - double recalculatedValue = 0; - for ( int i = 0; i < s.getRows(); i++ ) { STRUCTURE_DATA_RESPONSE.append( " " ); @@ -287,57 +295,22 @@ // information if ( (cell[j].getType() != CellType.EMPTY) || (cell[j].getCellFormat() != null) ) { - bFormula = false; - - // check the cell formula - if ( cell[j].getType() == CellType.NUMBER_FORMULA || cell[j].getType() == CellType.STRING_FORMULA - || cell[j].getType() == CellType.BOOLEAN_FORMULA || cell[j].getType() == CellType.DATE_FORMULA - || cell[j].getType() == CellType.FORMULA_ERROR ) - { - bFormula = true; - recalculatedValue = 0; - - // suppose your formula is in Cell - org.apache.poi.ss.util.CellReference cellReference = new org.apache.poi.ss.util.CellReference( - cell[j].getRow(), cell[j].getColumn() ); - org.apache.poi.ss.usermodel.Row rowPOI = sheetPOI.getRow( cellReference.getRow() ); - org.apache.poi.ss.usermodel.Cell cellPOI = rowPOI.getCell( cellReference.getCol() ); - - if ( cellPOI != null ) - { - switch ( evaluator.evaluateFormulaCell( cellPOI ) ) - { - case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC: - recalculatedValue = cellPOI.getNumericCellValue(); - break; - - // CELL_TYPE_FORMULA will never occur - case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA: - break; - } - } - } - + // end of checking the cell formula STRUCTURE_DATA_RESPONSE.append( " " ); STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE ); STRUCTURE_DATA_RESPONSE.append( " " ); - // print data in cell - if ( bFormula ) + if ( cell[j].getContents().equals( NUMBER_OF_ZERO ) ) { - STRUCTURE_DATA_RESPONSE.append( "" ); + + STRUCTURE_DATA_RESPONSE.append( "" ); } else { - if ( cell[j].getContents().equals( NUMBER_OF_ZERO ) ) { - - STRUCTURE_DATA_RESPONSE.append( "" ); - } - else { - STRUCTURE_DATA_RESPONSE.append( "" ); - } + STRUCTURE_DATA_RESPONSE.append( "" ); } + // } STRUCTURE_DATA_RESPONSE.append( "" ); STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE ); @@ -490,4 +463,62 @@ } } + private void recalculatedValueForCellFormula( org.apache.poi.ss.usermodel.Workbook wb, int sheetNo ) + { + + Cell[] cell = null; + Sheet s = WORKBOOK.getSheet( sheetNo ); + + org.apache.poi.ss.usermodel.Sheet sheet = wb.getSheetAt( sheetNo ); + org.apache.poi.ss.usermodel.FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + + String recalculatedValue = "0"; + + for ( int i = 0; i < s.getRows(); i++ ) + { + STRUCTURE_DATA_RESPONSE.append( " " ); + STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE ); + + cell = s.getRow( i ); + + for ( int j = 0; j < cell.length; j++ ) + { + + if ( cell[j].getType() == CellType.NUMBER_FORMULA || cell[j].getType() == CellType.STRING_FORMULA + || cell[j].getType() == CellType.BOOLEAN_FORMULA || cell[j].getType() == CellType.DATE_FORMULA + || cell[j].getType() == CellType.FORMULA_ERROR ) + { + + // suppose your formula is in Cell + org.apache.poi.ss.util.CellReference cellReference = new org.apache.poi.ss.util.CellReference( + cell[j].getRow(), cell[j].getColumn() ); + org.apache.poi.ss.usermodel.Row rowPOI = sheet.getRow( cellReference.getRow() ); + org.apache.poi.ss.usermodel.Cell cellPOI = rowPOI.getCell( cellReference.getCol() ); + + if ( cellPOI != null ) + { + switch ( evaluator.evaluateFormulaCell( cellPOI ) ) + { + case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC: + + recalculatedValue = String.valueOf( cellPOI.getNumericCellValue() ); + + if ( new Integer(recalculatedValue.split( "\\." )[1]) == 0 ) { + + recalculatedValue = recalculatedValue.split( "\\." )[0]; + } + + ExcelUtils.writeValueByPOI( i, j, recalculatedValue, ExcelUtils.NUMBER, (HSSFSheet)sheet, (HSSFCellStyle)wb.createCellStyle() ); + break; + + // CELL_TYPE_FORMULA will never occur + case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA: + break; + } + } + } + } + } + } + } === modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties 2009-11-09 05:52:46 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties 2009-11-09 06:59:22 +0000 @@ -154,3 +154,5 @@ associations = Associations sheetNo = Sheet choose_excelItem = Please choose excel items +copy_items_duplicated = Warning! Cannot copy the duplicated items +copy_successful = Copy successful ! === modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties 2009-11-09 05:52:46 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties 2009-11-09 06:59:22 +0000 @@ -163,7 +163,11 @@ generate_advanced_report = B\u00e1o c\u00e1o theo nh\u00f3m \u0111\u01a1n v\u1ecb report_ready_exist = B\u00e1o c\u00e1o n\u00e0y \u0111\u00e3 t\u1ed3n t\u1ea1i upload_file_first = Upload t\u1eadp tin tr\u01b0\u1edbc ! +choose_excelItem = Xin ch\u1ecdn c\u00e1c gi\u00e1 tr\u1ecb c\u1ea7n import please_enter_sheet_no = Vui l\u00f2ng nh\u1eadp sheet no please_enter_group_name = Vui l\u00f2ng nh\u1eadp t\u00ean nh\u00f3m upload_file_first = Upload t\u1eadp tin tr\u01b0\u1edbc ! choose_excelItem = Xin ch\u1ecdn c\u00e1c gi\u00e1 tr\u1ecb c\u1ea7n import +copy_items_duplicated = ReportItem b\u1ecb tr\u00f9ng l\u1eb7p, kh\u00f4ng th\u1ec3 sao ch\u00e9p ! +copy_successful = Sao ch\u00e9p th\u00e0nh c\u00f4ng ! + === modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/reportItem.js' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/reportItem.js 2009-11-09 05:52:46 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/reportItem.js 2009-11-09 06:59:22 +0000 @@ -156,7 +156,7 @@ /* * COPY REPORT ITEM */ -function copySelectedItem(){ +function copySelectedItem() { $.post("getAllReportExcels.action",{}, function (xmlObject){ xmlObject = xmlObject.getElementsByTagName('reports')[0]; @@ -173,21 +173,112 @@ },'xml'); } -function saveCopyItems(){ - var reportItems = new Array(); - var listRadio = document.getElementsByName('reportItemCheck'); - for(var i=0;i= 0 ) + { + reportItems.push( reportItemsChecked[i].split("#")[0] ); + } + } +} + +function saveCopyItems() { + + if (reportItemsDuplicated.length > 0) { + + var reportItemsDuplicatedList = "Sheet [" + + "]" +i18n_copy_items_duplicated + "
    "; + + for (var i in reportItemsDuplicated) { + + reportItemsDuplicatedList = reportItemsDuplicatedList + + "
  • " + + reportItemsDuplicated[i] + + "

  • "; + } + + reportItemsDuplicatedList = reportItemsDuplicatedList + "
" + + setMessage(reportItemsDuplicatedList); + $("#copyTo").hide(); - },'xml'); + } + else { + $.post("copyReportExcelItems.action", + { + reportId:$("#targetReport").val(), + sheetNo:sheetId, + reportItems:reportItems + }, + function (data) + { + setMessage( i18n_copy_successful ); + $("#copyTo").hide(); + },'xml'); + } + } /** === modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reportItems.vm' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reportItems.vm 2009-10-22 05:37:47 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reportItems.vm 2009-11-09 06:59:22 +0000 @@ -31,7 +31,7 @@ #set( $mark = false ) #foreach($reportItem in $reportItems) - + $encoder.htmlEncode( $reportItem.name ) $i18n.getString( $reportItem.itemType ) $i18n.getString( $reportItem.periodType ) @@ -308,7 +308,12 @@

- +

+ +