Skip to content

Commit

Permalink
version bump 0.10.7: autocorrections for bad files
Browse files Browse the repository at this point in the history
- recalculate SSF for malformed files (fixes SheetJS#506 h/t @asksahil)
- malformed shared string (fixes SheetJS#445 h/t @ramzec)
- SSF added to TS def (fixes SheetJS#711 h/t @duckywang1)
- Norsk property names
- resolved gitbook processing issues
  • Loading branch information
SheetJSDev committed Jul 5, 2017
1 parent 739c4f2 commit 00f25cf
Show file tree
Hide file tree
Showing 38 changed files with 2,461 additions and 300 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ node_js:
matrix:
include:
- node_js: "6"
env: TZ="America/New_York"
env: TZ="America/New_York" FMTS=misc
- node_js: "8"
env: TZ="America/Los_Angeles"
- node_js: "6"
env: TZ="Europe/London"
env: TZ="Europe/London" FMTS=misc
- node_js: "8"
env: TZ="Europe/Berlin"
- node_js: "6"
env: TZ="Asia/Kolkata"
env: TZ="Asia/Kolkata" FMTS=misc
- node_js: "7"
env: TZ="Asia/Shanghai"
- node_js: "8"
env: TZ="Asia/Seoul"
env: TZ="Asia/Seoul" FMTS=misc
before_install:
- "npm install -g [email protected]"
- "npm install -g [email protected] voc"
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ readme: README.md ## Update README Table of Contents

.PHONY: book
book: readme graph ## Update summary for documentation
printf "# Summary\n\n- [xlsx](README.md#xlsx)\n" > misc/docs/SUMMARY.md
printf "# Summary\n\n- [xlsx](README.md#sheetjs-js-xlsx)\n" > misc/docs/SUMMARY.md
markdown-toc README.md | sed 's/(#/(README.md#/g'>> misc/docs/SUMMARY.md
<README.md grep -vE "(details|summary)>" > misc/docs/README.md

.PHONY: help
help:
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ enhancements, additional features by request, and dedicated support.
* [ECMAScript 5 Compatibility](#ecmascript-5-compatibility)
- [Philosophy](#philosophy)
- [Parsing Workbooks](#parsing-workbooks)
* [Complete Examples](#complete-examples)
* [Parsing Examples](#parsing-examples)
* [Streaming Read](#streaming-read)
- [Working with the Workbook](#working-with-the-workbook)
* [Complete Examples](#complete-examples-1)
* [Parsing and Writing Examples](#parsing-and-writing-examples)
- [Writing Workbooks](#writing-workbooks)
* [Complete Examples](#complete-examples-2)
* [Writing Examples](#writing-examples)
* [Streaming Write](#streaming-write)
- [Interface](#interface)
* [Parsing functions](#parsing-functions)
Expand Down Expand Up @@ -403,7 +403,7 @@ input_dom_element.addEventListener('change', handleFile, false);
</details>


### Complete Examples
### Parsing Examples

- <http://oss.sheetjs.com/js-xlsx/> HTML5 File API / Base64 Text / Web Workers

Expand Down Expand Up @@ -550,7 +550,9 @@ wb.Sheets[ws_name] = ws;
</details>


### Complete Examples
### Parsing and Writing Examples

- <http://sheetjs.com/demos/modify.html> read + modify + write files

- <https://github.com/SheetJS/js-xlsx/blob/master/bin/xlsx.njs> node

Expand Down Expand Up @@ -607,7 +609,7 @@ saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), "test.xlsx");
```
</details>

### Complete Examples
### Writing Examples

- <http://sheetjs.com/demos/table.html> exporting an HTML table
- <http://sheetjs.com/demos/writexlsx.html> generates a simple file
Expand Down
2 changes: 1 addition & 1 deletion bits/01_version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
XLSX.version = '0.10.6';
XLSX.version = '0.10.7';
4 changes: 2 additions & 2 deletions bits/22_xmlutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ var matchtag = (function() {
var vtregex = (function(){ var vt_cache = {};
return function vt_regex(bt) {
if(vt_cache[bt] !== undefined) return vt_cache[bt];
return (vt_cache[bt] = new RegExp("<(?:vt:)?" + bt + ">(.*?)</(?:vt:)?" + bt + ">", 'g') );
return (vt_cache[bt] = new RegExp("<(?:vt:)?" + bt + ">([\\s\\S]*?)</(?:vt:)?" + bt + ">", 'g') );
};})();
var vtvregex = /<\/?(?:vt:)?variant>/g, vtmregex = /<(?:vt:)([^>]*)>(.*)</;
var vtvregex = /<\/?(?:vt:)?variant>/g, vtmregex = /<(?:vt:)([^>]*)>([\s\S]*)</;
function parseVector(data) {
var h = parsexmltag(data);

Expand Down
6 changes: 3 additions & 3 deletions bits/28_binstructs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function write_UInt32LE(x/*:number*/, o) {
}

/* [MS-XLSB] 2.5.168 */
function parse_XLWideString(data)/*:string*/ {
function parse_XLWideString(data/*::, length*/)/*:string*/ {
var cchCharacters = data.read_shift(4);
return cchCharacters === 0 ? "" : data.read_shift(cchCharacters, 'dbcs');
}
Expand Down Expand Up @@ -88,7 +88,7 @@ var parse_XLSBCodeName = parse_XLWideString;
var write_XLSBCodeName = write_XLWideString;

/* [MS-XLSB] 2.5.166 */
function parse_XLNullableWideString(data)/*:string*/ {
function parse_XLNullableWideString(data/*::, length*/)/*:string*/ {
var cchCharacters = data.read_shift(4);
return cchCharacters === 0 || cchCharacters === 0xFFFFFFFF ? "" : data.read_shift(cchCharacters, 'dbcs');
}
Expand Down Expand Up @@ -129,7 +129,7 @@ function write_RkNumber(data/*:number*/, o) {


/* [MS-XLSB] 2.5.117 RfX */
function parse_RfX(data)/*:Range*/ {
function parse_RfX(data /*::, length*/)/*:Range*/ {
var cell/*:Range*/ = ({s: {}, e: {}}/*:any*/);
cell.s.r = data.read_shift(4);
cell.e.r = data.read_shift(4);
Expand Down
2 changes: 1 addition & 1 deletion bits/33_coreprops.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var CORE_PROPS_REGEX/*:Array<RegExp>*/ = (function() {
for(var i = 0; i < CORE_PROPS.length; ++i) {
var f = CORE_PROPS[i];
var g = "(?:"+ f[0].substr(0,f[0].indexOf(":")) +":)"+ f[0].substr(f[0].indexOf(":")+1);
r[i] = new RegExp("<" + g + "[^>]*>(.*)<\/" + g + ">");
r[i] = new RegExp("<" + g + "[^>]*>([\\s\\S]*?)<\/" + g + ">");
}
return r;
})();
Expand Down
4 changes: 3 additions & 1 deletion bits/34_extprops.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function parse_ext_props(data, p) {
case "string": p[f[1]] = (data.match(matchtag(f[0]))||[])[1]; break;
case "bool": p[f[1]] = (data.match(matchtag(f[0]))||[])[1] === "true"; break;
case "raw":
var cur = data.match(new RegExp("<" + f[0] + "[^>]*>(.*)<\/" + f[0] + ">"));
var cur = data.match(new RegExp("<" + f[0] + "[^>]*>([\\s\\S]*?)<\/" + f[0] + ">"));
if(cur && cur.length > 0) q[f[1]] = cur[1];
break;
}
Expand All @@ -49,13 +49,15 @@ function parse_ext_props(data, p) {
case "Fogli di lavoro":
case "Folhas de cálculo":
case "Planilhas":
case "Regneark":
case "Werkbladen":
p.Worksheets = len;
p.SheetNames = parts.slice(idx, idx + len);
break;

case "Named Ranges":
case "Benannte Bereiche":
case "Navngivne områder":
p.NamedRanges = len;
p.DefinedNames = parts.slice(idx, idx + len);
break;
Expand Down
12 changes: 6 additions & 6 deletions bits/38_xlstypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function parse_VtVector(blob, cb) {
}

/* [MS-OLEPS] 2.15 TypedPropertyValue */
function parse_TypedPropertyValue(blob, type, _opts) {
function parse_TypedPropertyValue(blob, type/*:number*/, _opts) {
var t = blob.read_shift(2), ret, opts = _opts||{};
blob.l += 2;
if(type !== VT_VARIANT)
Expand All @@ -124,7 +124,7 @@ function parse_TypedPropertyValue(blob, type, _opts) {
case 0x41 /*VT_BLOB*/: return parse_BLOB(blob);
case 0x47 /*VT_CF*/: return parse_ClipboardData(blob);
case 0x50 /*VT_STRING*/: return parse_VtString(blob, t, !opts.raw && 4).replace(chr0,'');
case 0x51 /*VT_USTR*/: return parse_VtUnalignedString(blob, t, 4).replace(chr0,'');
case 0x51 /*VT_USTR*/: return parse_VtUnalignedString(blob, t/*, 4*/).replace(chr0,'');
case 0x100C /*VT_VECTOR|VT_VARIANT*/: return parse_VtVecHeadingPair(blob);
case 0x101E /*VT_LPSTR*/: return parse_VtVecUnalignedLpstr(blob);
default: throw new Error("TypedPropertyValue unrecognized type " + type + " " + t);
Expand Down Expand Up @@ -277,16 +277,16 @@ function parslurp(blob, length, cb) {

function parsebool(blob, length) { return blob.read_shift(length) === 0x1; }

function parseuint16(blob) { return blob.read_shift(2, 'u'); }
function parseuint16a(blob, length) { return parslurp(blob,length,parseuint16);}
function parseuint16(blob/*::, length:?number, opts:?any*/) { return blob.read_shift(2, 'u'); }
function parseuint16a(blob, length/*:: :?number, opts:?any*/) { return parslurp(blob,length,parseuint16);}

/* --- 2.5 Structures --- */

/* [MS-XLS] 2.5.14 Boolean */
var parse_Boolean = parsebool;

/* [MS-XLS] 2.5.10 Bes (boolean or error) */
function parse_Bes(blob) {
function parse_Bes(blob/*::, length*/) {
var v = blob.read_shift(1), t = blob.read_shift(1);
return t === 0x01 ? v : v === 0x01;
}
Expand Down Expand Up @@ -360,7 +360,7 @@ function parse_XLUnicodeString2(blob, length, opts) {
var parse_ControlInfo = parsenoop;

/* [MS-OSHARED] 2.3.7.6 URLMoniker TODO: flags */
var parse_URLMoniker = function(blob/*, length, opts*/) {
var parse_URLMoniker = function(blob/*::, length, opts*/) {
var len = blob.read_shift(4), start = blob.l;
var extra = false;
if(len > 24) {
Expand Down
8 changes: 4 additions & 4 deletions bits/40_harb.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ var SYLK = (function() {
return [arr, sht];
}

function sylk_to_sheet(str/*:string*/, opts)/*:Worksheet*/ {
var aoasht = sylk_to_aoa(str, opts);
function sylk_to_sheet(d/*:RawData*/, opts)/*:Worksheet*/ {
var aoasht = sylk_to_aoa(d, opts);
var aoa = aoasht[0], ws = aoasht[1];
var o = aoa_to_sheet(aoa, opts);
keys(ws).forEach(function(k) { o[k] = ws[k]; });
return o;
}

function sylk_to_workbook(str/*:string*/, opts)/*:Workbook*/ { return sheet_to_workbook(sylk_to_sheet(str, opts), opts); }
function sylk_to_workbook(d/*:RawData*/, opts)/*:Workbook*/ { return sheet_to_workbook(sylk_to_sheet(d, opts), opts); }

function write_ws_cell_sylk(cell/*:Cell*/, ws/*:Worksheet*/, R/*:number*/, C/*:number*/, opts)/*:string*/ {
var o = "C;Y" + (R+1) + ";X" + (C+1) + ";K";
Expand Down Expand Up @@ -580,7 +580,7 @@ var PRN = (function() {
return prn_to_sheet_str(str, opts);
}

function prn_to_workbook(str/*:string*/, opts)/*:Workbook*/ { return sheet_to_workbook(prn_to_sheet(str, opts), opts); }
function prn_to_workbook(d/*:RawData*/, opts)/*:Workbook*/ { return sheet_to_workbook(prn_to_sheet(d, opts), opts); }

function sheet_to_prn(ws/*:Worksheet*/, opts/*:?any*/)/*:string*/ {
var o/*:Array<string>*/ = [];
Expand Down
2 changes: 1 addition & 1 deletion bits/42_sstxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ var parse_rs = (function parse_rs_factory() {

/* 18.4.8 si CT_Rst */
var sitregex = /<(?:\w+:)?t[^>]*>([^<]*)<\/(?:\w+:)?t>/g, sirregex = /<(?:\w+:)?r>/;
var sirphregex = /<(?:\w+:)?rPh.*?>(.*?)<\/(?:\w+:)?rPh>/g;
var sirphregex = /<(?:\w+:)?rPh.*?>([\s\S]*?)<\/(?:\w+:)?rPh>/g;
function parse_si(x, opts) {
var html = opts ? opts.cellHTML : true;
var z = {};
Expand Down
55 changes: 35 additions & 20 deletions bits/47_styxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,48 @@ function parse_borders(t, styles, themes, opts) {
case '</border>': break;

/* note: not in spec, appears to be CT_BorderPr */
case '<left': case '<left/>': break;
case '<left/>': break;
case '<left': case '<left>': break;
case '</left>': break;

/* note: not in spec, appears to be CT_BorderPr */
case '<right': case '<right/>': break;
case '<right/>': break;
case '<right': case '<right>': break;
case '</right>': break;

/* 18.8.43 top CT_BorderPr */
case '<top': case '<top/>': break;
case '<top/>': break;
case '<top': case '<top>': break;
case '</top>': break;

/* 18.8.6 bottom CT_BorderPr */
case '<bottom': case '<bottom/>': break;
case '<bottom/>': break;
case '<bottom': case '<bottom>': break;
case '</bottom>': break;

/* 18.8.13 diagonal CT_BorderPr */
case '<diagonal': case '<diagonal/>': break;
case '<diagonal': case '<diagonal>': case '<diagonal/>': break;
case '</diagonal>': break;

/* 18.8.25 horizontal CT_BorderPr */
case '<horizontal': case '<horizontal/>': break;
case '<horizontal': case '<horizontal>': case '<horizontal/>': break;
case '</horizontal>': break;

/* 18.8.44 vertical CT_BorderPr */
case '<vertical': case '<vertical/>': break;
case '<vertical': case '<vertical>': case '<vertical/>': break;
case '</vertical>': break;

/* 18.8.37 start CT_BorderPr */
case '<start': case '<start/>': break;
case '<start': case '<start>': case '<start/>': break;
case '</start>': break;

/* 18.8.16 end CT_BorderPr */
case '<end': case '<end/>': break;
case '<end': case '<end>': case '<end/>': break;
case '</end>': break;

/* 18.8.? color CT_Color */
case '<color': case '<color/>': break;
case '</color>': break;
case '<color': case '<color>': break;
case '<color/>': case '</color>': break;

default: if(opts && opts.WTF) throw new Error('unrecognized ' + y[0] + ' in borders');
}
Expand All @@ -71,7 +75,7 @@ function parse_fills(t, styles, themes, opts) {
case '<fills': case '<fills>': case '</fills>': break;

/* 18.8.20 fill CT_Fill */
case '<fill>': break;
case '<fill>': case '<fill': break;
case '</fill>': styles.Fills.push(fill); fill = {}; break;

/* 18.8.24 gradientFill CT_GradientFill */
Expand Down Expand Up @@ -204,7 +208,7 @@ function parse_fonts(t, styles, themes, opts) {
if(!font.color) font.color = {};
if(y.auto) font.color.auto = parsexmlbool(y.auto);

if(y.rgb) font.color.rgb = y.rgb;
if(y.rgb) font.color.rgb = y.rgb.slice(-6);
else if(y.indexed) {
font.color.index = parseInt(y.indexed, 10);
var icv = XLSIcv[font.color.index];
Expand Down Expand Up @@ -240,7 +244,14 @@ function parse_numFmts(t, styles, opts) {
case '<numFmts': case '</numFmts>': case '<numFmts/>': case '<numFmts>': break;
case '<numFmt': {
var f=unescapexml(utf8read(y.formatCode)), j=parseInt(y.numFmtId,10);
styles.NumberFmt[j] = f; if(j>0) SSF.load(f,j);
styles.NumberFmt[j] = f;
if(j>0) {
if(j > 0x188) {
for(j = 0x188; j > 0x3c; --j) if(styles.NumberFmt[j] == null) break;
styles.NumberFmt[j] = f;
}
SSF.load(f,j);
}
} break;
case '</numFmt>': break;
default: if(opts.WTF) throw new Error('unrecognized ' + y[0] + ' in numFmts');
Expand Down Expand Up @@ -271,13 +282,16 @@ function parse_cellXfs(t, styles, opts) {
case '<cellXfs': case '<cellXfs>': case '<cellXfs/>': case '</cellXfs>': break;

/* 18.8.45 xf CT_Xf */
case '<xf':
case '<xf': case '<xf/>':
xf = y;
delete xf[0];
for(i = 0; i < cellXF_uint.length; ++i) if(xf[cellXF_uint[i]])
xf[cellXF_uint[i]] = parseInt(xf[cellXF_uint[i]], 10);
for(i = 0; i < cellXF_bool.length; ++i) if(xf[cellXF_bool[i]])
xf[cellXF_bool[i]] = parsexmlbool(xf[cellXF_bool[i]], "");
if(xf.numFmtId > 0x188) {
for(i = 0x188; i > 0x3c; --i) if(styles.NumberFmt[xf.numFmtId] == styles.NumberFmt[i]) { xf.numFmtId = i; break; }
}
styles.CellXf.push(xf); break;
case '</xf>': break;

Expand Down Expand Up @@ -316,15 +330,16 @@ function write_cellXfs(cellXfs)/*:string*/ {

/* 18.8 Styles CT_Stylesheet*/
var parse_sty_xml= (function make_pstyx() {
var numFmtRegex = /<numFmts([^>]*)>.*<\/numFmts>/;
var cellXfRegex = /<cellXfs([^>]*)>.*<\/cellXfs>/;
var fillsRegex = /<fills([^>]*)>.*<\/fills>/;
var fontsRegex = /<fonts([^>]*)>.*<\/fonts>/;
var bordersRegex = /<borders([^>]*)>.*<\/borders>/;
var numFmtRegex = /<numFmts([^>]*)>[\S\s]*?<\/numFmts>/;
var cellXfRegex = /<cellXfs([^>]*)>[\S\s]*?<\/cellXfs>/;
var fillsRegex = /<fills([^>]*)>[\S\s]*?<\/fills>/;
var fontsRegex = /<fonts([^>]*)>[\S\s]*?<\/fonts>/;
var bordersRegex = /<borders([^>]*)>[\S\s]*?<\/borders>/;

return function parse_sty_xml(data, themes, opts) {
var styles = {};
if(!data) return styles;
data = data.replace(/<!--([\s\S]*?)-->/mg,"").replace(/<!DOCTYPE[^\[]*\[[^\]]*\]>/gm,"");
/* 18.8.39 styleSheet CT_Stylesheet */
var t;

Expand Down
4 changes: 2 additions & 2 deletions bits/48_stybin.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ function parse_sty_bin(data, themes, opts) {
function write_FMTS_bin(ba, NF/*:?SSFTable*/) {
if(!NF) return;
var cnt = 0;
[[5,8],[23,26],[41,44],[/*63*/57,/*66],[164,*/392]].forEach(function(r) {
[[5,8],[23,26],[41,44],[/*63*/50,/*66],[164,*/392]].forEach(function(r) {
/*:: if(!NF) return; */
for(var i = r[0]; i <= r[1]; ++i) if(NF[i] != null) ++cnt;
});

if(cnt == 0) return;
write_record(ba, "BrtBeginFmts", write_UInt32LE(cnt));
[[5,8],[23,26],[41,44],[/*63*/57,/*66],[164,*/392]].forEach(function(r) {
[[5,8],[23,26],[41,44],[/*63*/50,/*66],[164,*/392]].forEach(function(r) {
/*:: if(!NF) return; */
for(var i = r[0]; i <= r[1]; ++i) if(NF[i] != null) write_record(ba, "BrtFmt", write_BrtFmt(i, NF[i]));
});
Expand Down
Loading

0 comments on commit 00f25cf

Please sign in to comment.