updating to 0.12.8

This commit is contained in:
SheetJS 2018-04-06 02:36:52 -04:00
parent ba24ed7893
commit e4c0f95f7e
4 changed files with 123 additions and 44 deletions

@ -26,7 +26,7 @@ var opts = ({cellNF: true}/*:any*/);
var TYPE = browser ? "binary" : "buffer";
opts.type = TYPE;
var fullex = [".xlsb", /*".xlsm",*/ ".xlsx"/*, ".xlml", ".xls"*/];
var ofmt = ["xlsb", "xlsm", "xlsx", "ods", "biff2", "biff5", "biff8", "xlml", "sylk", "dif", "dbf", "eth"];
var ofmt = ["xlsb", "xlsm", "xlsx", "ods", "biff2", "biff5", "biff8", "xlml", "sylk", "dif", "dbf", "eth", "fods", "csv", "txt", "html"];
var ex = fullex.slice(); ex = ex.concat([".ods", ".xls", ".xml", ".fods"]);
if(typeof process != 'undefined' && ((process||{}).env)) {
opts.WTF = true;
@ -540,6 +540,45 @@ describe('parse options', function() {
it('sheetRows n=10', function() { FSTPaths.forEach(function(p) {
checkcells(X.read(fs.readFileSync(p), {type:TYPE, sheetRows:10}), false, false, false, true);
}); });
it('sheetRows n=1', function() { ofmt.forEach(function(fmt) {
var data = [[1,2],[3,4],[5,6]];
var ws = X.utils.aoa_to_sheet(data);
assert(ws['!ref'] === "A1:B3");
var wb = X.utils.book_new();
X.utils.book_append_sheet(wb, ws, "Sheet1");
var bs = X.write(wb, { bookType: fmt, type: "binary" });
var wb0 = X.read(bs, { type: "binary" });
var ws0 = wb0.Sheets.Sheet1;
assert.equal(ws0['!ref'], "A1:B3");
assert.equal(get_cell(ws0, "A1").v, 1);
assert.equal(get_cell(ws0, "B2").v, 4);
assert.equal(get_cell(ws0, "A3").v, 5);
var wb1 = X.read(bs, { type: "binary", sheetRows: 1 });
var ws1 = wb1.Sheets.Sheet1;
assert.equal(ws1['!ref'], "A1:B1");
assert.equal(get_cell(ws1, "A1").v, 1);
assert(!get_cell(ws1, "B2"));
assert(!get_cell(ws1, "A3"));
if(ws1['!fullref']) assert.equal(ws1['!fullref'], "A1:B3");
var wb2 = X.read(bs, { type: "binary", sheetRows: 2 });
var ws2 = wb2.Sheets.Sheet1;
assert.equal(ws2['!ref'], "A1:B2");
assert.equal(get_cell(ws2, "A1").v, 1);
assert.equal(get_cell(ws2, "B2").v, 4);
assert(!get_cell(ws2, "A3"));
if(ws2['!fullref']) assert.equal(ws2['!fullref'], "A1:B3");
var wb3 = X.read(bs, { type: "binary", sheetRows: 3 });
var ws3 = wb3.Sheets.Sheet1;
assert.equal(ws3['!ref'], "A1:B3");
assert.equal(get_cell(ws3, "A1").v, 1);
assert.equal(get_cell(ws3, "B2").v, 4);
assert.equal(get_cell(ws3, "A3").v, 5);
if(ws3['!fullref']) assert.equal(ws3['!fullref'], "A1:B3");
}); });
});
describe('book', function() {
it('bookSheets should not generate sheets', function() {
@ -1981,6 +2020,17 @@ describe('HTML', function() {
assert.equal(get_cell(ws, "A1").v, "A&B");
assert.equal(get_cell(ws, "B1").v, "A·B");
});
if(domtest) it('should honor sheetRows', function() {
var html = X.utils.sheet_to_html(X.utils.aoa_to_sheet([[1,2],[3,4],[5,6]]));
var ws = X.utils.table_to_sheet(get_dom_element(html));
assert.equal(ws['!ref'], "A1:B3");
ws = X.utils.table_to_sheet(get_dom_element(html), {sheetRows:1});
assert.equal(ws['!ref'], "A1:B1");
assert.equal(ws['!fullref'], "A1:B3");
ws = X.utils.table_to_sheet(get_dom_element(html), {sheetRows:2});
assert.equal(ws['!ref'], "A1:B2");
assert.equal(ws['!fullref'], "A1:B3");
});
describe('type override', function() {
function chk(ws) {
assert.equal(get_cell(ws, "A1").t, "s");
@ -2025,7 +2075,7 @@ describe('js -> file -> js', function() {
['C2', 'C3'].forEach(cb); /* string */
if(!DIF_XL) cb('D4'); /* date */
if(DIF_XL && f == "dif") assert.equal(get_cell(newwb.Sheets.Sheet1, 'C5').v, '=""0.3""');// dif forces string formula
else eqcell(wb, newwb, 'Sheet1', 'C5');
else if(f != 'csv' && f != 'txt') eqcell(wb, newwb, 'Sheet1', 'C5');
});
});
});

30
xlsx.core.min.js vendored

File diff suppressed because one or more lines are too long

20
xlsx.full.min.js vendored

File diff suppressed because one or more lines are too long

63
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.7';
XLSX.version = '0.12.8';
var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true */
if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -5918,6 +5918,7 @@ var fields = [], field = ({});
}
}
if(ft != 0x02) if(d.l < d.length && d[d.l++] != 0x1A) throw new Error("DBF EOF Marker missing " + (d.l-1) + " of " + d.length + " " + d[d.l-1].toString(16));
if(opts && opts.sheetRows) out = out.slice(0, opts.sheetRows);
return out;
}
@ -5944,7 +5945,8 @@ function sheet_to_dbf(ws, opts) {
for(i = 0; i < headers.length; ++i) {
if(i == null) continue;
++hcnt;
if(typeof headers[i] !== 'string') throw new Error("DBF Invalid column name");
if(typeof headers[i] === 'number') headers[i] = headers[i].toString(10);
if(typeof headers[i] !== 'string') throw new Error("DBF Invalid column name " + headers[i] + " |" + (typeof headers[i]) + "|");
if(headers.indexOf(headers[i]) !== i) for(j=0; j<1024;++j)
if(headers.indexOf(headers[i] + "_" + j) == -1) { headers[i] += "_" + j; break; }
}
@ -6132,6 +6134,7 @@ var SYLK = (function() {
}
if(rowinfo.length > 0) sht['!rows'] = rowinfo;
if(colinfo.length > 0) sht['!cols'] = colinfo;
if(opts && opts.sheetRows) arr = arr.slice(0, opts.sheetRows);
return [arr, sht];
}
@ -6222,7 +6225,7 @@ var DIF = (function() {
}
throw new Error("Unrecognized type " + opts.type);
}
function dif_to_aoa_str(str) {
function dif_to_aoa_str(str, opts) {
var records = str.split('\n'), R = -1, C = -1, ri = 0, arr = [];
for (; ri !== records.length; ++ri) {
if (records[ri].trim() === 'BOT') { arr[++R] = []; C = 0; continue; }
@ -6250,6 +6253,7 @@ var DIF = (function() {
}
if (data === 'EOD') break;
}
if(opts && opts.sheetRows) arr = arr.slice(0, opts.sheetRows);
return arr;
}
@ -6323,7 +6327,7 @@ var ETH = (function() {
function decode(s) { return s.replace(/\\b/g,"\\").replace(/\\c/g,":").replace(/\\n/g,"\n"); }
function encode(s) { return s.replace(/\\/g, "\\b").replace(/:/g, "\\c").replace(/\n/g,"\\n"); }
function eth_to_aoa(str) {
function eth_to_aoa(str, opts) {
var records = str.split('\n'), R = -1, C = -1, ri = 0, arr = [];
for (; ri !== records.length; ++ri) {
var record = records[ri].trim().split(":");
@ -6344,6 +6348,7 @@ var ETH = (function() {
if(record[2] == 'vtf') arr[R][C] = [arr[R][C], _f];
}
}
if(opts && opts.sheetRows) arr = arr.slice(0, opts.sheetRows);
return arr;
}
@ -6451,6 +6456,7 @@ var PRN = (function() {
for(C = 1; C <= (lines[R].length - start)/10 + 1; ++C)
set_text_arr(lines[R].slice(start+(C-1)*10,start+C*10).trim(),arr,R,C,o);
}
if(o.sheetRows) arr = arr.slice(0, o.sheetRows);
return arr;
}
@ -6537,11 +6543,11 @@ var PRN = (function() {
start = end+1;
if(range.e.c < C) range.e.c = C;
if(range.e.r < R) range.e.r = R;
if(cc == sepcc) ++C; else { C = 0; ++R; }
if(cc == sepcc) ++C; else { C = 0; ++R; if(o.sheetRows && o.sheetRows <= R) return true; }
}
for(;end < str.length;++end) switch((cc=str.charCodeAt(end))) {
outer: for(;end < str.length;++end) switch((cc=str.charCodeAt(end))) {
case 0x22: instr = !instr; break;
case sepcc: case 0x0a: case 0x0d: if(!instr) finish_cell(); break;
case sepcc: case 0x0a: case 0x0d: if(!instr && finish_cell()) break outer; break;
default: break;
}
if(end - start > 0) finish_cell();
@ -6640,7 +6646,7 @@ var WK_ = (function() {
throw "Unsupported type " + opts.type;
}
function lotus_to_workbook_buf(d,opts) {
function lotus_to_workbook_buf(d, opts) {
if(!d) return d;
var o = opts || {};
if(DENSE != null && o.dense == null) o.dense = DENSE;
@ -6648,6 +6654,7 @@ var WK_ = (function() {
var sheets = {}, snames = [n];
var refguess = {s: {r:0, c:0}, e: {r:0, c:0} };
var sheetRows = o.sheetRows || 0;
if(d[2] == 0x02) o.Enum = WK1Enum;
else if(d[2] == 0x1a) o.Enum = WK3Enum;
@ -6695,6 +6702,7 @@ var WK_ = (function() {
sidx = val[3]; n = "Sheet" + (sidx + 1);
snames.push(n);
}
if(sheetRows > 0 && val[0].r >= sheetRows) break;
if(o.dense) {
if(!s[val[0].r]) s[val[0].r] = [];
s[val[0].r][val[0].c] = val[1];
@ -11896,7 +11904,7 @@ function parse_ws_xml(data, opts, idx, rels, wb, themes, styles) {
if(!s["!ref"] && refguess.e.c >= refguess.s.c && refguess.e.r >= refguess.s.r) s["!ref"] = encode_range(refguess);
if(opts.sheetRows > 0 && s["!ref"]) {
var tmpref = safe_decode_range(s["!ref"]);
if(opts.sheetRows < +tmpref.e.r) {
if(opts.sheetRows <= +tmpref.e.r) {
tmpref.e.r = opts.sheetRows - 1;
if(tmpref.e.r > refguess.e.r) tmpref.e.r = refguess.e.r;
if(tmpref.e.r < tmpref.s.r) tmpref.s.r = tmpref.e.r;
@ -13044,7 +13052,7 @@ function parse_ws_bin(data, _opts, idx, rels, wb, themes, styles) {
if(!s["!ref"] && (refguess.s.r < 2000000 || ref && (ref.e.r > 0 || ref.e.c > 0 || ref.s.r > 0 || ref.s.c > 0))) s["!ref"] = encode_range(ref || refguess);
if(opts.sheetRows && s["!ref"]) {
var tmpref = safe_decode_range(s["!ref"]);
if(opts.sheetRows < +tmpref.e.r) {
if(opts.sheetRows <= +tmpref.e.r) {
tmpref.e.r = opts.sheetRows - 1;
if(tmpref.e.r > refguess.e.r) tmpref.e.r = refguess.e.r;
if(tmpref.e.r < tmpref.s.r) tmpref.s.r = tmpref.e.r;
@ -14419,7 +14427,14 @@ for(var cma = c; cma <= cc; ++cma) {
if(Rn[1]==='/'){
if((tmp=state.pop())[0]!==Rn[3]) throw new Error("Bad state: "+tmp.join("|"));
sheetnames.push(sheetname);
if(refguess.s.r <= refguess.e.r && refguess.s.c <= refguess.e.c) cursheet["!ref"] = encode_range(refguess);
if(refguess.s.r <= refguess.e.r && refguess.s.c <= refguess.e.c) {
cursheet["!ref"] = encode_range(refguess);
if(opts.sheetRows && opts.sheetRows <= refguess.e.r) {
cursheet["!fullref"] = cursheet["!ref"];
refguess.e.r = opts.sheetRows - 1;
cursheet["!ref"] = encode_range(refguess);
}
}
if(merges.length) cursheet["!merges"] = merges;
if(cstys.length > 0) cursheet["!cols"] = cstys;
if(rowinfo.length > 0) cursheet["!rows"] = rowinfo;
@ -15418,6 +15433,7 @@ function parse_workbook(blob, options) {
};
var addcell = function addcell(cell, line, options) {
if(file_depth > 1) return;
if(options.sheetRows && cell.r >= options.sheetRows) cell_valid = false;
if(!cell_valid) return;
if(options.cellStyles && line.XF && line.XF.data) process_cell_style(cell, line, options);
delete line.ixfe; delete line.XF;
@ -15441,8 +15457,7 @@ function parse_workbook(blob, options) {
break;
}
}
if(options.sheetRows && lastcell.r >= options.sheetRows) cell_valid = false;
else {
{
if(options.dense) {
if(!out[cell.r]) out[cell.r] = [];
out[cell.r][cell.c] = line;
@ -15607,6 +15622,13 @@ wb.opts.Date1904 = Workbook.WBProps.date1904 = val; break;
if(range.e.r > 0 && range.e.c > 0) {
range.e.r--; range.e.c--;
out["!ref"] = encode_range(range);
if(options.sheetRows && options.sheetRows <= range.e.r) {
var tmpri = range.e.r;
range.e.r = options.sheetRows - 1;
out["!fullref"] = out["!ref"];
out["!ref"] = encode_range(range);
range.e.r = tmpri;
}
range.e.r++; range.e.c++;
}
if(merges.length > 0) out["!merges"] = merges;
@ -17796,7 +17818,7 @@ var HTML_ = (function() {
for(i = 0; i < rows.length; ++i) {
var row = rows[i].trim();
var hd = row.slice(0,3).toLowerCase();
if(hd == "<tr") { ++R; C = 0; continue; }
if(hd == "<tr") { ++R; if(opts.sheetRows && opts.sheetRows <= R) { --R; break; } C = 0; continue; }
if(hd != "<td") continue;
var cells = row.split(/<\/td>/i);
for(j = 0; j < cells.length; ++j) {
@ -17900,10 +17922,11 @@ function parse_dom_table(table, _opts) {
if(DENSE != null) opts.dense = DENSE;
var ws = opts.dense ? ([]) : ({});
var rows = table.getElementsByTagName('tr');
var range = {s:{r:0,c:0},e:{r:rows.length - 1,c:0}};
var sheetRows = Math.min(opts.sheetRows||10000000, rows.length);
var range = {s:{r:0,c:0},e:{r:sheetRows - 1,c:0}};
var merges = [], midx = 0;
var R = 0, _C = 0, C = 0, RS = 0, CS = 0;
for(; R < rows.length; ++R) {
for(; R < sheetRows; ++R) {
var row = rows[R];
var elts = (row.children);
for(_C = C = 0; _C < elts.length; ++_C) {
@ -17937,6 +17960,7 @@ function parse_dom_table(table, _opts) {
}
ws['!merges'] = merges;
ws['!ref'] = encode_range(range);
if(sheetRows < rows.length) ws['!fullref'] = encode_range((range.e.r = rows.length-1,range));
return ws;
}
@ -18007,6 +18031,11 @@ var parse_content_xml = (function() {
case 'table': case '工作表': // 9.1.2 <table:table>
if(Rn[1]==='/') {
if(range.e.c >= range.s.c && range.e.r >= range.s.r) ws['!ref'] = encode_range(range);
if(opts.sheetRows > 0 && opts.sheetRows <= range.e.r) {
ws['!fullref'] = ws['!ref'];
range.e.r = opts.sheetRows - 1;
ws['!ref'] = encode_range(range);
}
if(merges.length) ws['!merges'] = merges;
if(rowinfo.length) ws["!rows"] = rowinfo;
sheetag.name = utf8read(sheetag['名称'] || sheetag.name);
@ -18123,7 +18152,7 @@ var parse_content_xml = (function() {
if(comments.length > 0) { q.c = comments; comments = []; }
if(textp && opts.cellText !== false) q.w = textp;
if(!isstub || opts.sheetStubs) {
if(!(opts.sheetRows && opts.sheetRows < R)) {
if(!(opts.sheetRows && opts.sheetRows <= R)) {
for(var rpt = 0; rpt < rowpeat; ++rpt) {
colpeat = parseInt(ctag['number-columns-repeated']||"1", 10);
if(opts.dense) {