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