You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Yegor Kozlov <ye...@dinom.ru> on 2011/02/10 15:07:52 UTC

fixed regression in HSSF

Hi All

Just a heads up  that we had a regression in HSSF caused by r1061288, 
http://svn.apache.org/viewvc?view=revision&revision=1061288

As a consequence, new HSSF workbooks created from scratch could not be 
opened in Excel. I tested in Office 2007 and it complains that some of 
cell styles are invalid.

The regression was caused by the following change in InternalWorkbook:

+
          switch (id) {
-            case 0: return new FormatRecord(5, 
"\"$\"#,##0_);\\(\"$\"#,##0\\)");
-            case 1: return new FormatRecord(6, 
"\"$\"#,##0_);[Red]\\(\"$\"#,##0\\)");
-            case 2: return new FormatRecord(7, 
"\"$\"#,##0.00_);\\(\"$\"#,##0.00\\)");
-            case 3: return new FormatRecord(8, 
"\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)");
-            case 4: return new FormatRecord(0x2a, "_(\"$\"* 
#,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"_);_(@_)");
-            case 5: return new FormatRecord(0x29, "_(* #,##0_);_(* 
\\(#,##0\\);_(* \"-\"_);_(@_)");
-            case 6: return new FormatRecord(0x2c, "_(\"$\"* 
#,##0.00_);_(\"$\"* \\(#,##0.00\\);_(\"$\"* \"-\"??_);_(@_)");
-            case 7: return new FormatRecord(0x2b, "_(* #,##0.00_);_(* 
\\(#,##0.00\\);_(* \"-\"??_);_(@_)");
+            case 0: return new FormatRecord(5, 
BuiltinFormats.getBuiltinFormat(5));
+            case 1: return new FormatRecord(6, 
BuiltinFormats.getBuiltinFormat(6));
+            case 2: return new FormatRecord(7, 
BuiltinFormats.getBuiltinFormat(7));
+            case 3: return new FormatRecord(8, 
BuiltinFormats.getBuiltinFormat(8));
+            case 4: return new FormatRecord(0x2a, 
BuiltinFormats.getBuiltinFormat(0x2a));
+            case 5: return new FormatRecord(0x29, 
BuiltinFormats.getBuiltinFormat(0x29));
+            case 6: return new FormatRecord(0x2c, 
BuiltinFormats.getBuiltinFormat(0x2c));
+            case 7: return new FormatRecord(0x2b, 
BuiltinFormats.getBuiltinFormat(0x2b));
          }
          throw new  IllegalArgumentException("Unexpected id " + id);

The difference between the old and new code is that the old code escapes 
dollars and brackets and BuiltinFormats.getBuiltinFormat returns the raw 
format string. It appears that escaping special sumbols like $, ( and ) 
is important.

Since BuiltinFormats is a common class shared by HSSF and XSSF, I think 
it is best to escape format definitions hardcoded in it.
I committed the fix in r1069396.

Yegor

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: fixed regression in HSSF

Posted by Yegor Kozlov <ye...@dinom.ru>.
On 2/10/2011 5:42 PM, Nick Burch wrote:
> On Thu, 10 Feb 2011, Yegor Kozlov wrote:
>> Since BuiltinFormats is a common class shared by HSSF and XSSF, I 
>> think it is best to escape format definitions hardcoded in it. I 
>> committed the fix in r1069396.
>
> Do .xlsx files generated by excel have the escaped or non-escaped 
> form? If they have the old BuiltIn style form, we should maybe just 
> add the escaping when we create the record
>

Yup, .xlsx escapes dollars and brackets too. I created a test file in 
Office 2007 and see that dollar is enclosed in double quotes:

<styleSheet>
<numFmts count="4">
<numFmt numFmtId="42" formatCode="_("$"* #,##0_);_("$"* \(#,##0\);_("$"* 
"-"_);_(@_)"/>
<numFmt numFmtId="41" formatCode="_(* #,##0_);_(* \(#,##0\);_(* 
"-"_);_(@_)"/>
<numFmt numFmtId="44" formatCode="_("$"* #,##0.00_);_("$"* 
\(#,##0.00\);_("$"* "-"??_);_(@_)"/>
<numFmt numFmtId="43" formatCode="_(* #,##0.00_);_(* \(#,##0.00\);_(* 
"-"??_);_(@_)"/>
</numFmts>
....


So the fix seems to be OK for both HSSF and XSSF.

Yegor



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: fixed regression in HSSF

Posted by Nick Burch <ni...@alfresco.com>.
On Thu, 10 Feb 2011, Yegor Kozlov wrote:
> Since BuiltinFormats is a common class shared by HSSF and XSSF, I think 
> it is best to escape format definitions hardcoded in it. I committed the 
> fix in r1069396.

Do .xlsx files generated by excel have the escaped or non-escaped form? If 
they have the old BuiltIn style form, we should maybe just add the 
escaping when we create the record

(I made the change because the two lists had got out of sync, and that was 
breaking things for some other cases...)

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org