Skip to content

Commit

Permalink
version bump 0.7.3: last minute bugfixes
Browse files Browse the repository at this point in the history
- parse_XFExtGradient stubbed (fixes SheetJS#62, h/t @oakuraape)
- default to UTF16LE (fixes SheetJS#64, h/t @ajuhos)
- ensure that date1904 is propagated to SSF (fixes SheetJS#66, h/t @Martin-Pitt)
- pin CFB version in anticipation of future changes
  • Loading branch information
SheetJSDev committed Feb 10, 2015
1 parent 2aa239b commit 96a37d3
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 59 deletions.
2 changes: 1 addition & 1 deletion bits/01_version.js
@@ -1 +1 @@
XLS.version = '0.7.2';
XLS.version = '0.7.3';
4 changes: 2 additions & 2 deletions bits/02_codepage.js
@@ -1,9 +1,9 @@
var current_codepage = 1252, current_cptable;
var current_codepage = 1200, current_cptable;
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel');
current_cptable = cptable[current_codepage];
}
function reset_cp() { set_cp(1252); }
function reset_cp() { set_cp(1200); }
function set_cp(cp) { current_codepage = cp; if(typeof cptable !== 'undefined') current_cptable = cptable[cp]; }

var _getchar = function _gc1(x) { return String.fromCharCode(x); };
Expand Down
10 changes: 10 additions & 0 deletions bits/72_style.js
Expand Up @@ -24,6 +24,16 @@ function parse_FullColorExt(blob, length) {
return o;
}

/* 2.5.164 TODO: read 7 bits*/
function parse_IcvXF(blob, length) {
return parsenoop(blob, length);
}

/* 2.5.280 */
function parse_XFExtGradient(blob, length) {
return parsenoop(blob, length);
}

/* 2.5.108 */
function parse_ExtProp(blob, length) {
var extType = blob.read_shift(2);
Expand Down
25 changes: 15 additions & 10 deletions bits/80_xls.js
Expand Up @@ -52,7 +52,7 @@ function slurp(R, blob, length, opts) {
return R.f(b, b.length, opts);
}

function safe_format_xf(p, opts) {
function safe_format_xf(p, opts, date1904) {
if(!p.XF) return;
try {
var fmtid = p.XF.ifmt||0;
Expand All @@ -64,7 +64,7 @@ function safe_format_xf(p, opts) {
}
else p.w = SSF._general(p.v);
}
else p.w = SSF.format(fmtid,p.v);
else p.w = SSF.format(fmtid,p.v, {date1904:date1904||false});
if(opts.cellNF) p.z = SSF._table[fmtid];
} catch(e) { if(opts.WTF) throw e; }
}
Expand Down Expand Up @@ -146,6 +146,11 @@ function parse_workbook(blob, options) {
supbooks.arrayf = opts.arrayf;
var last_Rn = '';
var file_depth = 0; /* TODO: make a real stack */

/* explicit override for some broken writers */
opts.codepage = 1200;
set_cp(1200);

while(blob.l < blob.length - 1) {
var s = blob.l;
var RecordType = blob.read_shift(2);
Expand Down Expand Up @@ -265,24 +270,24 @@ function parse_workbook(blob, options) {
} break;
case 'Number': case 'BIFF2NUM': {
temp_val = {ixfe: val.ixfe, XF: XFs[val.ixfe], v:val.val, t:'n'};
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:val.c, r:val.r}, temp_val, options);
} break;
case 'BoolErr': {
temp_val = {ixfe: val.ixfe, XF: XFs[val.ixfe], v:val.val, t:val.t};
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:val.c, r:val.r}, temp_val, options);
} break;
case 'RK': {
temp_val = {ixfe: val.ixfe, XF: XFs[val.ixfe], v:val.rknum, t:'n'};
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:val.c, r:val.r}, temp_val, options);
} break;
case 'MulRk': {
for(var j = val.c; j <= val.C; ++j) {
var ixfe = val.rkrec[j-val.c][0];
temp_val= {ixfe:ixfe, XF:XFs[ixfe], v:val.rkrec[j-val.c][1], t:'n'};
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:j, r:val.r}, temp_val, options);
}
} break;
Expand All @@ -294,7 +299,7 @@ function parse_workbook(blob, options) {
temp_val = {v:val.val, ixfe:val.cell.ixfe, t:val.tt};
temp_val.XF = XFs[temp_val.ixfe];
if(options.cellFormula) temp_val.f = "="+stringify_formula(val.formula,range,val.cell,supbooks, opts);
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell(val.cell, temp_val, options);
last_formula = val;
}
Expand All @@ -305,7 +310,7 @@ function parse_workbook(blob, options) {
temp_val = {v:last_formula.val, ixfe:last_formula.cell.ixfe, t:'s'};
temp_val.XF = XFs[temp_val.ixfe];
if(options.cellFormula) temp_val.f = "="+stringify_formula(last_formula.formula, range, last_formula.cell, supbooks, opts);
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell(last_formula.cell, temp_val, options);
last_formula = null;
}
Expand All @@ -323,14 +328,14 @@ function parse_workbook(blob, options) {
//temp_val={v:sst[val.isst].t, ixfe:val.ixfe, t:'s'};
temp_val=make_cell(sst[val.isst].t, val.ixfe, 's');
temp_val.XF = XFs[temp_val.ixfe];
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:val.c, r:val.r}, temp_val, options);
break;
case 'Label': case 'BIFF2STR':
/* Some writers erroneously write Label */
temp_val=make_cell(val.val, val.ixfe, 's');
temp_val.XF = XFs[temp_val.ixfe];
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:val.c, r:val.r}, temp_val, options);
break;
case 'Dimensions': {
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Expand Up @@ -2,7 +2,7 @@
"name": "js-xls",
"homepage": "https://github.com/SheetJS/js-xls",
"main": "dist/xls.js",
"version": "0.7.2",
"version": "0.7.3",
"ignore": [
"bin",
"bits",
Expand Down
8 changes: 4 additions & 4 deletions dist/xls.core.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/xls.core.min.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/xls.full.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/xls.full.min.map

Large diffs are not rendered by default.

41 changes: 28 additions & 13 deletions dist/xls.js
Expand Up @@ -3,13 +3,13 @@
/*jshint funcscope:true, eqnull:true */
var XLS = {};
(function make_xls(XLS){
XLS.version = '0.7.2';
var current_codepage = 1252, current_cptable;
XLS.version = '0.7.3';
var current_codepage = 1200, current_cptable;
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel');
current_cptable = cptable[current_codepage];
}
function reset_cp() { set_cp(1252); }
function reset_cp() { set_cp(1200); }
function set_cp(cp) { current_codepage = cp; if(typeof cptable !== 'undefined') current_cptable = cptable[cp]; }

var _getchar = function _gc1(x) { return String.fromCharCode(x); };
Expand Down Expand Up @@ -5155,6 +5155,16 @@ function parse_FullColorExt(blob, length) {
return o;
}

/* 2.5.164 TODO: read 7 bits*/
function parse_IcvXF(blob, length) {
return parsenoop(blob, length);
}

/* 2.5.280 */
function parse_XFExtGradient(blob, length) {
return parsenoop(blob, length);
}

/* 2.5.108 */
function parse_ExtProp(blob, length) {
var extType = blob.read_shift(2);
Expand Down Expand Up @@ -5729,7 +5739,7 @@ function slurp(R, blob, length, opts) {
return R.f(b, b.length, opts);
}

function safe_format_xf(p, opts) {
function safe_format_xf(p, opts, date1904) {
if(!p.XF) return;
try {
var fmtid = p.XF.ifmt||0;
Expand All @@ -5741,7 +5751,7 @@ function safe_format_xf(p, opts) {
}
else p.w = SSF._general(p.v);
}
else p.w = SSF.format(fmtid,p.v);
else p.w = SSF.format(fmtid,p.v, {date1904:date1904||false});
if(opts.cellNF) p.z = SSF._table[fmtid];
} catch(e) { if(opts.WTF) throw e; }
}
Expand Down Expand Up @@ -5823,6 +5833,11 @@ function parse_workbook(blob, options) {
supbooks.arrayf = opts.arrayf;
var last_Rn = '';
var file_depth = 0; /* TODO: make a real stack */

/* explicit override for some broken writers */
opts.codepage = 1200;
set_cp(1200);

while(blob.l < blob.length - 1) {
var s = blob.l;
var RecordType = blob.read_shift(2);
Expand Down Expand Up @@ -5942,24 +5957,24 @@ function parse_workbook(blob, options) {
} break;
case 'Number': case 'BIFF2NUM': {
temp_val = {ixfe: val.ixfe, XF: XFs[val.ixfe], v:val.val, t:'n'};
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:val.c, r:val.r}, temp_val, options);
} break;
case 'BoolErr': {
temp_val = {ixfe: val.ixfe, XF: XFs[val.ixfe], v:val.val, t:val.t};
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:val.c, r:val.r}, temp_val, options);
} break;
case 'RK': {
temp_val = {ixfe: val.ixfe, XF: XFs[val.ixfe], v:val.rknum, t:'n'};
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:val.c, r:val.r}, temp_val, options);
} break;
case 'MulRk': {
for(var j = val.c; j <= val.C; ++j) {
var ixfe = val.rkrec[j-val.c][0];
temp_val= {ixfe:ixfe, XF:XFs[ixfe], v:val.rkrec[j-val.c][1], t:'n'};
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:j, r:val.r}, temp_val, options);
}
} break;
Expand All @@ -5971,7 +5986,7 @@ function parse_workbook(blob, options) {
temp_val = {v:val.val, ixfe:val.cell.ixfe, t:val.tt};
temp_val.XF = XFs[temp_val.ixfe];
if(options.cellFormula) temp_val.f = "="+stringify_formula(val.formula,range,val.cell,supbooks, opts);
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell(val.cell, temp_val, options);
last_formula = val;
}
Expand All @@ -5982,7 +5997,7 @@ function parse_workbook(blob, options) {
temp_val = {v:last_formula.val, ixfe:last_formula.cell.ixfe, t:'s'};
temp_val.XF = XFs[temp_val.ixfe];
if(options.cellFormula) temp_val.f = "="+stringify_formula(last_formula.formula, range, last_formula.cell, supbooks, opts);
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell(last_formula.cell, temp_val, options);
last_formula = null;
}
Expand All @@ -6000,14 +6015,14 @@ function parse_workbook(blob, options) {
//temp_val={v:sst[val.isst].t, ixfe:val.ixfe, t:'s'};
temp_val=make_cell(sst[val.isst].t, val.ixfe, 's');
temp_val.XF = XFs[temp_val.ixfe];
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:val.c, r:val.r}, temp_val, options);
break;
case 'Label': case 'BIFF2STR':
/* Some writers erroneously write Label */
temp_val=make_cell(val.val, val.ixfe, 's');
temp_val.XF = XFs[temp_val.ixfe];
if(temp_val.XF) safe_format_xf(temp_val, options);
if(temp_val.XF) safe_format_xf(temp_val, options, wb.opts.Date1904);
addcell({c:val.c, r:val.r}, temp_val, options);
break;
case 'Dimensions': {
Expand Down
8 changes: 4 additions & 4 deletions dist/xls.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/xls.min.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "xlsjs",
"version": "0.7.2",
"version": "0.7.3",
"author": "sheetjs",
"description": "Excel 5.0/95 and 97-2004 spreadsheet (BIFF5 XLS / BIFF8 XLS / XML 2003) parser",
"keywords": [ "excel", "xls", "office", "spreadsheet" ],
Expand All @@ -11,7 +11,7 @@
"dependencies": {
"ssf":"~0.8.1",
"codepage":"~1.3.6",
"cfb":">=0.10.3",
"cfb":"~0.10.3",
"commander":""
},
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions test.js
Expand Up @@ -61,6 +61,11 @@ function parsetest(x, wb, full, ext) {
it('should have all sheets', function() {
wb.SheetNames.forEach(function(y) { assert(wb.Sheets[y], 'bad sheet ' + y); });
});
/*
if(x.substr(-4) === ".xls") it('should have codepage property', function() {
if(!wb.Props || !wb.Props.CodePage) throw "Missing CodePage entry";
});
*/
it('should have the right sheet names', fs.existsSync(sname) ? function() {
var file = fs.readFileSync(sname, 'utf-8').replace(/\r/g,"");
var names = wb.SheetNames.map(fixsheetname).join("\n") + "\n";
Expand Down
2 changes: 1 addition & 1 deletion test_files
2 changes: 1 addition & 1 deletion tests.lst
Expand Up @@ -321,7 +321,7 @@ apachepoi_ex45978-extraLinkTableSheets.xls
apachepoi_ex46548-23133.xls
apachepoi_ex47747-sharedFormula.xls
apachepoi_excel_with_embeded.xls
apachepoi_excelant.xls
apachepoi_excelant.xls.pending
apachepoi_externalFunctionExample.xls
apachepoi_finance.xls
apachepoi_intercept.xls
Expand Down

0 comments on commit 96a37d3

Please sign in to comment.