[Bug 62242] New: Shouldn't show '0' if number format is "??" and cell value is 0

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug 62242] New: Shouldn't show '0' if number format is "??" and cell value is 0

Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=62242

            Bug ID: 62242
           Summary: Shouldn't show '0' if number format is "??" and cell
                    value is 0
           Product: POI
           Version: unspecified
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: SS Common
          Assignee: [hidden email]
          Reporter: [hidden email]
  Target Milestone: ---

I'm trying to read Excel cell's display text. There is a cell which format is:

_ * #,##0.00_ ;_ * -#,##0.00_ ;_ * "-"??_ ;_ @_

You see the 3rd part of formatting string is [_ * "-"??_ ].
In Excel, if the cell's value is zero, it looks like " -   ".
In poi, Cellformat.apply(new Float(0)) will return a string: "- 0 ", contains a
zero which shouldn't exist.

I debugged the source code of ver3.14 and found it may caused by following
code:

Class: org.apache.poi.ss.format.CellNumberFormatter
------------------------------------------------
  private void writeInteger(....

       ..........

       if (resultCh != '0' || s.ch == '0' || s.ch == '?' || pos >= strip) {
                zeroStrip = s.ch == '?' && pos < strip;
                output.setCharAt(s.pos, (zeroStrip ? ' ' : resultCh));
                lastOutputIntegerDigit = s;
       }
------------------------------------------------

The condition for variable "zeroStrip" checks the curren char's position. If it
is the last char(pos equals strip), zeroStrip will be false. It leads the last
zero will always be displayed. Shall we use "pos <= strip" instead of "pos <
strip" to fix this issue?

Best Regards

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 62242] Shouldn't show '0' if number format is "??" and cell value is 0

Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=62242

PJ Fanning <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from PJ Fanning <[hidden email]> ---
Thanks for reporting and investigating the issue. Could you create a Pull
Request on https://github.com/apache/poi with a test case?

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 62242] Shouldn't show '0' if number format is "??" and cell value is 0

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=62242

--- Comment #2 from [hidden email] ---
I'm not sure whether it's a bug or a feature. Maybe for some reasons, the zero
character must appear at least once?
If nobody knows that, I can create a pull request and do some unit test, a few
days later. I need more time to confirm the current logic.

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 62242] Shouldn't show '0' if number format is "??" and cell value is 0

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=62242

--- Comment #3 from [hidden email] ---
Found already there is a TODO in unit test TestCellFormat.java :

// TODO Fix these to not have an incorrect bonus 0 on the end
//assertEquals(" "+pound+"   -   ", cfUK.apply(Double.valueOf(0)).text);
//assertEquals(" -    "+euro+"  ", cfFR.apply(Double.valueOf(0)).text);

so it's a known issue. I have tried to fix code in my way, it works but leads
other case failed.

I will create a pull request if I find the correct way. I hope so.

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 62242] Shouldn't show '0' if number format is "??" and cell value is 0

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=62242

--- Comment #4 from [hidden email] ---
I created a pull request: https://github.com/apache/poi/pull/106.
Also found another bug when test with new test case for my code. This bug
exists all the time. I have commented out the failed new case and add a TODO on
it.

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 62242] Shouldn't show '0' if number format is "??" and cell value is 0

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=62242

Dominik Stadler <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #5 from Dominik Stadler <[hidden email]> ---
The PR causes unit-tests to fail, please try to adjust any other unit-test as
well to still have tests succeed with the changes applied.

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 62242] Shouldn't show '0' if number format is "??" and cell value is 0

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=62242

[hidden email] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW

--- Comment #6 from [hidden email] ---
(In reply to Dominik Stadler from comment #5)
> The PR causes unit-tests to fail, please try to adjust any other unit-test
> as well to still have tests succeed with the changes applied.

Sorry for that. I didn't notice the ooxml test cases. It seems hard to resolve
it. I will try.

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 62242] Shouldn't show '0' if number format is "??" and cell value is 0

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=62242

Dominik Stadler <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 62242] Shouldn't show '0' if number format is "??" and cell value is 0

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=62242

Dominik Stadler <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[hidden email]

--- Comment #7 from Dominik Stadler <[hidden email]> ---
*** Bug 59433 has been marked as a duplicate of this bug. ***

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 62242] Shouldn't show '0' if number format is "??" and cell value is 0

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=62242

--- Comment #8 from Dominik Stadler <[hidden email]> ---
When trying to apply the changes from the PR it fixes the issue here, but some
other tests fail, so unfortunately this needs a bit more work to either change
the tests or the fix.

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]