<changes>
<release version="3.8-beta6" date="2012-??-??">
+ <action dev="poi-developers" type="add">52389 - Support ?/? as well as #/# fractions, and tighten DataFormatter rules for fraction matching</action>
<action dev="poi-developers" type="add">52200 - Updated XWPF table example code </action>
<action dev="poi-developers" type="add">52378 - Support for WORKDAY and NETWORKDAYS functions</action>
<action dev="poi-developers" type="add">52349 - Merge the logic between the TEXT function and DataFormatter</action>
}
// 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);
}
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) {
} else {
fractParts = str.split("/");
}
+
+ // Excel supports both #/# and ?/?, but Java only the former
+ for (int i=0; i<fractParts.length; i++) {
+ fractParts[i] = fractParts[i].replace('?', '#');
+ }
if (fractParts.length == 2) {
double minVal = 1.0;
public void testFractions() {
DataFormatter dfUS = new DataFormatter(Locale.US);
- assertEquals("321 1/3", dfUS.formatRawCellContents(321.321, -1, "# #/#"));
+ // Excel often prefers "# #/#"
+ assertEquals("321 1/3", dfUS.formatRawCellContents(321.321, -1, "# #/#"));
assertEquals("321 26/81", dfUS.formatRawCellContents(321.321, -1, "# #/##"));
- assertEquals("26027/81", dfUS.formatRawCellContents(321.321, -1, "#/##"));
+ assertEquals("26027/81", dfUS.formatRawCellContents(321.321, -1, "#/##"));
+
+ // OOo seems to like the "# ?/?" form
+ assertEquals("321 1/3", dfUS.formatRawCellContents(321.321, -1, "# ?/?"));
+ assertEquals("321 26/81", dfUS.formatRawCellContents(321.321, -1, "# ?/??"));
+ assertEquals("26027/81", dfUS.formatRawCellContents(321.321, -1, "?/??"));
}
/**