You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2013/11/01 18:53:59 UTC

[Bug 55731] The character repeation format character * isn't stripped

https://issues.apache.org/bugzilla/show_bug.cgi?id=55731

--- Comment #1 from Eric Peters <er...@peters.org> ---
Here's some additional debug information: 


Basically,
DataFormatter.cleanFormatForNumber("$"* #,##0.00_);_("$"* (#,##0.00)) =>
$#,##0.00;$(#,##0.00)

strips the *<space>

But
DataFormatter.cleanFormatForNumber((_(* #,##0.00_);_(* (#,##0.00)) => *
#,##0.00;* (#,##0.00)

Doesn't & java.text.DecimalFormat will just reprint the *<space> out:
scala> val format = new java.text.DecimalFormat("* #,##0.00;* (#,##0.00)")
format: java.text.DecimalFormat = java.text.DecimalFormat@67a12

scala> format.format(4.79d)
res2: String = * 4.79



A psuedo stack trace/debug statements:


10:51:36.477 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
DataFormatter.getFormat(4.79, 43, _(* #,##0.00_);_(* (#,##0.00);_(*
"-"??_);_(@_))
10:51:36.477 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.getFormat(4.79, +43, _(* #,##0.00_);_(* (#,##0.00);_(*
"-"??_);_(@_)), Target formatStr: _(* #,##0.00_);_(* (#,##0.00)
10:51:36.477 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
DataFormatter.createFormat(4.79, +43, _(* #,##0.00_);_(* (#,##0.00))
10:51:36.477 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
DataFormatter.createNumberFormat(_(* #,##0.00_);_(* (#,##0.00), +4.79)
10:51:36.477 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.createNumberFormat(_(* #,##0.00_);_(* (#,##0.00), +4.79):
cleanFormatForNumber(formatStr) => * #,##0.00;* (#,##0.00)
10:51:36.482 [main] TRACE fm.flatfile.excel.XLSStreamProcessor - ok numrec:
[NUMBER]
    .row    = 0x0000
    .col    = 0x0000
    .xfindex= 0x003E
  .value= 4.79
[/NUMBER]
 and formatListener.getFormatIndex(numrec): 43,
formatListener.getFormatString(43): _(* #,##0.00_);_(* (#,##0.00);_(*
"-"??_);_(@_), HSSFDataFormat.getBuiltinFormat(43): _(* #,##0.00_);_(*
(#,##0.00);_(* "-"??_);_(@_), formatListener.formatNumberDateCell(numrec): *
4.79





10:51:36.483 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
DataFormatter.getFormat(4.79, 43, _(* #,##0.00_);_(* (#,##0.00);_(*
"-"??_);_(@_))
10:51:36.483 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.getFormat(4.79, +43, _(* #,##0.00_);_(* (#,##0.00);_(*
"-"??_);_(@_)), Target formatStr: _(* #,##0.00_);_(* (#,##0.00)
10:51:36.484 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
DataFormatter.getFormat(5.79, 44, _("$"* #,##0.00_);_("$"* (#,##0.00);_("$"*
"-"??_);_(@_))
10:51:36.484 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.getFormat(5.79, +44, _("$"* #,##0.00_);_("$"* (#,##0.00);_("$"*
"-"??_);_(@_)), Target formatStr: _("$"* #,##0.00_);_("$"* (#,##0.00)
10:51:36.484 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
DataFormatter.createFormat(5.79, +44, _("$"* #,##0.00_);_("$"* (#,##0.00))
10:51:36.484 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
DataFormatter.createNumberFormat(_("$"* #,##0.00_);_("$"* (#,##0.00), +5.79)
10:51:36.485 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.createNumberFormat(_("$"* #,##0.00_);_("$"* (#,##0.00), +5.79):
cleanFormatForNumber(formatStr) => $#,##0.00;$(#,##0.00)
10:51:36.485 [main] TRACE fm.flatfile.excel.XLSStreamProcessor - ok numrec:
[NUMBER]
    .row    = 0x0000
    .col    = 0x0001
    .xfindex= 0x003F
  .value= 5.79
[/NUMBER]
 and formatListener.getFormatIndex(numrec): 44,
formatListener.getFormatString(44): _("$"* #,##0.00_);_("$"* (#,##0.00);_("$"*
"-"??_);_(@_), HSSFDataFormat.getBuiltinFormat(44): _("$"* #,##0.00_);_("$"*
(#,##0.00);_("$"* "-"??_);_(@_), formatListener.formatNumberDateCell(numrec):
$5.79




scala> val format = new java.text.DecimalFormat("* #,##0.00;* (#,##0.00)")
format: java.text.DecimalFormat = java.text.DecimalFormat@67a12

scala> format.format(4.79d)
res2: String = * 4.79

scala> 

scala> val format = new java.text.DecimalFormat("$#,##0.00;$(#,##0.00")
format: java.text.DecimalFormat = java.text.DecimalFormat@67500

scala> format.format(5.79d)
res3: String = $5.79

scala>

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


Re: [Bug 55731] The character repeation format character * isn't stripped

Posted by Eric Peters <Er...@Peters.org>.
I'm hoping someone can take my debug information and make a real patch out
of it :)

Turns out, I think this whole foreach statement in DataFormatter.java/
private String cleanFormatForNumber(String formatStr) { is flawed unless
I'm missing something

Notice how its still looping through the StringBuffer even after it's
deleted characters and has effectively "changed the length"

            for (int i = 0; i < sb.length(); i++) {
                char c = sb.charAt(i);
                logger.log(POILogger.DEBUG,
"DataFormatter.cleanFormatForNumber("+formatStr+"), else/foreach character
at: "+i+", value: "+c+", current StringBuffer: "+sb.toString()+", sb size:
"+sb.length());
                if (c == '_' || c == '*') {
                    if (i > 0 && sb.charAt((i - 1)) == '\\') {
                        // It's escaped, don't worry
                        continue;
                    }
                    if (i < sb.length() - 1) {
                        // Remove the character we're supposed
                        //  to match the space of / pad to the
                        //  column width with
                        sb.deleteCharAt(i + 1);
                    }
                    // Remove the _ too
                    sb.deleteCharAt(i);
                }

Confirming how String Buffer works:

scala> val sb = new java.lang.StringBuffer("12345678910")
sb: StringBuffer = 12345678910

scala> sb.length
res6: Int = 11

scala> sb.deleteCharAt(1)
res7: StringBuffer = 1345678910

scala> sb.length
res8: Int = 10

scala> sb.charAt(10)
java.lang.StringIndexOutOfBoundsException: String index out of range: 10


Play by play of cleanFormatForNumber: it never even see's the char "*":

11:15:02.106 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.cleanFormatForNumber(_(* #,##0.00_);_(* (#,##0.00)),
else/foreach character at: 0, value: _, current StringBuffer: _(*
#,##0.00_);_(* (#,##0.00)
11:15:02.106 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.cleanFormatForNumber(_(* #,##0.00_);_(* (#,##0.00)),
else/foreach character at: 1, value:  , current StringBuffer: *
#,##0.00_);_(* (#,##0.00)
11:15:02.106 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.cleanFormatForNumber(_(* #,##0.00_);_(* (#,##0.00)),
else/foreach character at: 2, value: #, current StringBuffer: *
#,##0.00_);_(* (#,##0.00)
11:15:02.106 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.cleanFormatForNumber(_(* #,##0.00_);_(* (#,##0.00)),
else/foreach character at: 3, value: ,, current StringBuffer: *
#,##0.00_);_(* (#,##0.00)
11:15:02.106 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.cleanFormatForNumber(_(* #,##0.00_);_(* (#,##0.00)),
else/foreach character at: 4, value: #, current StringBuffer: *
#,##0.00_);_(* (#,##0.00)
11:15:02.106 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.cleanFormatForNumber(_(* #,##0.00_);_(* (#,##0.00)),
else/foreach character at: 5, value: #, current StringBuffer: *
#,##0.00_);_(* (#,##0.00)
11:15:02.106 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
DataFormatter.cleanFormatForNumber(_(* #,##0.00_);_(* (#,##0.00)),
else/foreach character at: 6, value: 0, current StringBuffer: *
#,##0.00_);_(* (#,##0.00

-Eric



On Fri, Nov 1, 2013 at 10:53 AM, <bu...@apache.org> wrote:

> https://issues.apache.org/bugzilla/show_bug.cgi?id=55731
>
> --- Comment #1 from Eric Peters <er...@peters.org> ---
> Here's some additional debug information:
>
>
> Basically,
> DataFormatter.cleanFormatForNumber("$"* #,##0.00_);_("$"* (#,##0.00)) =>
> $#,##0.00;$(#,##0.00)
>
> strips the *<space>
>
> But
> DataFormatter.cleanFormatForNumber((_(* #,##0.00_);_(* (#,##0.00)) => *
> #,##0.00;* (#,##0.00)
>
> Doesn't & java.text.DecimalFormat will just reprint the *<space> out:
> scala> val format = new java.text.DecimalFormat("* #,##0.00;* (#,##0.00)")
> format: java.text.DecimalFormat = java.text.DecimalFormat@67a12
>
> scala> format.format(4.79d)
> res2: String = * 4.79
>
>
>
> A psuedo stack trace/debug statements:
>
>
> 10:51:36.477 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
> DataFormatter.getFormat(4.79, 43, _(* #,##0.00_);_(* (#,##0.00);_(*
> "-"??_);_(@_))
> 10:51:36.477 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
> DataFormatter.getFormat(4.79, +43, _(* #,##0.00_);_(* (#,##0.00);_(*
> "-"??_);_(@_)), Target formatStr: _(* #,##0.00_);_(* (#,##0.00)
> 10:51:36.477 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
> DataFormatter.createFormat(4.79, +43, _(* #,##0.00_);_(* (#,##0.00))
> 10:51:36.477 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
> DataFormatter.createNumberFormat(_(* #,##0.00_);_(* (#,##0.00), +4.79)
> 10:51:36.477 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
> DataFormatter.createNumberFormat(_(* #,##0.00_);_(* (#,##0.00), +4.79):
> cleanFormatForNumber(formatStr) => * #,##0.00;* (#,##0.00)
> 10:51:36.482 [main] TRACE fm.flatfile.excel.XLSStreamProcessor - ok numrec:
> [NUMBER]
>     .row    = 0x0000
>     .col    = 0x0000
>     .xfindex= 0x003E
>   .value= 4.79
> [/NUMBER]
>  and formatListener.getFormatIndex(numrec): 43,
> formatListener.getFormatString(43): _(* #,##0.00_);_(* (#,##0.00);_(*
> "-"??_);_(@_), HSSFDataFormat.getBuiltinFormat(43): _(* #,##0.00_);_(*
> (#,##0.00);_(* "-"??_);_(@_), formatListener.formatNumberDateCell(numrec):
> *
> 4.79
>
>
>
>
>
> 10:51:36.483 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
> DataFormatter.getFormat(4.79, 43, _(* #,##0.00_);_(* (#,##0.00);_(*
> "-"??_);_(@_))
> 10:51:36.483 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
> DataFormatter.getFormat(4.79, +43, _(* #,##0.00_);_(* (#,##0.00);_(*
> "-"??_);_(@_)), Target formatStr: _(* #,##0.00_);_(* (#,##0.00)
> 10:51:36.484 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
> DataFormatter.getFormat(5.79, 44, _("$"* #,##0.00_);_("$"*
> (#,##0.00);_("$"*
> "-"??_);_(@_))
> 10:51:36.484 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
> DataFormatter.getFormat(5.79, +44, _("$"* #,##0.00_);_("$"*
> (#,##0.00);_("$"*
> "-"??_);_(@_)), Target formatStr: _("$"* #,##0.00_);_("$"* (#,##0.00)
> 10:51:36.484 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
> DataFormatter.createFormat(5.79, +44, _("$"* #,##0.00_);_("$"* (#,##0.00))
> 10:51:36.484 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter - Enter
> DataFormatter.createNumberFormat(_("$"* #,##0.00_);_("$"* (#,##0.00),
> +5.79)
> 10:51:36.485 [main] DEBUG o.a.poi.ss.usermodel.DataFormatter -
> DataFormatter.createNumberFormat(_("$"* #,##0.00_);_("$"* (#,##0.00),
> +5.79):
> cleanFormatForNumber(formatStr) => $#,##0.00;$(#,##0.00)
> 10:51:36.485 [main] TRACE fm.flatfile.excel.XLSStreamProcessor - ok numrec:
> [NUMBER]
>     .row    = 0x0000
>     .col    = 0x0001
>     .xfindex= 0x003F
>   .value= 5.79
> [/NUMBER]
>  and formatListener.getFormatIndex(numrec): 44,
> formatListener.getFormatString(44): _("$"* #,##0.00_);_("$"*
> (#,##0.00);_("$"*
> "-"??_);_(@_), HSSFDataFormat.getBuiltinFormat(44): _("$"*
> #,##0.00_);_("$"*
> (#,##0.00);_("$"* "-"??_);_(@_),
> formatListener.formatNumberDateCell(numrec):
> $5.79
>
>
>
>
> scala> val format = new java.text.DecimalFormat("* #,##0.00;* (#,##0.00)")
> format: java.text.DecimalFormat = java.text.DecimalFormat@67a12
>
> scala> format.format(4.79d)
> res2: String = * 4.79
>
> scala>
>
> scala> val format = new java.text.DecimalFormat("$#,##0.00;$(#,##0.00")
> format: java.text.DecimalFormat = java.text.DecimalFormat@67500
>
> scala> format.format(5.79d)
> res3: String = $5.79
>
> scala>
>
> --
> You are receiving this mail because:
> You are the assignee for the bug.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
> For additional commands, e-mail: dev-help@poi.apache.org
>
>