← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1234: Improved/Upgrade the ultilities while generating excel file:

 

------------------------------------------------------------
revno: 1234
committer: hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2009-12-17 09:15:50 +0700
message:
  Improved/Upgrade the ultilities while generating excel file:
  - Allowing to write data following the customized format of the template excel file.
  - Unprinting out ZERO value in excel file.
modified:
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportSupport.java
  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/utils/ExcelUtils.java
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/StringUtils.java
  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_vi_VN.properties
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/preview.js
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reportparams.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportSupport.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportSupport.java	2009-12-15 09:02:24 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/export/action/GenerateReportSupport.java	2009-12-17 02:15:50 +0000
@@ -362,7 +362,7 @@
         initPOIStylesManager.initCellStyle( csTextICDJustify, csFont, this.CELLSTYLE_BORDER,
             this.CELLSTYLE_BORDER_COLOR, this.CELLSTYLE_BORDER, this.CELLSTYLE_BORDER_COLOR, this.CELLSTYLE_BORDER,
             this.CELLSTYLE_BORDER_COLOR, this.CELLSTYLE_BORDER, this.CELLSTYLE_BORDER_COLOR,
-            this.CELLSTYLE_ALIGN_JUSTIFY, false );
+            this.CELLSTYLE_ALIGN_JUSTIFY, true );
         initPOIStylesManager.initCellStyle( csText12BoldCenter, csFont12BoldCenter, this.CELLSTYLE_BORDER,
             this.CELLSTYLE_BORDER_COLOR, this.CELLSTYLE_BORDER, this.CELLSTYLE_BORDER_COLOR, this.CELLSTYLE_BORDER,
             this.CELLSTYLE_BORDER_COLOR, this.CELLSTYLE_BORDER, this.CELLSTYLE_BORDER_COLOR, this.CELLSTYLE_ALIGN_CENTER, true );

=== 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-12-15 09:02:24 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java	2009-12-17 02:15:50 +0000
@@ -307,9 +307,17 @@
 
                             break;
 
+                        // CELL_TYPE_STRING will occur if the formula return a
+                        // string value
+                        case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING:
+
+                            recalculatedValue = cellRef.getRichStringCellValue().getString();
+
+                            break;
+
                         // CELL_TYPE_FORMULA will never occur
                         case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA:
-                            System.out.println( "Place of cell :: [" + cellRef.getRowIndex() + "]["
+                            System.out.println( "Formula into cell :: [" + cellRef.getRowIndex() + "]["
                                 + cellRef.getColumnIndex() + "]" );
                             break;
 

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java	2009-11-18 05:27:27 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java	2009-12-17 02:15:50 +0000
@@ -57,8 +57,27 @@
 
     public static final String NUMBER = "NUMBER";
 
+    public static final String ZERO = "0.0";
+
     private final static Integer NUMBER_OF_LETTER = new Integer( 26 );
 
+    // -------------------------------------------------------------------------
+    //
+    // -------------------------------------------------------------------------
+
+    /* JXL - Get the specified cell */
+    public static Cell getCell( int row, int column, Sheet sheet )
+    {
+        return sheet.getCell( column - 1, row - 1 );
+    }
+
+    /* JXL - Read the value of specified cell */
+    public static String readValue( int row, int column, Sheet sheet )
+    {
+        return sheet.getCell( column - 1, row - 1 ).getContents();
+    }
+
+    /* JXL - Write the value with customize format */
     public static void writeValue( int row, int column, String value, String type, WritableSheet sheet,
         WritableCellFormat format )
         throws RowsExceededException, WriteException
@@ -84,9 +103,204 @@
         }
     }
 
-    public static Cell getValue( int row, int column, Sheet sheet )
-    {
-        return sheet.getCell( column - 1, row - 1 );
+    /* JXL - Write formula with customize format */
+    public static void writeFormula( int row, int column, String formula, WritableSheet sheet, WritableCellFormat format )
+        throws RowsExceededException, WriteException
+    {
+        if ( row > 0 && column > 0 )
+        {
+            sheet.addCell( new Formula( column - 1, row - 1, formula, format ) );
+        }
+    }
+
+    /* POI - Get the specified cell */
+    public static HSSFCell getCellByPOI( int row, int column, HSSFSheet sheet )
+    {
+        return sheet.getRow( row - 1 ).getCell( column - 1 );
+    }
+
+    /* POI - Read the value of specified cell */
+    public static String readValuePOI( int row, int column, HSSFSheet sheet )
+    {
+        HSSFCell cellPOI = getCellByPOI( row - 1, column - 1, sheet );
+
+        String value = "";
+
+        if ( cellPOI != null )
+        {
+            switch ( cellPOI.getCellType() )
+            {
+            case HSSFCell.CELL_TYPE_STRING:
+                value = cellPOI.getRichStringCellValue().toString();
+                break;
+
+            case HSSFCell.CELL_TYPE_BOOLEAN:
+                value = String.valueOf( cellPOI.getBooleanCellValue() );
+                break;
+
+            case HSSFCell.CELL_TYPE_ERROR:
+                value = String.valueOf( cellPOI.getErrorCellValue() );
+                break;
+
+            case HSSFCell.CELL_TYPE_FORMULA:
+                value = cellPOI.getCellFormula();
+                break;
+
+            case HSSFCell.CELL_TYPE_NUMERIC:
+                value = String.valueOf( cellPOI.getNumericCellValue() );
+                break;
+
+            default:
+                value = cellPOI.getStringCellValue();
+                break;
+            }
+        }
+
+        return value;
+
+    }
+
+    /* POI - Write value without CellStyle */
+    public static void writeValueByPOI( int row, int column, String value, String type, HSSFSheet sheet )
+    {
+        if ( row > 0 && column > 0 )
+        {
+
+            HSSFRow rowPOI = sheet.getRow( row - 1 );
+            HSSFCellStyle cellStylePOI = sheet.getColumnStyle( column - 1 );
+
+            if ( rowPOI == null )
+            {
+                rowPOI = sheet.createRow( row - 1 );
+            }
+
+            HSSFCell cellPOI = rowPOI.getCell( column - 1 );
+
+            if ( cellPOI == null )
+            {
+                cellPOI = rowPOI.createCell( column - 1 );
+            }
+            else
+            {
+                cellStylePOI = cellPOI.getCellStyle();
+            }
+
+            cellPOI.setCellStyle( cellStylePOI );
+
+            if ( type.equalsIgnoreCase( ExcelUtils.TEXT ) )
+            {
+                cellPOI.setCellValue( new HSSFRichTextString( value ) );
+            }
+            else if ( type.equalsIgnoreCase( ExcelUtils.NUMBER ) )
+            {
+                if ( value.equals( ZERO ) )
+                {
+                    cellPOI.setCellType( HSSFCell.CELL_TYPE_BLANK );
+                }
+                else if ( Double.isNaN( Double.valueOf( value ) ) )
+                {
+                    cellPOI.setCellErrorValue( (byte) HSSFErrorConstants.ERROR_NA );
+                }
+                else if ( Double.isInfinite( Double.valueOf( value ) ) )
+                {
+                    cellPOI.setCellErrorValue( (byte) HSSFErrorConstants.ERROR_NUM );
+                }
+                else
+                {
+                    cellPOI.setCellValue( Double.parseDouble( value ) );
+                }
+            }
+        }
+    }
+
+    /* POI - Write value with customized CellStyle */
+    public static void writeValueByPOI( int row, int column, String value, String type, HSSFSheet sheet,
+        HSSFCellStyle cellStyle )
+    {
+        if ( row > 0 && column > 0 )
+        {
+            HSSFRow rowPOI = sheet.getRow( row - 1 );
+
+            if ( rowPOI == null )
+            {
+                rowPOI = sheet.createRow( row - 1 );
+            }
+
+            HSSFCell cellPOI = rowPOI.createCell( column - 1 );
+
+            cellPOI.setCellStyle( cellStyle );
+
+            if ( type.equalsIgnoreCase( ExcelUtils.TEXT ) )
+            {
+                cellPOI.setCellValue( new HSSFRichTextString( value ) );
+            }
+            else if ( type.equalsIgnoreCase( ExcelUtils.NUMBER ) )
+            {
+                if ( value.equals( ZERO ) )
+                {
+                    cellPOI.setCellType( HSSFCell.CELL_TYPE_BLANK );
+                }
+                else if ( Double.isNaN( Double.valueOf( value ) ) )
+                {
+                    cellPOI.setCellErrorValue( (byte) HSSFErrorConstants.ERROR_NA );
+                }
+                else if ( Double.isInfinite( Double.valueOf( value ) ) )
+                {
+                    cellPOI.setCellErrorValue( (byte) HSSFErrorConstants.ERROR_NUM );
+                }
+                else
+                {
+                    cellPOI.setCellValue( Double.parseDouble( value ) );
+                }
+            }
+        }
+    }
+
+    /* POI - Write formula without CellStyle */
+    public static void writeFormulaByPOI( int row, int column, String formula, HSSFSheet sheet )
+    {
+        if ( row > 0 && column > 0 )
+        {
+            HSSFRow rowPOI = sheet.getRow( row - 1 );
+            HSSFCellStyle cellStylePOI = sheet.getColumnStyle( column - 1 );
+
+            if ( rowPOI == null )
+            {
+                rowPOI = sheet.createRow( row - 1 );
+            }
+
+            HSSFCell cellPOI = rowPOI.getCell( column - 1 );
+
+            if ( cellPOI == null )
+            {
+                cellPOI = rowPOI.createCell( column - 1 );
+            }
+            else
+            {
+                cellStylePOI = cellPOI.getCellStyle();
+            }
+
+            cellPOI.setCellStyle( cellStylePOI );
+            cellPOI.setCellFormula( formula );
+        }
+    }
+
+    /* POI - Write formula with customize CellStyle */
+    public static void writeFormulaByPOI( int row, int column, String formula, HSSFSheet sheet, HSSFCellStyle cellStyle )
+    {
+        if ( row > 0 && column > 0 )
+        {
+            HSSFRow rowPOI = sheet.getRow( row - 1 );
+
+            if ( rowPOI == null )
+            {
+                rowPOI = sheet.createRow( row - 1 );
+            }
+
+            HSSFCell cellPOI = rowPOI.createCell( column - 1 );
+            cellPOI.setCellStyle( cellStyle );
+            cellPOI.setCellFormula( formula );
+        }
     }
 
     public static String convertColNumberToColName( int column )
@@ -109,81 +323,6 @@
         return ConvertToLetter;
     }
 
-    public static void writeFormula( int row, int column, String formula, WritableSheet sheet, WritableCellFormat format )
-        throws RowsExceededException, WriteException
-    {
-        if ( row > 0 && column > 0 )
-        {
-            sheet.addCell( new Formula( column - 1, row - 1, formula, format ) );
-        }
-    }
-
-//    public static String readValue( int row, int column, Sheet sheet )
-//    {
-//        Cell cell = sheet.getCell( column - 1, row - 1 );
-//        return cell.getContents();
-//    }
-
-    /* POI methods */
-    public static void writeValueByPOI( int row, int column, String value, String type, HSSFSheet sheet,
-        HSSFCellStyle cellStyle )
-    {
-        if ( row > 0 && column > 0 )
-        {
-            HSSFRow rowPOI = sheet.getRow( row - 1 );
-
-            if ( rowPOI == null )
-            {
-                rowPOI = sheet.createRow( row - 1 );
-            }
-
-            HSSFCell cellPOI = rowPOI.createCell( column - 1 );
-            cellPOI.setCellStyle( cellStyle );
-
-            if ( type.equalsIgnoreCase( ExcelUtils.TEXT ) )
-            {
-                cellPOI.setCellValue( new HSSFRichTextString( value ) );
-            }
-            else if ( type.equalsIgnoreCase( ExcelUtils.NUMBER ) )
-            {
-                if ( Double.isNaN( Double.valueOf( value ) ) )
-                {
-                    cellPOI.setCellErrorValue( (byte) HSSFErrorConstants.ERROR_NA );
-                }
-                else if ( Double.isInfinite( Double.valueOf( value ) ) )
-                {
-                    cellPOI.setCellErrorValue( (byte) HSSFErrorConstants.ERROR_NUM );
-                }
-                else
-                {
-                    cellPOI.setCellValue( Double.parseDouble( value ) );
-                }
-            }
-        }
-    }
-
-    public static HSSFCell getValueByPOI( int row, int column, HSSFSheet sheet )
-    {
-        return sheet.getRow( row - 1 ).getCell( column - 1 );
-    }
-
-    public static void writeFormulaByPOI( int row, int column, String formula, HSSFSheet sheet, HSSFCellStyle cellStyle )
-    {
-        if ( row > 0 && column > 0 )
-        {
-            HSSFRow rowPOI = sheet.getRow( row - 1 );
-
-            if ( rowPOI == null )
-            {
-                rowPOI = sheet.createRow( row - 1 );
-            }
-
-            HSSFCell cellPOI = rowPOI.createCell( column - 1 );
-            cellPOI.setCellStyle( cellStyle );
-            cellPOI.setCellFormula( formula );
-        }
-    }
-
     public static int convertExcelColumnNameToNumber( String columnName )
     {
         try
@@ -208,8 +347,4 @@
         }
     }
 
-    public static String readValuePOI( int row, int column, HSSFSheet sheet )
-    {
-        return String.valueOf( sheet.getRow( row - 1 ).getCell( column - 1 ).getNumericCellValue() );
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/StringUtils.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/StringUtils.java	2009-12-15 09:02:24 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/StringUtils.java	2009-12-17 02:15:50 +0000
@@ -69,7 +69,7 @@
     /*                                                                        */
     /* ---------------------------------------------------------------------- */
 
-    public static String checkingNumberDecimal( String input )
+    public static String refiningNumberDecimalFormat( String input )
     {
         try
         {

=== 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-12-11 04:27:39 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties	2009-12-17 02:15:50 +0000
@@ -177,3 +177,4 @@
 list_of_excel_items         = List of excel items
 selected_dataelements		= Selected Data Elements
 available_dataelements		= Available Data Elements
+value_rounded               = This value maybe have been rounded
\ No newline at end of file

=== 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-12-11 04:27:39 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties	2009-12-17 02:15:50 +0000
@@ -176,4 +176,5 @@
 warning_upload_is_null      = Xin vui l\u00f2ng ch\u1ecdn file excel c\u1ea7n upload !
 list_of_excel_items         = Danh s\u00e1ch c\u00e1c excel item
 selected_dataelements		= Ph\u1ea7n t\u1eed c\u00f3 s\u1eb5n
-available_dataelements		= Ph\u1ea7n t\u1eed \u0111\u01b0\u1ee3c ch\u1ecdn
\ No newline at end of file
+available_dataelements		= Ph\u1ea7n t\u1eed \u0111\u01b0\u1ee3c ch\u1ecdn
+value_rounded               = Gi\u00e1 tr\u1ecb n\u00e0y c\u00f3 th\u1ec3 \u0111\u00e3 \u0111\u01b0\u1ee3c l\u00e0m tr\u00f2n
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/preview.js'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/preview.js	2009-12-09 10:26:46 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/preview.js	2009-12-17 02:15:50 +0000
@@ -155,17 +155,18 @@
 					j 		= Number(j) + Number(_colspan);
 					_index 	= Number(_index) + Number(_colspan);
 					
-					_sHTML += "<td align='" + _align + "' colspan='" + _colspan;
+					_sHTML += "<td align='" + _align + "' colspan='" + _colspan + "' ";
 					
-					if ( isNaN(_sData) == false )
+					if ( !isNaN(_sData) && (_sData != "") )
 					{
-						_sHTML += "' class='formatNumberPreview";
+						_sHTML += "class='formatNumberPreview' "
+							   + "title='" + i18n_value_rounded;
 					}
 					else
 					{
-						_sHTML += "' class='formatStringPreview";
+						_sHTML += "class='formatStringPreview" ;
 					}
-					_sHTML += "'>"+ _sData + "</td>";
+					_sHTML += "'>" + _sData + "</td>";
 				}
 			}
 			_sHTML += "</tr>";

=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reportparams.vm'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reportparams.vm	2009-12-16 03:44:27 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/reportparams.vm	2009-12-17 02:15:50 +0000
@@ -67,6 +67,9 @@
 <span id="processing" style="display:none;position:fixed;"><img src="../images/ajax-loader-preview.gif" /></span>
 
 <script>
+
+	var i18n_value_rounded = '$encoder.jsEscape( $i18n.getString("value_rounded"), "'" )';
+
 	#if ( $organisationUnit )
 		
 		$(document).ready(function() {