Skip to content

Commit

Permalink
version bump 0.12.13: sylk niggles
Browse files Browse the repository at this point in the history
- sylk column-major order support
- third-party extensions in SST
- `string` type codepage
  • Loading branch information
SheetJSDev committed May 20, 2018
1 parent c0b4895 commit 233102d
Show file tree
Hide file tree
Showing 21 changed files with 193 additions and 101 deletions.
2 changes: 1 addition & 1 deletion bits/01_version.js
@@ -1 +1 @@
XLSX.version = '0.12.12';
XLSX.version = '0.12.13';
1 change: 0 additions & 1 deletion bits/22_xmlutils.js
Expand Up @@ -152,7 +152,6 @@ if(has_buf) {
};
var corpus = "foo bar baz\u00e2\u0098\u0083\u00f0\u009f\u008d\u00a3";
if(utf8read(corpus) == utf8readb(corpus)) utf8read = utf8readb;
// $FlowIgnore
var utf8readc = function utf8readc(data) { return Buffer.from(data, 'binary').toString('utf8'); };
if(utf8read(corpus) == utf8readc(corpus)) utf8read = utf8readc;

Expand Down
4 changes: 2 additions & 2 deletions bits/29_xlsenum.js
Expand Up @@ -105,8 +105,8 @@ var SpecialProperties = {
DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y];
})();

var DocSummaryRE = evert_key(DocSummaryPIDDSI, "n");
var SummaryRE = evert_key(SummaryPIDSI, "n");
var DocSummaryRE/*:{[key:string]:string}*/ = evert_key(DocSummaryPIDDSI, "n");
var SummaryRE/*:{[key:string]:string}*/ = evert_key(SummaryPIDSI, "n");

/* [MS-XLS] 2.4.63 Country/Region codes */
var CountryEnum = {
Expand Down
13 changes: 9 additions & 4 deletions bits/38_xlstypes.js
Expand Up @@ -138,9 +138,10 @@ function write_TypedPropertyValue(type/*:number*/, value) {
case 0x03 /*VT_I4*/: p.write_shift(-4, value); break;
case 0x05 /*VT_I4*/: p = new_buf(8); p.write_shift(8, value, 'f'); break;
case 0x0B /*VT_BOOL*/: p.write_shift(4, value ? 0x01 : 0x00); break;
case 0x40 /*VT_FILETIME*/: p = write_FILETIME(value); break;
case 0x40 /*VT_FILETIME*/: /*:: if(typeof value !== "string" && !(value instanceof Date)) throw "unreachable"; */ p = write_FILETIME(value); break;
case 0x1F /*VT_LPWSTR*/:
case 0x50 /*VT_STRING*/:
/*:: if(typeof value !== "string") throw "unreachable"; */
p = new_buf(4 + 2 * (value.length + 1) + (value.length % 2 ? 0 : 2));
p.write_shift(4, value.length + 1);
p.write_shift(0, value, "dbcs");
Expand Down Expand Up @@ -291,8 +292,12 @@ function write_PropertySet(entries, RE, PIDSI) {
var val = entries[i][1], idx = 0;
if(RE) {
idx = +RE[entries[i][0]];
var pinfo = PIDSI[idx];
if(pinfo.p == "version" && typeof val == "string") val = (+((val = val.split("."))[0])<<16) + (+val[1]||0);
var pinfo = (PIDSI/*:: || {}*/)[idx]/*:: || {} */;
if(pinfo.p == "version" && typeof val == "string") {
/*:: if(typeof val !== "string") throw "unreachable"; */
var arr = val.split(".");
val = ((+arr[0])<<16) + ((+arr[1])||0);
}
pr = write_TypedPropertyValue(pinfo.t, val);
} else {
var T = guess_property_type(val);
Expand Down Expand Up @@ -350,7 +355,7 @@ function parse_PropertySetStream(file, PIDSI, clsid) {
rval.FMTID = [FMTID0, FMTID1]; // TODO: verify FMTID0/1
return rval;
}
function write_PropertySetStream(entries, clsid, RE, PIDSI, entries2/*:?any*/, clsid2/*:?any*/) {
function write_PropertySetStream(entries, clsid, RE, PIDSI/*:{[key:string|number]:any}*/, entries2/*:?any*/, clsid2/*:?any*/) {
var hdr = new_buf(entries2 ? 68 : 48);
var bufs = [hdr];
hdr.write_shift(2, 0xFFFE);
Expand Down
7 changes: 4 additions & 3 deletions bits/40_harb.js
Expand Up @@ -330,11 +330,11 @@ var SYLK = (function() {
formats.push(rstr.slice(3).replace(/;;/g, ";"));
break;
case 'C':
var C_seen_K = false;
var C_seen_K = false, C_seen_X = false;
for(rj=1; rj<record.length; ++rj) switch(record[rj].charAt(0)) {
case 'X': C = parseInt(record[rj].slice(1))-1; break;
case 'X': C = parseInt(record[rj].slice(1))-1; C_seen_X = true; break;
case 'Y':
R = parseInt(record[rj].slice(1))-1; C = 0;
R = parseInt(record[rj].slice(1))-1; if(!C_seen_X) C = 0;
for(j = arr.length; j <= R; ++j) arr[j] = [];
break;
case 'K':
Expand All @@ -348,6 +348,7 @@ var SYLK = (function() {
} else if(!isNaN(fuzzydate(val).getDate())) {
val = parseDate(val);
}
if(typeof cptable !== 'undefined' && typeof val == "string" && ((opts||{}).type != "string") && (opts||{}).codepage) val = cptable.utils.decode(opts.codepage, val);
C_seen_K = true;
break;
case 'E':
Expand Down
7 changes: 6 additions & 1 deletion bits/42_sstxml.js
Expand Up @@ -4,6 +4,7 @@ var parse_rs = (function parse_rs_factory() {
/* 18.4.7 rPr CT_RPrElt */
var parse_rpr = function parse_rpr(rpr, intro, outro) {
var font = {}, cp = 65001, align = "";
var pass = false;
var m = rpr.match(tagregex), i = 0;
if(m) for(;i!=m.length; ++i) {
var y = parsexmltag(m[i]);
Expand Down Expand Up @@ -94,8 +95,12 @@ var parse_rs = (function parse_rs_factory() {
/* 18.8.35 scheme CT_FontScheme TODO */
case '<scheme': break;

/* 18.2.10 extLst CT_ExtensionList ? */
case '<extLst': case '<extLst>': case '</extLst>': break;
case '<ext': pass = true; break;
case '</ext>': pass = false; break;
default:
if(y[0].charCodeAt(1) !== 47) throw 'Unrecognized rich format ' + y[0];
if(y[0].charCodeAt(1) !== 47 && !pass) throw new Error('Unrecognized rich format ' + y[0]);
}
}
var style/*:Array<string>*/ = [];
Expand Down
4 changes: 3 additions & 1 deletion bits/76_xls.js
Expand Up @@ -873,11 +873,13 @@ function write_xls_props(wb/*:Workbook*/, cfb/*:CFBContainer*/) {
var i = 0, Keys;
if(wb.Props) {
Keys = keys(wb.Props);
// $FlowIgnore
for(i = 0; i < Keys.length; ++i) (DocSummaryRE.hasOwnProperty(Keys[i]) ? DSEntries : SummaryRE.hasOwnProperty(Keys[i]) ? SEntries : CEntries).push([Keys[i], wb.Props[Keys[i]]]);
}
if(wb.Custprops) {
Keys = keys(wb.Custprops);
for(i = 0; i < Keys.length; ++i) if(!wb.Props.hasOwnProperty(Keys[i])) (DocSummaryRE.hasOwnProperty(Keys[i]) ? DSEntries : SummaryRE.hasOwnProperty(Keys[i]) ? SEntries : CEntries).push([Keys[i], wb.Custprops[Keys[i]]]);
// $FlowIgnore
for(i = 0; i < Keys.length; ++i) if(!(wb.Props||{}).hasOwnProperty(Keys[i])) (DocSummaryRE.hasOwnProperty(Keys[i]) ? DSEntries : SummaryRE.hasOwnProperty(Keys[i]) ? SEntries : CEntries).push([Keys[i], wb.Custprops[Keys[i]]]);
}
var CEntries2 = [];
for(i = 0; i < CEntries.length; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion bits/87_read.js
Expand Up @@ -78,7 +78,7 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
if(o.dateNF) _ssfopts.dateNF = o.dateNF;
if(!o.type) o.type = (has_buf && Buffer.isBuffer(data)) ? "buffer" : "base64";
if(o.type == "file") { o.type = has_buf ? "buffer" : "binary"; d = read_binary(data); }
if(o.type == "string") { str = true; o.type = "binary"; d = bstrify(data); }
if(o.type == "string") { str = true; o.type = "binary"; o.codepage = 65001; d = bstrify(data); }
if(o.type == 'array' && typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && typeof ArrayBuffer !== 'undefined') {
// $FlowIgnore
var ab=new ArrayBuffer(3), vu=new Uint8Array(ab); vu.foo="bar";
Expand Down
22 changes: 11 additions & 11 deletions dist/xlsx.core.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

34 changes: 22 additions & 12 deletions dist/xlsx.extendscript.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions dist/xlsx.full.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

34 changes: 22 additions & 12 deletions dist/xlsx.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions dist/xlsx.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "xlsx",
"version": "0.12.12",
"version": "0.12.13",
"author": "sheetjs",
"description": "SheetJS Spreadsheet data parser and writer",
"keywords": [
Expand Down
19 changes: 19 additions & 0 deletions test.js
Expand Up @@ -1983,6 +1983,25 @@ describe('CSV', function() {
});
});

describe('sylk', function() {
var cpavail = true;
var bef = (function() {
if(typeof cptable == 'undefined') cpavail = false;
});
if(typeof before != 'undefined') before(bef);
describe('input', function(){
it('codepage', cpavail ? function() {
var str = "ID;PWXL;N;E\r\nC;X1;Y1;K\"a – b\"\r\nE", A1 = "a – b";
assert.equal(get_cell(X.read(str, {type:"string"}).Sheets.Sheet1, "A1").v, A1);
assert.equal(get_cell(X.read(str.replace(//, "\x96"), {type:"binary", codepage:1252}).Sheets.Sheet1, "A1").v, A1);
if(typeof Buffer !== 'undefined' && !browser) {
assert.equal(get_cell(X.read(Buffer.from(str), {type:"buffer", codepage:65001}).Sheets.Sheet1, "A1").v, A1);
assert.equal(get_cell(X.read(Buffer.from(str.replace(//, "\x96"), "binary"), {type:"buffer", codepage:1252}).Sheets.Sheet1, "A1").v, A1);
}
} : null);
});
});

if(fs.existsSync(dir + 'dbf/d11.dbf')) describe('dbf', function() {
var wbs/*:Array<any>*/ = ([
['d11', dir + 'dbf/d11.dbf'],
Expand Down

0 comments on commit 233102d

Please sign in to comment.