← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1038: Importantly fixed - Avoid the error of Infinity or NaN value while write on the excel file by POI

 

------------------------------------------------------------
revno: 1038
committer: hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Tue 2009-11-17 12:07:58 +0700
message:
  Importantly fixed - Avoid the error of Infinity or NaN value while write on the excel file by POI
modified:
  dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java


--
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/utils/ExcelUtils.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java	2009-11-16 04:56:59 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java	2009-11-17 05:07:58 +0000
@@ -40,6 +40,7 @@
 
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
 import org.apache.poi.hssf.usermodel.HSSFRichTextString;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
@@ -145,7 +146,18 @@
             }
             else if ( type.equalsIgnoreCase( ExcelUtils.NUMBER ) )
             {
-                cellPOI.setCellValue( Double.parseDouble( value ) );
+                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 ) );
+                }
             }
         }
     }