question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Number formats not supported in .ODS

See original GitHub issue
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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
SheetJSDevcommented, May 30, 2022

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

1reaction
dandvcommented, Jan 2, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: Numeric Format in Excel ODS - SAS Communities
Hi,. My code creates an XML based Excel file using ODS. I'd like to format the numeric fields using the format "COMMAw.d". For...
Read more >
Differences between the OpenDocument Spreadsheet (.ods ...
Area Subarea Level of Support Excel for Microsoft 365 and Excel 2021 Formatting Row Heights/Column widths Supported. Appearance should be similar. Formatting Cell Supported
Read more >
Number formats for OpenDocument ODS - Lazarus Forum
I am currently trying to implement writing of ods number formats for fpspreadsheet and got stuck with the percentage format which is not...
Read more >
Trouble Converting ODS files to XLS - Apple Community
You need to install Open Office for Mac, open the .ods spreadsheets and save as .xls. Then Numbers can open the file. User...
Read more >
Set Conditional Formats of Excel and ODS files.|Documentation
If the value of the cell does not meet the format condition, the cell's default formatting is used. In Microsoft Excel, select Format,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found