From bf4736e966a23141e0de7dc7eb9b84e79f5a16b7 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Thu, 2 Sep 2021 05:58:39 -0400 Subject: [PATCH] biff8 write column widths --- .gitattributes | 1 - bits/39_xlsbiff.js | 14 ++++++++++++++ bits/78_writebiff.js | 12 ++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index f26ed36..e41a26c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,3 @@ -*.*s linguist-documentation *.html linguist-documentation *.md text eol=lf diff --git a/bits/39_xlsbiff.js b/bits/39_xlsbiff.js index b5eb743..755b5de 100644 --- a/bits/39_xlsbiff.js +++ b/bits/39_xlsbiff.js @@ -967,6 +967,20 @@ function parse_ColInfo(blob, length, opts) { if(opts.biff >= 5 || !opts.biff) o.level = (flags >> 8) & 0x7; return o; } +function write_ColInfo(col, idx) { + var o = new_buf(12); + o.write_shift(2, idx); + o.write_shift(2, idx); + o.write_shift(2, col.width * 256); + o.write_shift(2, 0); + var f = 0; + if(col.hidden) f |= 1; + o.write_shift(1, f); + f = col.level || 0; + o.write_shift(1, f); + o.write_shift(2, 0); + return o; +} /* [MS-XLS] 2.4.257 */ function parse_Setup(blob, length) { diff --git a/bits/78_writebiff.js b/bits/78_writebiff.js index 6d0cf37..d761cae 100644 --- a/bits/78_writebiff.js +++ b/bits/78_writebiff.js @@ -164,6 +164,16 @@ function write_ws_biff8_hlinks(ba/*:BufArray*/, ws) { delete ws['!links']; } +function write_ws_cols_biff8(ba, cols, ws) { + if(!cols) return; + var cnt = 0; + cols.forEach(function(col, idx) { + if(++cnt <= 256 && col) { + write_biff_rec(ba, "ColInfo", write_ColInfo(col_obj_w(idx, col), idx)); + } + }); +} + function write_ws_biff8_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:number*/, opts) { var os = 16 + get_cell_style(opts.cellXfs, cell, opts); if(cell.v == null && !cell.bf) { @@ -227,6 +237,8 @@ function write_ws_biff8(idx/*:number*/, opts, wb/*:Workbook*/) { write_biff_rec(ba, "HCenter", writebool(false)); write_biff_rec(ba, "VCenter", writebool(false)); /* ... */ + if(b8) write_ws_cols_biff8(ba, ws["!cols"], ws); + /* ... */ write_biff_rec(ba, 0x200, write_Dimensions(range, opts)); /* ... */