You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2010/06/03 18:20:27 UTC
svn commit: r951052 - in /poi/trunk/src:
documentation/content/xdocs/status.xml
java/org/apache/poi/ss/usermodel/DataFormatter.java
java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java
Author: nick
Date: Thu Jun 3 16:20:26 2010
New Revision: 951052
URL: http://svn.apache.org/viewvc?rev=951052&view=rev
Log:
Fix bug #49377 - only call DecimalFormat.setRoundingMode on Java 1.6 - it's needed to match excel's rendering of numbers
Modified:
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
poi/trunk/src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=951052&r1=951051&r2=951052&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Jun 3 16:20:26 2010
@@ -34,6 +34,7 @@
<changes>
<release version="3.7-SNAPSHOT" date="2010-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">49377 - only call DecimalFormat.setRoundingMode on Java 1.6 - it's needed to match excel's rendering of numbers</action>
<action dev="POI-DEVELOPERS" type="fix">49378 - correct 1.6ism</action>
<action dev="POI-DEVELOPERS" type="add">Parse the HSMF headers chunk if present, and use it to find Dates in text extraction if needed</action>
<action dev="POI-DEVELOPERS" type="fix">48494 - detect and support time formats like HH:MM;HH:MM</action>
Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java?rev=951052&r1=951051&r2=951052&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java Thu Jun 3 16:20:26 2010
@@ -19,6 +19,8 @@ package org.apache.poi.ss.usermodel;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.*;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.math.RoundingMode;
import java.text.*;
@@ -415,7 +417,7 @@ public class DataFormatter {
try {
DecimalFormat df = new DecimalFormat(sb.toString(), decimalSymbols);
- df.setRoundingMode(RoundingMode.HALF_UP);
+ setExcelStyleRoundingMode(df);
return df;
} catch(IllegalArgumentException iae) {
@@ -659,6 +661,30 @@ public class DataFormatter {
result.setParseIntegerOnly(true);
return result;
}
+
+ /**
+ * Enables excel style rounding mode (round half up)
+ * on the Decimal Format if possible.
+ * This will work for Java 1.6, but isn't possible
+ * on Java 1.5.
+ */
+ public static void setExcelStyleRoundingMode(DecimalFormat format) {
+ try {
+ Method srm = format.getClass().getMethod("setRoundingMode", RoundingMode.class);
+ srm.invoke(format, RoundingMode.HALF_UP);
+ } catch(NoSuchMethodException e) {
+ // Java 1.5
+ } catch(IllegalAccessException iae) {
+ // Shouldn't happen
+ throw new RuntimeException("Unable to set rounding mode", iae);
+ } catch(InvocationTargetException ite) {
+ // Shouldn't happen
+ throw new RuntimeException("Unable to set rounding mode", ite);
+ } catch(SecurityException se) {
+ // Not much we can do here
+ }
+ }
+
/**
* Format class for Excel's SSN format. This class mimics Excel's built-in
* SSN formatting.
Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java?rev=951052&r1=951051&r2=951052&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java Thu Jun 3 16:20:26 2010
@@ -43,8 +43,8 @@ public class ExcelStyleDateFormatter ext
private DecimalFormat format1digit = new DecimalFormat("0");
private DecimalFormat format2digits = new DecimalFormat("00");
{
- format1digit.setRoundingMode(RoundingMode.HALF_UP);
- format2digits.setRoundingMode(RoundingMode.HALF_UP);
+ DataFormatter.setExcelStyleRoundingMode(format1digit);
+ DataFormatter.setExcelStyleRoundingMode(format2digits);
}
private double dateToBeFormatted = 0.0;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org