sheetjs icon indicating copy to clipboard operation
sheetjs copied to clipboard

SSF - format not supported

Open alonkh2 opened this issue 2 years ago • 4 comments

I have been using SSF in my project, and have run into this problem - when the format is "#,0" it seems to throw an error. That is a valid excel format.

image

Error: unsupported format |#,0| Component: write_num_flt Stack: at write_num_flt (ssf.js:498) at write_num (ssf.js:616) at eval_fmt (ssf.js:824) at format (ssf.js:940)

alonkh2 avatar May 25 '22 14:05 alonkh2

Excel appears to be auto-correcting #,0 to #,##0. You can create a new file with

var wb = XLSX.utils.book_new();
var ws = XLSX.utils.aoa_to_sheet([[12345.6789]]);
ws["A1"].z = "#,0";
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
XLSX.writeFile(wb, "issue2695.xlsx");

(https://jsfiddle.net/c91Lotas/ live example) Excel 2019 en-US appears to treat it as number with thousands separator and zero decimal places

SheetJSDev avatar May 25 '22 15:05 SheetJSDev

I can see that, but is the library going to support that?

alonkh2 avatar May 26 '22 09:05 alonkh2

It's an interesting question. The current approach is to stick the autocorrected formats in the main file processing library, but it probably should be added to the library.

SheetJSDev avatar May 27 '22 04:05 SheetJSDev

could you refer me to the code relating to this?

alonkh2 avatar Jun 12 '22 07:06 alonkh2