version bump 0.5.8: bookFiles, default change

- option bookFiles controls whether zip files and keys are written to object
  *** Default has been flipped from "true" to "false"
- updated SSF to 0.5.8
- updated test_files to 20140216 (tests also look at 2013 XLSB)
- added dist files (make dist)
This commit is contained in:
SheetJS 2014-02-17 03:44:22 -05:00
parent c0a8bef07c
commit 33fbc389c5
16 changed files with 3125 additions and 58 deletions

@ -1,12 +1,13 @@
LIB=xlsx
DEPS=$(wildcard bits/*.js)
TARGET=xlsx.js
TARGET=$(LIB).js
FMT=xlsx xlsm xlsb
$(TARGET): $(DEPS)
cat $^ > $@
bits/31_version.js: package.json
echo "XLSX.version = '"`grep version package.json | awk '{gsub(/[^0-9\.]/,"",$$2); print $$2}'`"';" > $@
echo "XLSX.version = '"`grep version package.json | awk '{gsub(/[^0-9\.]/,"",$$2); print $$2}'`"';" > $@
.PHONY: clean
clean:
@ -21,7 +22,7 @@ init:
.PHONY: test mocha
test mocha:
test mocha: test.js
mocha -R spec
TESTFMT=$(patsubst %,test_%,$(FMT))
@ -40,7 +41,7 @@ lint: $(TARGET)
.PHONY: cov
cov: misc/coverage.html
misc/coverage.html: xlsx.js test.js
misc/coverage.html: $(TARGET) test.js
mocha --require blanket -R html-cov > misc/coverage.html
.PHONY: coveralls
@ -48,5 +49,7 @@ coveralls:
mocha --require blanket --reporter mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js
.PHONY: dist
dist: xlsx.js
uglifyjs xlsx.js -o dist/xlsx.min.js --source-map dist/xlsx.min.map --preamble "$$(head -n 1 bits/00_header.js)"
dist: $(TARGET)
cp $(TARGET) dist/
cp LICENSE dist/
uglifyjs $(TARGET) -o dist/$(LIB).min.js --source-map dist/$(LIB).min.map --preamble "$$(head -n 1 bits/00_header.js)"

@ -6,7 +6,7 @@ var _strrev = function(x) { return String(x).split("").reverse().join("");};
function fill(c,l) { return new Array(l+1).join(c); }
function pad(v,d,c){var t=String(v);return t.length>=d?t:(fill(c||0,d-t.length)+t);}
function rpad(v,d,c){var t=String(v);return t.length>=d?t:(t+fill(c||0,d-t.length));}
SSF.version = '0.5.7';
SSF.version = '0.5.8';
/* Options */
var opts_fmt = {};
function fixopts(o){for(var y in opts_fmt) if(o[y]===undefined) o[y]=opts_fmt[y];}
@ -113,7 +113,7 @@ var general_fmt = function(v) {
return o.replace("e","E").replace(/\.0*$/,"").replace(/\.([0-9]*[^0])0*$/,".$1").replace(/(E[+-])([0-9])$/,"$1"+"0"+"$2");
}
if(typeof v === 'string') return v;
throw "unsupported value in General format: " + v;
throw new Error("unsupported value in General format: " + v);
};
SSF._general = general_fmt;
var parse_date_code = function parse_date_code(v,opts) {
@ -230,7 +230,7 @@ var write_num = function(type, fmt, val) {
return o.replace("e","E");
}
if(fmt[0] === "$") return "$"+write_num(type,fmt.substr(fmt[1]==' '?2:1),val);
var r, ff, aval = val < 0 ? -val : val, sign = val < 0 ? "-" : "";
var r, rr, ff, aval = val < 0 ? -val : val, sign = val < 0 ? "-" : "";
if((r = fmt.match(/# (\?+)([ ]?)\/([ ]?)(\d+)/))) {
var den = Number(r[4]), rnd = Math.round(aval * den), base = Math.floor(rnd/den);
var myn = (rnd - base*den), myd = den;
@ -243,8 +243,17 @@ var write_num = function(type, fmt, val) {
o = Math.round(val * Math.pow(10,r[1].length));
return String(o/Math.pow(10,r[1].length)).replace(/^([^\.]+)$/,"$1."+r[1]).replace(/\.$/,"."+r[1]).replace(/\.([0-9]*)$/,function($$, $1) { return "." + $1 + fill("0", r[1].length-$1.length); });
}
if((r = fmt.match(/^(0*)\.(#*)$/))) {
o = Math.round(val*Math.pow(10,r[2].length));
return String(o * Math.pow(10,-r[2].length)).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^([-]?\d*)$/,"$1.").replace(/^0\./,r[1].length?"0.":".");
}
if((r = fmt.match(/^#,##0([.]?)$/))) return sign + commaify(String(Math.round(aval)));
if((r = fmt.match(/^#,##0\.([#0]*0)$/))) {
rr = Math.round((val-Math.floor(val))*Math.pow(10,r[1].length));
return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(rr,r[1].length,0);
}
if((r = fmt.match(/^# ([?]+)([ ]?)\/([ ]?)([?]+)/))) {
var rr = Math.min(Math.max(r[1].length, r[4].length),7);
rr = Math.min(Math.max(r[1].length, r[4].length),7);
ff = frac(aval, Math.pow(10,rr)-1, true);
return sign + (ff[0]||(ff[1] ? "" : "0")) + " " + (ff[1] ? pad(ff[1],rr," ") + r[2] + "/" + r[3] + rpad(ff[2],rr," "): fill(" ", 2*rr+1 + r[2].length + r[3].length));
}
@ -253,16 +262,6 @@ var write_num = function(type, fmt, val) {
case "#.##": o = Math.round(val*100);
return String(o/100).replace(/^([^\.]+)$/,"$1.").replace(/^0\.$/,".");
case "#,###": var x = commaify(String(Math.round(aval))); return x !== "0" ? sign + x : "";
case "#,##0": return sign + commaify(String(Math.round(aval)));
case "#,##0.0": r = Math.round((val-Math.floor(val))*10); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,1,"0");
case "#,##0.00": r = Math.round((val-Math.floor(val))*100); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,2,"0");
case "#,##0.000": r = Math.round((val-Math.floor(val))*1000); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,3,0);
case "#,##0.0000": r = Math.round((val-Math.floor(val))*10000); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,4,0);
case "#,##0.00000": r = Math.round((val-Math.floor(val))*Math.pow(10,5)); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,5,0);
case "#,##0.000000": r = Math.round((val-Math.floor(val))*Math.pow(10,6)); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,6,0);
case "#,##0.0000000": r = Math.round((val-Math.floor(val))*Math.pow(10,7)); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,7,0);
case "#,##0.00000000": r = Math.round((val-Math.floor(val))*Math.pow(10,8)); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,8,0);
case "#,##0.000000000": r = Math.round((val-Math.floor(val))*Math.pow(10,9)); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,9,0);
default:
}
throw new Error("unsupported format |" + fmt + "|");
@ -279,7 +278,7 @@ function split_fmt(fmt) {
j = i+1;
}
out.push(fmt.slice(j));
if(in_str !=-1) throw "Format |" + fmt + "| unterminated string at " + in_str;
if(in_str !=-1) throw new Error("Format |" + fmt + "| unterminated string at " + in_str);
return out;
}
SSF._split = split_fmt;
@ -292,7 +291,7 @@ function eval_fmt(fmt, v, opts, flen) {
switch((c = fmt[i])) {
case 'G': /* General */
if(fmt.substr(i, i+6).toLowerCase() !== "general")
throw 'unrecognized character ' + fmt[i] + ' in ' + fmt;
throw new Error('unrecognized character ' + fmt[i] + ' in ' +fmt);
out.push({t:'G',v:'General'}); i+=7; break;
case '"': /* Literal text */
for(o="";fmt[++i] !== '"' && i < fmt.length;) o += fmt[i];
@ -335,7 +334,7 @@ function eval_fmt(fmt, v, opts, flen) {
} else { o=""; }
break;
/* Numbers */
case '0': case '#':
case '0': case '#': case '.':
o = c; while("0#?.,E+-%".indexOf(c=fmt[++i]) > -1) o += c;
out.push({t:'n', v:o}); break;
case '?':

@ -1 +1 @@
XLSX.version = '0.5.7';
XLSX.version = '0.5.8';

@ -16,7 +16,7 @@ function parse_sty_bin(data) {
for(var y in SSF._table) styles.NumberFmt[y] = SSF._table[y];
styles.CellXf = [];
var state = "";
var state = ""; /* TODO: this should be a stack */
var pass = false;
recordhopper(data, function(val, R, RT) {
switch(R.n) {
@ -35,8 +35,14 @@ function parse_sty_bin(data) {
case 'BrtStyle': break; /* TODO */
case 'BrtRowHdr': break; /* TODO */
case 'BrtCellMeta': break; /* ?? */
case 'BrtDXF': break; /* TODO */
case 'BrtMRUColor': break; /* TODO */
case 'BrtIndexedColor': break; /* TODO */
case 'BrtBeginStyleSheet': break;
case 'BrtEndStyleSheet': break;
case 'BrtBeginTableStyle': break;
case 'BrtTableStyleElement': break;
case 'BrtEndTableStyle': break;
case 'BrtBeginFmts': state = "FMTS"; break;
case 'BrtEndFmts': state = ""; break;
case 'BrtBeginFonts': state = "FONTS"; break;
@ -57,6 +63,12 @@ function parse_sty_bin(data) {
case 'BrtEndDXFs': state = ""; break;
case 'BrtBeginTableStyles': state = "TABLESTYLES"; break;
case 'BrtEndTableStyles': state = ""; break;
case 'BrtBeginColorPalette': state = "COLORPALETTE"; break;
case 'BrtBeginIndexedColors': state = "INDEXEDCOLORS"; break;
case 'BrtEndIndexedColors': state = ""; break;
case 'BrtBeginMRUColors': state = "MRUCOLORS"; break;
case 'BrtEndMRUColors': state = ""; break;
case 'BrtEndColorPalette': state = ""; break;
case 'BrtFRTBegin': pass = true; break;
case 'BrtFRTEnd': pass = false; break;
//default: if(!pass) throw new Error("Unexpected record " + RT + " " + R.n);

@ -20,6 +20,11 @@ var parse_wb_bin = function(data) {
case 'BrtBeginBook': break;
case 'BrtFileVersion': break;
case 'BrtWbProp': break;
case 'BrtACBegin': break;
case 'BrtAbsPath15': break;
case 'BrtACEnd': break;
/*case 'BrtBookProtectionIso': break;*/
case 'BrtBookProtection': break;
case 'BrtBeginBookViews': break;
case 'BrtBookView': break;
case 'BrtEndBookViews': break;
@ -29,15 +34,22 @@ var parse_wb_bin = function(data) {
case 'BrtEndFnGroup': break;
case 'BrtBeginExternals': break;
case 'BrtSupSelf': break;
case 'BrtSupBookSrc': break;
case 'BrtExternSheet': break;
case 'BrtEndExternals': break;
case 'BrtName': break;
case 'BrtCalcProp': break;
case 'BrtUserBookView': break;
case 'BrtBeginPivotCacheIDs': break;
case 'BrtBeginPivotCacheID': break;
case 'BrtEndPivotCacheID': break;
case 'BrtEndPivotCacheIDs': break;
case 'BrtWebOpt': break;
case 'BrtFileRecover': break;
/*case 'BrtBeginWebPubItems': break;
case 'BrtBeginWebPubItem': break;
case 'BrtEndWebPubItem': break;
case 'BrtEndWebPubItems': break;*/
case 'BrtFRTBegin': pass = true; break;
case 'BrtFRTEnd': pass = false; break;
case 'BrtEndBook': break;

@ -9,6 +9,7 @@ function fixopts(opts) {
['bookDeps', false], /* parse calculation chains */
['bookSheets', false], /* only try to get sheet names (no Sheets) */
['bookProps', false], /* only try to get properties (no Sheets) */
['bookFiles', false], /* include raw file structure (keys, files) */
['WTF', false] /* WTF mode (throws errors) */
];

@ -85,7 +85,7 @@ function parseZip(zip, opts) {
if(dir.comments) parse_comments(zip, dir.comments, sheets, sheetRels, opts);
return {
out = {
Directory: dir,
Workbook: wb,
Props: props,
@ -95,7 +95,10 @@ function parseZip(zip, opts) {
SheetNames: props.SheetNames,
Strings: strs,
Styles: styles,
keys: keys,
files: zip.files
};
if(opts.bookFiles) {
out.keys = keys,
out.files = zip.files
}
return out;
}

@ -37,7 +37,7 @@ function sheet_to_row_object_array(sheet, opts){
if(typeof val.w !== 'undefined' && !opts.raw) { row[hdr[C]] = val.w; isempty = false; }
else switch(val.t){
case 's': case 'str': case 'b': case 'n':
if(val.v !== undefined) {
if(typeof val.v !== 'undefined') {
row[hdr[C]] = val.v;
isempty = false;
}
@ -68,6 +68,7 @@ function sheet_to_csv(sheet, opts) {
if(!sheet || !sheet["!ref"]) return out;
var r = XLSX.utils.decode_range(sheet["!ref"]);
var fs = opts.FS||",", rs = opts.RS||"\n";
for(var R = r.s.r; R <= r.e.r; ++R) {
var row = [];
for(var C = r.s.c; C <= r.e.c; ++C) {
@ -90,8 +91,8 @@ function get_formulae(ws) {
var x = ws[y];
var val = "";
if(x.f) val = x.f;
else if(typeof x.w !== 'undefined') val = "'" + x.w;
else if(typeof x.v === 'undefined') continue;
else if(typeof x.v === 'number') val = x.v;
else val = x.v;
cmds.push(y + "=" + val);
}

17
dist/LICENSE vendored Normal file

@ -0,0 +1,17 @@
Copyright (C) 2012-2014 SheetJS
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Except where noted, this license applies to any and all software programs and associated documentation files created by the Original Author and distributed with the Software:
'jszip.js' is a modified version of JSZip, Copyright (c) Stuart Knightley, David Duponchel, Franz Buchinger, Ant'onio Afonso. JSZip is dual licensed and is used according to the terms of the MIT License.

2963
dist/xlsx.js vendored Normal file

File diff suppressed because it is too large Load Diff

5
dist/xlsx.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/xlsx.min.map vendored Normal file

File diff suppressed because one or more lines are too long

@ -1,6 +1,6 @@
{
"name": "xlsx",
"version": "0.5.7",
"version": "0.5.8",
"author": "sheetjs",
"description": "XLSB / XLSX / XLSM parser",
"keywords": [ "xlsx", "xlsb", "xlsm", "office", "excel", "spreadsheet" ],

26
test.js

@ -63,6 +63,12 @@ function parsetest(x, wb) {
} : null);
});
});
if(!fs.existsSync(dir + '2013/' + x + '.xlsb')) return;
describe(x + '.xlsb from 2013', function() {
it('should parse', function() {
var xlsb = XLSX.readFile(dir + '2013/' + x + '.xlsb', opts);
});
});
}
describe('should parse test files', function() {
@ -163,12 +169,28 @@ describe('options', function() {
assert(typeof wb.Sheets === 'undefined');
});
it('should not generate deps by default', function() {
var wb = XLSX.readFile(dir+'formula_stress_test.xlsx');
assert(typeof wb.Deps === 'undefined' || !(wb.Deps.length>0));
});
it('bookDeps should generate deps', function() {
var wb = XLSX.readFile(dir+'formula_stress_test.xlsx', {bookDeps:true});
assert(typeof wb.Deps !== 'undefined' && wb.Deps.length > 0);
});
it('bookDeps should generate deps', function() {
it('should not generate files or keys by default', function() {
var wb = XLSX.readFile(dir+'formula_stress_test.xlsx');
assert(typeof wb.Deps === 'undefined' || !(wb.Deps.length>0));
assert(typeof wb.files === 'undefined');
assert(typeof wb.keys === 'undefined');
wb = XLSX.readFile(dir+'formula_stress_test.xlsb');
assert(typeof wb.files === 'undefined');
assert(typeof wb.keys === 'undefined');
});
it('bookFiles should generate files and keys', function() {
var wb = XLSX.readFile(dir+'formula_stress_test.xlsx', {bookFiles:true});
assert(typeof wb.files !== 'undefined');
assert(typeof wb.keys !== 'undefined');
wb = XLSX.readFile(dir+'formula_stress_test.xlsb', {bookFiles:true});
assert(typeof wb.files !== 'undefined');
assert(typeof wb.keys !== 'undefined');
});
});
});

@ -1 +1 @@
Subproject commit 09abbe1b28237722d93a8510f42c71094c1244fd
Subproject commit 15d10e8eba67bafd07a406b3345c9309739b5da1

76
xlsx.js

@ -9,7 +9,7 @@ var _strrev = function(x) { return String(x).split("").reverse().join("");};
function fill(c,l) { return new Array(l+1).join(c); }
function pad(v,d,c){var t=String(v);return t.length>=d?t:(fill(c||0,d-t.length)+t);}
function rpad(v,d,c){var t=String(v);return t.length>=d?t:(t+fill(c||0,d-t.length));}
SSF.version = '0.5.7';
SSF.version = '0.5.8';
/* Options */
var opts_fmt = {};
function fixopts(o){for(var y in opts_fmt) if(o[y]===undefined) o[y]=opts_fmt[y];}
@ -116,7 +116,7 @@ var general_fmt = function(v) {
return o.replace("e","E").replace(/\.0*$/,"").replace(/\.([0-9]*[^0])0*$/,".$1").replace(/(E[+-])([0-9])$/,"$1"+"0"+"$2");
}
if(typeof v === 'string') return v;
throw "unsupported value in General format: " + v;
throw new Error("unsupported value in General format: " + v);
};
SSF._general = general_fmt;
var parse_date_code = function parse_date_code(v,opts) {
@ -233,7 +233,7 @@ var write_num = function(type, fmt, val) {
return o.replace("e","E");
}
if(fmt[0] === "$") return "$"+write_num(type,fmt.substr(fmt[1]==' '?2:1),val);
var r, ff, aval = val < 0 ? -val : val, sign = val < 0 ? "-" : "";
var r, rr, ff, aval = val < 0 ? -val : val, sign = val < 0 ? "-" : "";
if((r = fmt.match(/# (\?+)([ ]?)\/([ ]?)(\d+)/))) {
var den = Number(r[4]), rnd = Math.round(aval * den), base = Math.floor(rnd/den);
var myn = (rnd - base*den), myd = den;
@ -246,8 +246,17 @@ var write_num = function(type, fmt, val) {
o = Math.round(val * Math.pow(10,r[1].length));
return String(o/Math.pow(10,r[1].length)).replace(/^([^\.]+)$/,"$1."+r[1]).replace(/\.$/,"."+r[1]).replace(/\.([0-9]*)$/,function($$, $1) { return "." + $1 + fill("0", r[1].length-$1.length); });
}
if((r = fmt.match(/^(0*)\.(#*)$/))) {
o = Math.round(val*Math.pow(10,r[2].length));
return String(o * Math.pow(10,-r[2].length)).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^([-]?\d*)$/,"$1.").replace(/^0\./,r[1].length?"0.":".");
}
if((r = fmt.match(/^#,##0([.]?)$/))) return sign + commaify(String(Math.round(aval)));
if((r = fmt.match(/^#,##0\.([#0]*0)$/))) {
rr = Math.round((val-Math.floor(val))*Math.pow(10,r[1].length));
return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(rr,r[1].length,0);
}
if((r = fmt.match(/^# ([?]+)([ ]?)\/([ ]?)([?]+)/))) {
var rr = Math.min(Math.max(r[1].length, r[4].length),7);
rr = Math.min(Math.max(r[1].length, r[4].length),7);
ff = frac(aval, Math.pow(10,rr)-1, true);
return sign + (ff[0]||(ff[1] ? "" : "0")) + " " + (ff[1] ? pad(ff[1],rr," ") + r[2] + "/" + r[3] + rpad(ff[2],rr," "): fill(" ", 2*rr+1 + r[2].length + r[3].length));
}
@ -256,16 +265,6 @@ var write_num = function(type, fmt, val) {
case "#.##": o = Math.round(val*100);
return String(o/100).replace(/^([^\.]+)$/,"$1.").replace(/^0\.$/,".");
case "#,###": var x = commaify(String(Math.round(aval))); return x !== "0" ? sign + x : "";
case "#,##0": return sign + commaify(String(Math.round(aval)));
case "#,##0.0": r = Math.round((val-Math.floor(val))*10); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,1,"0");
case "#,##0.00": r = Math.round((val-Math.floor(val))*100); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,2,"0");
case "#,##0.000": r = Math.round((val-Math.floor(val))*1000); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,3,0);
case "#,##0.0000": r = Math.round((val-Math.floor(val))*10000); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,4,0);
case "#,##0.00000": r = Math.round((val-Math.floor(val))*Math.pow(10,5)); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,5,0);
case "#,##0.000000": r = Math.round((val-Math.floor(val))*Math.pow(10,6)); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,6,0);
case "#,##0.0000000": r = Math.round((val-Math.floor(val))*Math.pow(10,7)); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,7,0);
case "#,##0.00000000": r = Math.round((val-Math.floor(val))*Math.pow(10,8)); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,8,0);
case "#,##0.000000000": r = Math.round((val-Math.floor(val))*Math.pow(10,9)); return val < 0 ? "-" + write_num(type, fmt, -val) : commaify(String(Math.floor(val))) + "." + pad(r,9,0);
default:
}
throw new Error("unsupported format |" + fmt + "|");
@ -282,7 +281,7 @@ function split_fmt(fmt) {
j = i+1;
}
out.push(fmt.slice(j));
if(in_str !=-1) throw "Format |" + fmt + "| unterminated string at " + in_str;
if(in_str !=-1) throw new Error("Format |" + fmt + "| unterminated string at " + in_str);
return out;
}
SSF._split = split_fmt;
@ -295,7 +294,7 @@ function eval_fmt(fmt, v, opts, flen) {
switch((c = fmt[i])) {
case 'G': /* General */
if(fmt.substr(i, i+6).toLowerCase() !== "general")
throw 'unrecognized character ' + fmt[i] + ' in ' + fmt;
throw new Error('unrecognized character ' + fmt[i] + ' in ' +fmt);
out.push({t:'G',v:'General'}); i+=7; break;
case '"': /* Literal text */
for(o="";fmt[++i] !== '"' && i < fmt.length;) o += fmt[i];
@ -338,7 +337,7 @@ function eval_fmt(fmt, v, opts, flen) {
} else { o=""; }
break;
/* Numbers */
case '0': case '#':
case '0': case '#': case '.':
o = c; while("0#?.,E+-%".indexOf(c=fmt[++i]) > -1) o += c;
out.push({t:'n', v:o}); break;
case '?':
@ -424,7 +423,7 @@ SSF.load_table = function(tbl) { for(var i=0; i!=0x0188; ++i) if(tbl[i]) SSF.loa
make_ssf(SSF);
var XLSX = {};
(function(XLSX){
XLSX.version = '0.5.7';
XLSX.version = '0.5.8';
var current_codepage, current_cptable, cptable;
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') cptable = require('codepage');
@ -982,7 +981,7 @@ function parse_sty_bin(data) {
for(var y in SSF._table) styles.NumberFmt[y] = SSF._table[y];
styles.CellXf = [];
var state = "";
var state = ""; /* TODO: this should be a stack */
var pass = false;
recordhopper(data, function(val, R, RT) {
switch(R.n) {
@ -1001,8 +1000,14 @@ function parse_sty_bin(data) {
case 'BrtStyle': break; /* TODO */
case 'BrtRowHdr': break; /* TODO */
case 'BrtCellMeta': break; /* ?? */
case 'BrtDXF': break; /* TODO */
case 'BrtMRUColor': break; /* TODO */
case 'BrtIndexedColor': break; /* TODO */
case 'BrtBeginStyleSheet': break;
case 'BrtEndStyleSheet': break;
case 'BrtBeginTableStyle': break;
case 'BrtTableStyleElement': break;
case 'BrtEndTableStyle': break;
case 'BrtBeginFmts': state = "FMTS"; break;
case 'BrtEndFmts': state = ""; break;
case 'BrtBeginFonts': state = "FONTS"; break;
@ -1023,6 +1028,12 @@ function parse_sty_bin(data) {
case 'BrtEndDXFs': state = ""; break;
case 'BrtBeginTableStyles': state = "TABLESTYLES"; break;
case 'BrtEndTableStyles': state = ""; break;
case 'BrtBeginColorPalette': state = "COLORPALETTE"; break;
case 'BrtBeginIndexedColors': state = "INDEXEDCOLORS"; break;
case 'BrtEndIndexedColors': state = ""; break;
case 'BrtBeginMRUColors': state = "MRUCOLORS"; break;
case 'BrtEndMRUColors': state = ""; break;
case 'BrtEndColorPalette': state = ""; break;
case 'BrtFRTBegin': pass = true; break;
case 'BrtFRTEnd': pass = false; break;
//default: if(!pass) throw new Error("Unexpected record " + RT + " " + R.n);
@ -1797,6 +1808,11 @@ var parse_wb_bin = function(data) {
case 'BrtBeginBook': break;
case 'BrtFileVersion': break;
case 'BrtWbProp': break;
case 'BrtACBegin': break;
case 'BrtAbsPath15': break;
case 'BrtACEnd': break;
/*case 'BrtBookProtectionIso': break;*/
case 'BrtBookProtection': break;
case 'BrtBeginBookViews': break;
case 'BrtBookView': break;
case 'BrtEndBookViews': break;
@ -1806,15 +1822,22 @@ var parse_wb_bin = function(data) {
case 'BrtEndFnGroup': break;
case 'BrtBeginExternals': break;
case 'BrtSupSelf': break;
case 'BrtSupBookSrc': break;
case 'BrtExternSheet': break;
case 'BrtEndExternals': break;
case 'BrtName': break;
case 'BrtCalcProp': break;
case 'BrtUserBookView': break;
case 'BrtBeginPivotCacheIDs': break;
case 'BrtBeginPivotCacheID': break;
case 'BrtEndPivotCacheID': break;
case 'BrtEndPivotCacheIDs': break;
case 'BrtWebOpt': break;
case 'BrtFileRecover': break;
/*case 'BrtBeginWebPubItems': break;
case 'BrtBeginWebPubItem': break;
case 'BrtEndWebPubItem': break;
case 'BrtEndWebPubItems': break;*/
case 'BrtFRTBegin': pass = true; break;
case 'BrtFRTEnd': pass = false; break;
case 'BrtEndBook': break;
@ -2679,6 +2702,7 @@ function fixopts(opts) {
['bookDeps', false], /* parse calculation chains */
['bookSheets', false], /* only try to get sheet names (no Sheets) */
['bookProps', false], /* only try to get properties (no Sheets) */
['bookFiles', false], /* include raw file structure (keys, files) */
['WTF', false] /* WTF mode (throws errors) */
];
@ -2771,7 +2795,7 @@ function parseZip(zip, opts) {
if(dir.comments) parse_comments(zip, dir.comments, sheets, sheetRels, opts);
return {
out = {
Directory: dir,
Workbook: wb,
Props: props,
@ -2781,9 +2805,12 @@ function parseZip(zip, opts) {
SheetNames: props.SheetNames,
Strings: strs,
Styles: styles,
keys: keys,
files: zip.files
};
if(opts.bookFiles) {
out.keys = keys,
out.files = zip.files
}
return out;
}
function readSync(data, options) {
var zip, d = data;
@ -2850,7 +2877,7 @@ function sheet_to_row_object_array(sheet, opts){
if(typeof val.w !== 'undefined' && !opts.raw) { row[hdr[C]] = val.w; isempty = false; }
else switch(val.t){
case 's': case 'str': case 'b': case 'n':
if(val.v !== undefined) {
if(typeof val.v !== 'undefined') {
row[hdr[C]] = val.v;
isempty = false;
}
@ -2881,6 +2908,7 @@ function sheet_to_csv(sheet, opts) {
if(!sheet || !sheet["!ref"]) return out;
var r = XLSX.utils.decode_range(sheet["!ref"]);
var fs = opts.FS||",", rs = opts.RS||"\n";
for(var R = r.s.r; R <= r.e.r; ++R) {
var row = [];
for(var C = r.s.c; C <= r.e.c; ++C) {
@ -2903,8 +2931,8 @@ function get_formulae(ws) {
var x = ws[y];
var val = "";
if(x.f) val = x.f;
else if(typeof x.w !== 'undefined') val = "'" + x.w;
else if(typeof x.v === 'undefined') continue;
else if(typeof x.v === 'number') val = x.v;
else val = x.v;
cmds.push(y + "=" + val);
}