updating to 0.12.11

This commit is contained in:
SheetJS 2018-04-27 16:12:36 -04:00
parent e4bc2ce1ce
commit c72dd3a7ba
4 changed files with 88 additions and 35 deletions

@ -1326,6 +1326,27 @@ describe('write features', function() {
assert(str.indexOf("<b>abc</b>") > 0);
});
});
describe('sheet range limits', function() { [
["biff2", "IV16384"],
["biff5", "IV16384"],
["biff8", "IV65536"],
["xlsx", "XFD1048576"],
["xlsb", "XFD1048576"]
].forEach(function(r) { it(r[0], function() {
var C = X.utils.decode_cell(r[1]);
var wopts = {bookType:r[0], type:'binary', WTF:1};
var wb = { SheetNames: ["Sheet1"], Sheets: { Sheet1: {} } };
wb.Sheets.Sheet1['!ref'] = "A1:" + X.utils.encode_cell({r:0, c:C.c});
X.write(wb, wopts);
wb.Sheets.Sheet1['!ref'] = "A" + X.utils.encode_row(C.r - 5) + ":" + X.utils.encode_cell({r:C.r, c:0});
X.write(wb, wopts);
wb.Sheets.Sheet1['!ref'] = "A1:" + X.utils.encode_cell({r:0, c:C.c+1});
assert.throws(function() { X.write(wb, wopts); });
wb.Sheets.Sheet1['!ref'] = "A" + X.utils.encode_row(C.r - 5) + ":" + X.utils.encode_cell({r:C.r+1, c:0});
assert.throws(function() { X.write(wb, wopts); });
}); }); });
});
function seq(end/*:number*/, start/*:?number*/)/*:Array<number>*/ {

28
xlsx.core.min.js vendored

File diff suppressed because one or more lines are too long

32
xlsx.full.min.js vendored

File diff suppressed because one or more lines are too long

42
xlsx.js

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {};
(function make_xlsx(XLSX){
XLSX.version = '0.12.10';
XLSX.version = '0.12.11';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -4105,7 +4105,6 @@ function write_cust_props(cp) {
if(!cp) return o.join("");
var pid = 1;
keys(cp).forEach(function custprop(k) { ++pid;
// $FlowIgnore
o[o.length] = (writextag('property', write_vt(cp[k]), {
'fmtid': '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}',
'pid': pid,
@ -11828,6 +11827,13 @@ function safe_format(p, fmtid, fillid, opts, themes, styles) {
}
} catch(e) { if(opts.WTF && styles.Fills) throw e; }
}
function check_ws(ws, sname, i) {
if(ws && ws['!ref']) {
var range = safe_decode_range(ws['!ref']);
if(range.e.c < range.s.c || range.e.r < range.s.r) throw new Error("Bad range (" + i + "): " + ws['!ref']);
}
}
function parse_ws_xml_dim(ws, s) {
var d = safe_decode_range(s);
if(d.s.r<=d.e.r && d.s.c<=d.e.c && d.s.r>=0 && d.s.c>=0) ws["!ref"] = encode_range(d);
@ -12299,7 +12305,14 @@ function write_ws_xml(idx, opts, wb, rels) {
var s = wb.SheetNames[idx], sidx = 0, rdata = "";
var ws = wb.Sheets[s];
if(ws == null) ws = {};
var ref = ws['!ref']; if(ref == null) ref = 'A1';
var ref = ws['!ref'] || 'A1';
var range = safe_decode_range(ref);
if(range.e.c > 0x3FFF || range.e.r > 0xFFFFF) {
if(opts.WTF) throw new Error("Range " + ref + " exceeds format limit A1:XFD1048576");
range.e.c = Math.min(range.e.c, 0x3FFF);
range.e.r = Math.min(range.e.c, 0xFFFFF);
ref = encode_range(range);
}
if(!rels) rels = {};
ws['!comments'] = [];
ws['!drawing'] = [];
@ -13217,6 +13230,11 @@ function write_ws_bin(idx, opts, wb, rels) {
var s = wb.SheetNames[idx], ws = wb.Sheets[s] || {};
var c = s; try { if(wb && wb.Workbook) c = wb.Workbook.Sheets[idx].CodeName || c; } catch(e) {}
var r = safe_decode_range(ws['!ref'] || "A1");
if(r.e.c > 0x3FFF || r.e.r > 0xFFFFF) {
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:XFD1048576");
r.e.c = Math.min(r.e.c, 0x3FFF);
r.e.r = Math.min(r.e.c, 0xFFFFF);
}
ws['!links'] = [];
/* passed back to write_zip and removed there */
ws['!comments'] = [];
@ -13550,6 +13568,7 @@ function check_wb(wb) {
if(!wb.SheetNames.length) throw new Error("Workbook is empty");
var Sheets = (wb.Workbook && wb.Workbook.Sheets) || [];
check_wb_names(wb.SheetNames, Sheets, !!wb.vbaraw);
for(var i = 0; i < wb.SheetNames.length; ++i) check_ws(wb.Sheets[wb.SheetNames[i]], wb.SheetNames[i], i);
/* TODO: validate workbook */
}
/* 18.2 Workbook */
@ -13600,7 +13619,7 @@ function parse_wb_xml(data, opts) {
/* 18.2.1 bookViews CT_BookViews ? */
case '<bookViews': case '<bookViews>': case '</bookViews>': break;
/* 18.2.30 workbookView CT_BookView + */
case '<workbookView': delete y[0]; wb.WBView.push(y); break;
case '<workbookView': case '<workbookView/>': delete y[0]; wb.WBView.push(y); break;
case '</workbookView>': break;
/* 18.2.20 sheets CT_Sheets 1 */
@ -17546,6 +17565,12 @@ function write_ws_biff2_cell(ba, cell, R, C) {
function write_ws_biff2(ba, ws, idx, opts) {
var dense = Array.isArray(ws);
var range = safe_decode_range(ws['!ref'] || "A1"), ref, rr = "", cols = [];
if(range.e.c > 0xFF || range.e.r > 0x3FFF) {
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
range.e.c = Math.min(range.e.c, 0xFF);
range.e.r = Math.min(range.e.c, 0x3FFF);
ref = encode_range(range);
}
for(var R = range.s.r; R <= range.e.r; ++R) {
rr = encode_row(R);
for(var C = range.s.c; C <= range.e.c; ++C) {
@ -17649,9 +17674,16 @@ function write_ws_biff8(idx, opts, wb) {
var _WB = ((wb||{}).Workbook||{});
var _sheet = ((_WB.Sheets||[])[idx]||{});
var dense = Array.isArray(ws);
var b8 = opts.biff == 8;
var ref, rr = "", cols = [];
var range = safe_decode_range(ws['!ref'] || "A1");
var b8 = opts.biff == 8;
var MAX_ROWS = b8 ? 65536 : 16384;
if(range.e.c > 0xFF || range.e.r >= MAX_ROWS) {
if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
range.e.c = Math.min(range.e.c, 0xFF);
range.e.r = Math.min(range.e.c, MAX_ROWS-1);
}
write_biff_rec(ba, 0x0809, write_BOF(wb, 0x10, opts));
/* ... */
write_biff_rec(ba, "CalcMode", writeuint16(1));