Comparing version 0.5.7 to 0.5.8
@@ -9,3 +9,3 @@ /* Spreadsheet Format -- jump to XLSX for the XLSX code */ | ||
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 */ | ||
@@ -117,3 +117,3 @@ var opts_fmt = {}; | ||
if(typeof v === 'string') return v; | ||
throw "unsupported value in General format: " + v; | ||
throw new Error("unsupported value in General format: " + v); | ||
}; | ||
@@ -235,3 +235,3 @@ SSF._general = general_fmt; | ||
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+)/))) { | ||
@@ -249,4 +249,13 @@ var den = Number(r[4]), rnd = Math.round(aval * den), base = Math.floor(rnd/den); | ||
} | ||
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); | ||
@@ -260,12 +269,2 @@ 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)); | ||
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: | ||
@@ -287,3 +286,3 @@ } | ||
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; | ||
@@ -301,3 +300,3 @@ } | ||
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; | ||
@@ -345,3 +344,3 @@ case '"': /* Literal text */ | ||
/* Numbers */ | ||
case '0': case '#': | ||
case '0': case '#': case '.': | ||
o = c; while("0#?.,E+-%".indexOf(c=fmt[++i]) > -1) o += c; | ||
@@ -348,0 +347,0 @@ out.push({t:'n', v:o}); break; |
@@ -1,1 +0,1 @@ | ||
XLSX.version = '0.5.7'; | ||
XLSX.version = '0.5.8'; |
@@ -19,3 +19,3 @@ function parse_BrtFmt(data, length) { | ||
styles.CellXf = []; | ||
var state = ""; | ||
var state = ""; /* TODO: this should be a stack */ | ||
var pass = false; | ||
@@ -39,4 +39,10 @@ recordhopper(data, function(val, R, RT) { | ||
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; | ||
@@ -62,2 +68,8 @@ case 'BrtEndFmts': state = ""; 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; | ||
@@ -64,0 +76,0 @@ case 'BrtFRTEnd': pass = false; break; |
@@ -23,2 +23,7 @@ /* [MS-XLSB] 2.4.301 BrtBundleSh */ | ||
case 'BrtWbProp': break; | ||
case 'BrtACBegin': break; | ||
case 'BrtAbsPath15': break; | ||
case 'BrtACEnd': break; | ||
/*case 'BrtBookProtectionIso': break;*/ | ||
case 'BrtBookProtection': break; | ||
case 'BrtBeginBookViews': break; | ||
@@ -33,2 +38,3 @@ case 'BrtBookView': break; | ||
case 'BrtSupSelf': break; | ||
case 'BrtSupBookSrc': break; | ||
case 'BrtExternSheet': break; | ||
@@ -38,2 +44,3 @@ case 'BrtEndExternals': break; | ||
case 'BrtCalcProp': break; | ||
case 'BrtUserBookView': break; | ||
case 'BrtBeginPivotCacheIDs': break; | ||
@@ -43,3 +50,8 @@ case 'BrtBeginPivotCacheID': 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; | ||
@@ -46,0 +58,0 @@ case 'BrtFRTEnd': pass = false; break; |
@@ -12,2 +12,3 @@ function fixopts(opts) { | ||
['bookProps', false], /* only try to get properties (no Sheets) */ | ||
['bookFiles', false], /* include raw file structure (keys, files) */ | ||
@@ -14,0 +15,0 @@ ['WTF', false] /* WTF mode (throws errors) */ |
@@ -88,3 +88,3 @@ function parseZip(zip, opts) { | ||
return { | ||
out = { | ||
Directory: dir, | ||
@@ -99,5 +99,8 @@ Workbook: wb, | ||
Styles: styles, | ||
keys: keys, | ||
files: zip.files | ||
}; | ||
if(opts.bookFiles) { | ||
out.keys = keys, | ||
out.files = zip.files | ||
} | ||
return out; | ||
} |
@@ -40,3 +40,3 @@ var _chr = function(c) { return String.fromCharCode(c); }; | ||
case 's': case 'str': case 'b': case 'n': | ||
if(val.v !== undefined) { | ||
if(typeof val.v !== 'undefined') { | ||
row[hdr[C]] = val.v; | ||
@@ -72,2 +72,3 @@ isempty = false; | ||
var fs = opts.FS||",", rs = opts.RS||"\n"; | ||
for(var R = r.s.r; R <= r.e.r; ++R) { | ||
@@ -95,4 +96,4 @@ var row = []; | ||
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; | ||
@@ -99,0 +100,0 @@ cmds.push(y + "=" + val); |
{ | ||
"name": "xlsx", | ||
"version": "0.5.7", | ||
"version": "0.5.8", | ||
"author": "sheetjs", | ||
@@ -5,0 +5,0 @@ "description": "XLSB / XLSX / XLSM parser", |
26
test.js
@@ -66,2 +66,8 @@ /* vim: set ts=2: */ | ||
}); | ||
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); | ||
}); | ||
}); | ||
} | ||
@@ -167,9 +173,25 @@ | ||
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'); | ||
}); | ||
}); | ||
@@ -176,0 +198,0 @@ }); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
647480
60
11178
8