Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format ;($0.0) #2559

Open
hy9be opened this issue Jun 22, 2017 · 7 comments
Open

Format ;($0.0) #2559

hy9be opened this issue Jun 22, 2017 · 7 comments

Comments

@hy9be
Copy link

hy9be commented Jun 22, 2017

SSF.format('[<=-1000](0.0,"K");[<0]($0.0)', -200);

returns

(20$0.0)
@SheetJSDev
Copy link
Contributor

@hy9be can confirm that is an issue as part of the second part of a conditional format. Simpler repro:

SSF.format(';($0.0)', -200);

@SheetJSDev SheetJSDev changed the title Mask ($0.0) breaks the number to be formatted Format ;($0.0) Jun 22, 2017
@hy9be
Copy link
Author

hy9be commented Jun 27, 2017

@SheetJSDev Are you guys looking into it?

I could also try to fix it if you guys can give me some hint. The source codes do not have many comments. That makes it a bit hard to debug for me.

@n8agrin
Copy link

n8agrin commented Nov 2, 2017

The issue stems from this line SheetJS/ssf@d273a28#diff-2bf8a02964fc7c103bafd1eea1a85abdL126

@n8agrin
Copy link

n8agrin commented Nov 3, 2017

I spent several hours yesterday trying to dig into this and come up with a fix, but was ultimately defeated by the complexity of the code.

@SheetJSDev do you guys have some kind of grammar from which this code is generated? I found it really difficult to navigate with so many conditionals and single letter variables to juggle. I'm assuming everything in this repo is machine generated. If you're willing to let go of the source, I'd be happy to continue to dig in here.

@SheetJSDev
Copy link
Contributor

@n8agrin The "official grammar" is in [MS-XLS] 2.4.126 and there's an attempt to describe the behavior in ECMA-376 18.8.30-18.8.31 (pages 1776-1792 of the Fifth Edition PDF, I exported the relevant pages in a new PDF linked at the bottom of this comment).

We started from there and quickly found it diverged from actual Excel behavior (our general opinion is that it's generally correct for the standard format codes but quickly degrades for anything remotely nonstandard). Incidentally, even Excel Online doesn't support custom number formats, probably because they also succumbed to the mess.

The code you're looking at written by hand, and in retrospect we probably should have used more descriptive variable names. We're going to try to clean it up soon.

The error in this case is in how the overflow is handled with the currency symbol. There's a weird trick in the eval_fmt function to determine where the decimal point starts and draw digits. The reason for this trick is apparent when considering formats like ###0 "Million" 000 "Thousand" 0 "Hundred" 00:

screen shot 2017-11-03 at 13 30 26

Ecma Office Open XML Part 1 - Fundamentals And Markup Language Reference.pdf

@jgdovin
Copy link

jgdovin commented Aug 29, 2019

This is still a large issue for a project we are working on. I plan to look at it in the future but if anyone has a fix ready for this that would be great.

@cubewise-tryan
Copy link
Contributor

I was having the same issue, I have created a pull request with a fix SheetJS/ssf#39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants