ASF Bugzilla – Attachment 30044 Details for
Bug 54686
[PATCH] Some Excel formats are formatted incorrectly by DataFormatter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
DataFormatter changes
DataFormatter.patch (text/plain), 3.92 KB, created by
abramova151288
on 2013-03-13 12:30:34 UTC
(
hide
)
Description:
DataFormatter changes
Filename:
MIME Type:
Creator:
abramova151288
Created:
2013-03-13 12:30:34 UTC
Size:
3.92 KB
patch
obsolete
>diff -r c4fb047f2adf POI/trunk/org.openl.lib.poi.dev/poi/src/java/org/apache/poi/ss/usermodel/DataFormatter.java >--- a/POI/trunk/org.openl.lib.poi.dev/poi/src/java/org/apache/poi/ss/usermodel/DataFormatter.java Tue Mar 12 12:21:04 2013 +0400 >+++ b/POI/trunk/org.openl.lib.poi.dev/poi/src/java/org/apache/poi/ss/usermodel/DataFormatter.java Wed Mar 13 16:05:22 2013 +0400 >@@ -351,11 +351,31 @@ > // Excel supports fractions in format strings, which Java doesn't > if (!formatStr.contains("-") && > (formatStr.indexOf("#/#") >= 0 && formatStr.indexOf("#/#") == formatStr.lastIndexOf("#/#")) || >- (formatStr.indexOf("?/?") >= 0 && formatStr.indexOf("?/?") == formatStr.lastIndexOf("?/?"))) { >+ (formatStr.indexOf("?/?") >= 0 && formatStr.indexOf("?/?") == formatStr.lastIndexOf("?/?")) || >+ (formatStr.matches(".*?/[1-9].*") && formatStr.indexOf("?/") == formatStr.lastIndexOf("?/"))) { > return new FractionFormat(formatStr); > } > > if (numPattern.matcher(formatStr).find()) { >+ if (formatStr.contains("._")) { >+ if (!formatStr.contains("_._")) { >+ formatStr = formatStr.replace("._", "'.'_"); >+ } >+ } >+ if (formatStr.contains(".\"")) { >+ formatStr = formatStr.replace(".\"", "'.'"); >+ } >+ if (formatStr.contains("\"")) { >+ formatStr = formatStr.replace("\"", ""); >+ } >+ if (formatStr.endsWith(".")) { >+ if (!formatStr.endsWith("_.")) { >+ formatStr = formatStr.substring(0, formatStr.length() - 1) + "'.'"; >+ if (formatStr.contains(".;")) { >+ formatStr = formatStr.replace(".;", "'.';"); >+ } >+ } >+ } > return createNumberFormat(formatStr, cellValue); > } > >@@ -700,6 +720,9 @@ > if (result.contains("E") && !result.contains("E-")) { > result = result.replaceFirst("E", "E+"); > } >+ if (result.charAt(0) == '*') { >+ result = result.substring(1); >+ } > return result; > } > >@@ -981,8 +1004,15 @@ > } > > public String format(Number num) { >- double wholePart = Math.floor(num.doubleValue()); >- double decPart = num.doubleValue() - wholePart; >+ double wholePart; >+ double decPart; >+ if (num.doubleValue() >= 0) { >+ wholePart = Math.floor(num.doubleValue()); >+ decPart = num.doubleValue() - wholePart; >+ } else { >+ wholePart = Math.ceil(num.doubleValue()); >+ decPart = wholePart - num.doubleValue(); >+ } > if (wholePart + decPart == 0) { > return "0"; > } >@@ -1014,10 +1044,19 @@ > } > } > } >+ > NumberFormat neumFormatter = new DecimalFormat(fractParts[0]); >+ NumberFormat wholeFormatter; >+ if (!fractParts[1].contains("#")) { >+ wholeFormatter = new DecimalFormat(parts[0]); >+ currNeum = Math.round(decPart * Integer.parseInt(fractParts[1])); >+ String result = wholeFormatter.format(wholePart) + " " + neumFormatter.format(currNeum) + "/" + fractParts[1]; >+ return result; >+ } >+ > NumberFormat denomFormatter = new DecimalFormat(fractParts[1]); > if (parts.length == 2) { >- NumberFormat wholeFormatter = new DecimalFormat(parts[0]); >+ wholeFormatter = new DecimalFormat(parts[0]); > String result = wholeFormatter.format(wholePart) + " " + neumFormatter.format(currNeum) + "/" + denomFormatter.format(currDenom); > return result; > } else {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 54686
: 30044 |
30430
|
30431
|
30981