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

Number formats not supported in .ODS #1569

Closed
dandv opened this issue Jul 19, 2019 · 8 comments
Closed

Number formats not supported in .ODS #1569

dandv opened this issue Jul 19, 2019 · 8 comments
Labels

Comments

@dandv
Copy link
Contributor

dandv commented Jul 19, 2019

const XLSX = require('xlsx');

const wb = XLSX.utils.book_new();

const ws = XLSX.utils.json_to_sheet([{ dummy: '' }]);

XLSX.utils.book_append_sheet(wb, ws, 'Bug sheet');

ws.A1 = { t: 'n', f: '-10*20', z: '$0.00' };

XLSX.writeFile(wb, 'bug.ods');  // change extension to .xlsx and the format *is* output

image

@SheetJSDev
Copy link
Contributor

The ODS number format representation is quite different from Excel, if there are specific formats you have in mind we can take a look

@dandv
Copy link
Contributor Author

dandv commented Jul 29, 2019 via email

@dandv
Copy link
Contributor Author

dandv commented Jan 2, 2020

Happy New Year! 🎆 Any updates on this? Currency formats are an important feature.

@GusMartins499
Copy link

const XLSX = require('xlsx');

const wb = XLSX.utils.book_new();

const ws = XLSX.utils.json_to_sheet([{ dummy: '' }]);

XLSX.utils.book_append_sheet(wb, ws, 'Bug sheet');

ws.A1 = { t: 'n', f: '-10*20', z: '$0.00' };

XLSX.writeFile(wb, 'bug.ods');  // change extension to .xlsx and the format *is* output

image

same issue

@reviewher reviewher added the ODS label Mar 8, 2022
@XiaoSunXS
Copy link

Any updates on this?

@GusMartins499
Copy link

Any updates on this?

I think not

@SheetJSDev
Copy link
Contributor

There are multiple parts to this discussion. The SheetJS number format representation aligns with the text string in Excel.

OpenDocument vs Excel

OpenDocument stores number formats as a stream of tokens in XML. For example, this is the format for LibreOffice WW QQ:

    <number:date-style style:name="N121">
      <number:week-of-year/>
      <number:text> </number:text>
      <number:quarter number:style="long"/>
    </number:date-style>

Excel does not have support for the "week of year" (you can use the WEEKNUM function to get the same info, but it is not available as a token in the Number Format).

This is not particularly difficult, but it would require some decision on how to map unsupported features between ODS and the SheetJS number format.

LibreOffice vs OpenDocument

LibreOffice translates the OpenDocument XML representation into its own Number Format string.
The bulk of the issues lie in this chasm.

The ODF spec asserts that the default calendar system for the locale should be used. LibreOffice always appears to follow the gengō scheme. This has unexpected behavioral differences where en-US era is 2022 in Excel and ODF but 5782 in LibreOffice

LibreOffice vs Excel

In addition to the aforementioned issues, there are subtle mapping issues like

EEEE (corresponds to one rendering of long Era in Excel but two renderings in LibreOffice)

Y is 2-digit year in Excel, but literal Y in LibreOffice. YYY is 4-digit year in Excel, but 2-digit year followed by Y in LibreOffice.

Open Questions

  1. Coming from LibreOffice, does the library need to translate between SheetJS and LibreOffice style number formats?

  2. How should unsupported features be handled?

Note that this same issue affects Numbers. For example, the Duration cell formats in Numbers support week/day/hr/min/sec/ms while Excel only supports absolute hr/min/sec

@SheetJSDev
Copy link
Contributor

SheetJSDev commented Jun 8, 2022

08f5678 adds support for basic ODS number format read and write.

Issues like missing formats will require a general consensus and revisions to the SSF number formatting library. We'll probably have to expand support since Numbers also supports special formats like the number of weeks.

Style maps (ODF equivalent of multi-part formats in Excel) are not emitted. The main show-stopper is LO support. As it turns out, there are a number of bugs in LibreOffice support for ODF, to the extent that Excel itself seems to have better support for ODS than LibreOffice! We'll try to raise more issues with LO and hopefully the project will more closely align with the spec, at which point we'll revisit more of the ODF minutiae.

As for the literal example, @dandv there are LO bugs around automatic recalculation, but seeding the initial value produces a file that behaves as expected:

const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet([{ dummy: '' }]);
XLSX.utils.book_append_sheet(wb, ws, 'Bug sheet');
ws.A1 = { t: 'n', v: -200, f: '-10*20', z: '$0.00' };
XLSX.writeFile(wb, 'bug.ods');

bug.ods

Live demo: https://jsfiddle.net/m7hnapus/

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

No branches or pull requests

5 participants