From: Nick Burch Date: Wed, 28 Dec 2011 05:10:24 +0000 (+0000) Subject: Bug #52389 - Handle ?/? format fractions as well as #/# ones, and tighten the criteri... X-Git-Tag: REL_3_8_FINAL~91 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=05bfb7c0c95e5c0634d79f5fdfd3b93afc090c1d;p=poi.git Bug #52389 - Handle ?/? format fractions as well as #/# ones, and tighten the criteria for triggering fraction formatting matching git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1225093 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 3a3d523b9d..5c420b3582 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 52389 - Support ?/? as well as #/# fractions, and tighten DataFormatter rules for fraction matching 52200 - Updated XWPF table example code 52378 - Support for WORKDAY and NETWORKDAYS functions 52349 - Merge the logic between the TEXT function and DataFormatter diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java index 9c56adaa47..c041e32376 100644 --- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java +++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java @@ -349,8 +349,9 @@ public class DataFormatter { } // Excel supports fractions in format strings, which Java doesn't - if (formatStr.indexOf("/") == formatStr.lastIndexOf("/") && - formatStr.indexOf("/") >= 0 && !formatStr.contains("-")) { + if (!formatStr.contains("-") && + (formatStr.indexOf("#/#") >= 0 && formatStr.indexOf("#/#") == formatStr.lastIndexOf("#/#")) || + (formatStr.indexOf("?/?") >= 0 && formatStr.indexOf("?/?") == formatStr.lastIndexOf("?/?"))) { return new FractionFormat(formatStr); } @@ -985,6 +986,8 @@ public class DataFormatter { if (wholePart * decPart == 0) { return "0"; } + + // Split the format string into decimal and fraction parts String[] parts = str.split(" "); String[] fractParts; if (parts.length == 2) { @@ -992,6 +995,11 @@ public class DataFormatter { } else { fractParts = str.split("/"); } + + // Excel supports both #/# and ?/?, but Java only the former + for (int i=0; i