sheetjs icon indicating copy to clipboard operation
sheetjs copied to clipboard

Format `;($0.0)`

Open hy9be opened this issue 7 years ago • 7 comments

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

returns

(20$0.0)

hy9be avatar Jun 22 '17 14:06 hy9be

@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 avatar Jun 22 '17 16:06 SheetJSDev

@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.

hy9be avatar Jun 27 '17 14:06 hy9be

The issue stems from this line https://github.com/SheetJS/ssf/commit/d273a28d54b3f0478e568e59b0d9159c68a8731d#diff-2bf8a02964fc7c103bafd1eea1a85abdL126

n8agrin avatar Nov 02 '17 16:11 n8agrin

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.

n8agrin avatar Nov 03 '17 16:11 n8agrin

@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

SheetJSDev avatar Nov 03 '17 17:11 SheetJSDev

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.

jgdovin avatar Aug 29 '19 13:08 jgdovin

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

cubewise-tryan avatar Dec 05 '19 06:12 cubewise-tryan