version bump 0.4.3: shared strings and formatting

- XLSB basic support for number formats
- removed extraneous Strings table element
- formatting xml tags (rich_stress_test)
- updating test_files to 20130130
This commit is contained in:
SheetJS 2014-01-31 06:52:18 -05:00
parent bf5155dd5d
commit 5c4bf62b83
13 changed files with 187 additions and 35 deletions

@ -1 +1 @@
XLSX.version = '0.4.2';
XLSX.version = '0.4.3';

@ -6,10 +6,9 @@ var recordhopper = function(data, cb) {
var RT = data.read_shift(1);
if(RT & 0x80) RT = (RT & 0x7F) + ((data.read_shift(1) & 0x7F)<<7);
var R = RecordEnum[RT] || RecordEnum[0xFFFF];
length = tmpbyte = data.read_shift(1);
for(cntbyte = 1; cntbyte <4 && (tmpbyte & 0x80); ++cntbyte) length += ((tmpbyte = data.read_shift(1)) & 0x7F)<<(7*cntbyte);
var d = R.f(data, length);
if(cb(d, R)) return;
if(cb(d, R, RT)) return;
}
};

@ -26,7 +26,7 @@ function parse_Cell(data) {
var iStyleRef = data.read_shift(2);
iStyleRef += data.read_shift(1) <<16;
var fPhShow = data.read_shift(1);
return { c:col };
return { c:col, iStyleRef: iStyleRef };
}
/* [MS-XLSB] 2.5.21 */

@ -15,13 +15,17 @@ var parse_rs = (function() {
case '<extend': break;
/* 18.8.36 shadow CT_BooleanProperty */
/* ** not required . */
case '<shadow': break;
case '<shadow':
/* falls through */
case '<shadow/>': break;
/* 18.4.1 charset CT_IntProperty TODO */
case '<charset': break;
/* 18.4.2 outline CT_BooleanProperty TODO */
case '<outline': break;
case '<outline':
/* falls through */
case '<outline/>': break;
/* 18.4.5 rFont CT_FontName */
case '<rFont': font.name = y.val; break;
@ -103,7 +107,7 @@ var parse_rs = (function() {
/* 18.4.8 si CT_Rst */
var parse_si = function(x) {
var z = {};
if(!x) return z;
if(!x) return null;
var y;
/* 18.4.12 t ST_Xstring (Plaintext String) */
if(x[1] === 't') {
@ -129,7 +133,7 @@ var parse_sst_xml = function(data) {
/* 18.4.9 sst CT_Sst */
var sst = data.match(new RegExp("<sst([^>]*)>([\\s\\S]*)<\/sst>","m"));
if(isval(sst)) {
s = sst[2].replace(/<si>/g,"").split(/<\/si>/).map(parse_si);
s = sst[2].replace(/<si>/g,"").split(/<\/si>/).map(parse_si).filter(function(x) { return x; });
sst = parsexmltag(sst[1]); s.Count = sst.count; s.Unique = sst.uniqueCount;
}
return s;

@ -24,7 +24,8 @@ function parseCXfs(t) {
case '<cellXfs': case '<cellXfs/>': case '</cellXfs>': break;
/* 18.8.45 xf CT_Xf */
case '<xf': if(y.numFmtId) y.numFmtId = parseInt(y.numFmtId, 10);
case '<xf': delete y[0];
if(y.numFmtId) y.numFmtId = parseInt(y.numFmtId, 10);
styles.CellXf.push(y); break;
case '</xf>': break;

@ -1,3 +1,66 @@
function parse_sty_bin(data) {
function parse_BrtFmt(data, length) {
var ifmt = data.read_shift(2);
var stFmtCode = parse_XLWideString(data,length-2);
return [ifmt, stFmtCode];
}
function parse_BrtXF(data, length) {
var ixfeParent = data.read_shift(2);
var ifmt = data.read_shift(2);
parsenoop(data, length-4);
return {ixfe:ixfeParent, ifmt:ifmt };
}
function parse_sty_bin(data) {
styles.NumberFmt = [];
for(var y in SSF._table) styles.NumberFmt[y] = SSF._table[y];
styles.CellXf = [];
var state = "";
var pass = false;
recordhopper(data, function(val, R, RT) {
switch(R.n) {
case 'BrtFmt':
styles.NumberFmt[val[0]] = val[1]; SSF.load(val[1], val[0]);
break;
case 'BrtFont': break; /* TODO */
case 'BrtKnownFonts': break; /* TODO */
case 'BrtFill': break; /* TODO */
case 'BrtBorder': break; /* TODO */
case 'BrtXF':
if(state === "CELLXFS") {
styles.CellXf.push(val);
}
break; /* TODO */
case 'BrtStyle': break; /* TODO */
case 'BrtRowHdr': break; /* TODO */
case 'BrtCellMeta': break; /* ?? */
case 'BrtBeginStyleSheet': break;
case 'BrtEndStyleSheet': break;
case 'BrtBeginFmts': state = "FMTS"; break;
case 'BrtEndFmts': state = ""; break;
case 'BrtBeginFonts': state = "FONTS"; break;
case 'BrtEndFonts': state = ""; break;
case 'BrtACBegin': state = "ACFONTS"; break;
case 'BrtACEnd': state = ""; break;
case 'BrtBeginFills': state = "FILLS"; break;
case 'BrtEndFills': state = ""; break;
case 'BrtBeginBorders': state = "BORDERS"; break;
case 'BrtEndBorders': state = ""; break;
case 'BrtBeginCellStyleXFs': state = "CELLSTYLEXFS"; break;
case 'BrtEndCellStyleXFs': state = ""; break;
case 'BrtBeginCellXFs': state = "CELLXFS"; break;
case 'BrtEndCellXFs': state = ""; break;
case 'BrtBeginStyles': state = "STYLES"; break;
case 'BrtEndStyles': state = ""; break;
case 'BrtBeginDXFs': state = "DXFS"; break;
case 'BrtEndDXFs': state = ""; break;
case 'BrtBeginTableStyles': state = "TABLESTYLES"; break;
case 'BrtEndTableStyles': state = ""; break;
case 'BrtFRTBegin': pass = true; break;
case 'BrtFRTEnd': pass = false; break;
//default: if(!pass) throw new Error("Unexpected record " + RT + " " + R.n);
}
});
return styles;
}

@ -115,6 +115,9 @@ var parse_ws_bin = function(data) {
case 'str': if(p.v) p.v = utf8read(p.v); break;
}
if(val[3]) p.f = val[3];
if(styles.CellXf[val[0].iStyleRef]) try {
p.w = SSF.format(styles.CellXf[val[0].iStyleRef].ifmt,p.v,_ssfopts);
} catch(e) { }
s[encode_cell({c:val[0].c,r:row.r})] = p;
break; // TODO
@ -144,8 +147,8 @@ var parse_ws_bin = function(data) {
case 'BrtPrintOptions': break; // TODO
case 'BrtMargins': break; // TODO
case 'BrtPageSetup': break; // TODO
case 'BrtFRTBegin': pass = true; break; // TODO
case 'BrtFRTEnd': pass = false; break; // TODO
case 'BrtFRTBegin': pass = true; break;
case 'BrtFRTEnd': pass = false; break;
case 'BrtEndSheet': break; // TODO
//default: if(!pass) throw new Error("Unexpected record " + R.n);
}

@ -36,10 +36,10 @@ var RecordEnum = {
0x0028: { n:"BrtIndexRowBlock", f:parsenoop },
0x002A: { n:"BrtIndexBlock", f:parsenoop },
0x002B: { n:"BrtFont", f:parsenoop },
0x002C: { n:"BrtFmt", f:parsenoop },
0x002C: { n:"BrtFmt", f:parse_BrtFmt },
0x002D: { n:"BrtFill", f:parsenoop },
0x002E: { n:"BrtBorder", f:parsenoop },
0x002F: { n:"BrtXF", f:parsenoop },
0x002F: { n:"BrtXF", f:parse_BrtXF },
0x0030: { n:"BrtStyle", f:parsenoop },
0x0031: { n:"BrtCellMeta", f:parsenoop },
0x0032: { n:"BrtValueMeta", f:parsenoop },

@ -33,8 +33,8 @@ function sheet_to_row_object_array(sheet, opts){
for (C = r.s.c; C <= r.e.c; ++C) {
val = sheet[encode_cell({c: C,r: R})];
if(!val || !val.t) continue;
v = (val || {}).v;
switch(val.t){
if(typeof val.w !== 'undefined') { row[hdr[C]] = val.w; isempty = false; }
else switch(val.t){
case 's': case 'str': case 'b': case 'n':
if(val.v !== undefined) {
row[hdr[C]] = val.v;
@ -53,6 +53,7 @@ function sheet_to_row_object_array(sheet, opts){
function sheet_to_csv(sheet, opts) {
var stringify = function stringify(val) {
if(!val.t) return "";
if(typeof val.w !== 'undefined') return '"' + val.w.replace(/"/,'""') + '"';
switch(val.t){
case 'n': return String(val.v);
case 's': case 'str':

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

@ -1,4 +1,6 @@
formula_stress_test.xlsb
number_format.xlsb
rich_text_stress.xlsb
time_stress_test_1.xlsb
LONumbers-2010.xlsx
LONumbers-2011.xlsx
@ -41,6 +43,7 @@ apachepoi_50846-border_colours.xlsx
apachepoi_50867_with_table.xlsx
apachepoi_51222.xlsx
apachepoi_51470.xlsx
apachepoi_51585.xlsx
apachepoi_51710.xlsx
apachepoi_51850.xlsx
apachepoi_51963.xlsx
@ -122,6 +125,7 @@ apachepoi_workbookProtection_workbook_structure_protected.xlsx
apachepoi_workbookProtection_workbook_windows_protected.xlsx
apachepoi_workbookProtection_worksheet_protected.xlsx
apachepoi_xlsx-jdbc.xlsx
comments_stress_test.xlsx
excel-reader-xlsx_data01.xlsx
excel-reader-xlsx_data02.xlsx
excel-reader-xlsx_error02.xlsx.pending
@ -163,6 +167,7 @@ openpyxl_r_date_1904.xlsx
openpyxl_r_formulae.xlsx
openpyxl_r_null_archive.xlsx.pending
openpyxl_r_null_file.xlsx.pending
rich_text_stress.xlsx
roo_1900_base.xlsx
roo_1904_base.xlsx
roo_Bibelbund.xlsx
@ -195,6 +200,7 @@ spreadsheet-parsexlsx_bug-11.xlsx
spreadsheet-parsexlsx_bug-12.xlsx
spreadsheet-parsexlsx_bug-13.xlsx
spreadsheet-parsexlsx_bug-14.xlsx
spreadsheet-parsexlsx_bug-15.xlsx
spreadsheet-parsexlsx_bug-2.xlsx
spreadsheet-parsexlsx_bug-3.xlsx
spreadsheet-parsexlsx_bug-4.xlsx
@ -203,11 +209,15 @@ spreadsheet-parsexlsx_bug-6-2.xlsx
spreadsheet-parsexlsx_bug-6.xlsx
spreadsheet-parsexlsx_bug-7.xlsx
spreadsheet-parsexlsx_bug-8.xlsx
xlrd_merged_cells.xlsx
xlrd_reveng1.xlsx
xlrd_test_comments_excel.xlsx
xlrd_test_comments_gdocs.xlsx
xlrd_text_bar.xlsx
חישוב_נקודות_זיכוי.xlsx
apachepoi_45431.xlsm
apachepoi_47026.xlsm
apachepoi_47089.xlsm
apachepoi_ExcelWithAttachments.xlsm
number_format.xlsm
openpyxl_r_vba-test.xlsm

@ -1 +1 @@
Subproject commit 51eb4765cd8828155a72d5b2aa273e999daaa93e
Subproject commit a9fc7e00949b0f7621f0b51e0ed5b139bac8e109

103
xlsx.js

@ -420,7 +420,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.4.2';
XLSX.version = '0.4.3';
var current_codepage, current_cptable, cptable;
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') cptable = require('codepage');
@ -705,11 +705,10 @@ var recordhopper = function(data, cb) {
var RT = data.read_shift(1);
if(RT & 0x80) RT = (RT & 0x7F) + ((data.read_shift(1) & 0x7F)<<7);
var R = RecordEnum[RT] || RecordEnum[0xFFFF];
length = tmpbyte = data.read_shift(1);
for(cntbyte = 1; cntbyte <4 && (tmpbyte & 0x80); ++cntbyte) length += ((tmpbyte = data.read_shift(1)) & 0x7F)<<(7*cntbyte);
var d = R.f(data, length);
if(cb(d, R)) return;
if(cb(d, R, RT)) return;
}
};
/* [MS-XLSB] 2.1.7.121 */
@ -740,7 +739,7 @@ function parse_Cell(data) {
var iStyleRef = data.read_shift(2);
iStyleRef += data.read_shift(1) <<16;
var fPhShow = data.read_shift(1);
return { c:col };
return { c:col, iStyleRef: iStyleRef };
}
/* [MS-XLSB] 2.5.21 */
@ -815,13 +814,17 @@ var parse_rs = (function() {
case '<extend': break;
/* 18.8.36 shadow CT_BooleanProperty */
/* ** not required . */
case '<shadow': break;
case '<shadow':
/* falls through */
case '<shadow/>': break;
/* 18.4.1 charset CT_IntProperty TODO */
case '<charset': break;
/* 18.4.2 outline CT_BooleanProperty TODO */
case '<outline': break;
case '<outline':
/* falls through */
case '<outline/>': break;
/* 18.4.5 rFont CT_FontName */
case '<rFont': font.name = y.val; break;
@ -903,7 +906,7 @@ var parse_rs = (function() {
/* 18.4.8 si CT_Rst */
var parse_si = function(x) {
var z = {};
if(!x) return z;
if(!x) return null;
var y;
/* 18.4.12 t ST_Xstring (Plaintext String) */
if(x[1] === 't') {
@ -929,7 +932,7 @@ var parse_sst_xml = function(data) {
/* 18.4.9 sst CT_Sst */
var sst = data.match(new RegExp("<sst([^>]*)>([\\s\\S]*)<\/sst>","m"));
if(isval(sst)) {
s = sst[2].replace(/<si>/g,"").split(/<\/si>/).map(parse_si);
s = sst[2].replace(/<si>/g,"").split(/<\/si>/).map(parse_si).filter(function(x) { return x; });
sst = parsexmltag(sst[1]); s.Count = sst.count; s.Unique = sst.uniqueCount;
}
return s;
@ -985,7 +988,8 @@ function parseCXfs(t) {
case '<cellXfs': case '<cellXfs/>': case '</cellXfs>': break;
/* 18.8.45 xf CT_Xf */
case '<xf': if(y.numFmtId) y.numFmtId = parseInt(y.numFmtId, 10);
case '<xf': delete y[0];
if(y.numFmtId) y.numFmtId = parseInt(y.numFmtId, 10);
styles.CellXf.push(y); break;
case '</xf>': break;
@ -1025,8 +1029,71 @@ function parse_styles(data) {
return styles;
}
function parse_sty_bin(data) {
function parse_BrtFmt(data, length) {
var ifmt = data.read_shift(2);
var stFmtCode = parse_XLWideString(data,length-2);
return [ifmt, stFmtCode];
}
function parse_BrtXF(data, length) {
var ixfeParent = data.read_shift(2);
var ifmt = data.read_shift(2);
parsenoop(data, length-4);
return {ixfe:ixfeParent, ifmt:ifmt };
}
function parse_sty_bin(data) {
styles.NumberFmt = [];
for(var y in SSF._table) styles.NumberFmt[y] = SSF._table[y];
styles.CellXf = [];
var state = "";
var pass = false;
recordhopper(data, function(val, R, RT) {
switch(R.n) {
case 'BrtFmt':
styles.NumberFmt[val[0]] = val[1]; SSF.load(val[1], val[0]);
break;
case 'BrtFont': break; /* TODO */
case 'BrtKnownFonts': break; /* TODO */
case 'BrtFill': break; /* TODO */
case 'BrtBorder': break; /* TODO */
case 'BrtXF':
if(state === "CELLXFS") {
styles.CellXf.push(val);
}
break; /* TODO */
case 'BrtStyle': break; /* TODO */
case 'BrtRowHdr': break; /* TODO */
case 'BrtCellMeta': break; /* ?? */
case 'BrtBeginStyleSheet': break;
case 'BrtEndStyleSheet': break;
case 'BrtBeginFmts': state = "FMTS"; break;
case 'BrtEndFmts': state = ""; break;
case 'BrtBeginFonts': state = "FONTS"; break;
case 'BrtEndFonts': state = ""; break;
case 'BrtACBegin': state = "ACFONTS"; break;
case 'BrtACEnd': state = ""; break;
case 'BrtBeginFills': state = "FILLS"; break;
case 'BrtEndFills': state = ""; break;
case 'BrtBeginBorders': state = "BORDERS"; break;
case 'BrtEndBorders': state = ""; break;
case 'BrtBeginCellStyleXFs': state = "CELLSTYLEXFS"; break;
case 'BrtEndCellStyleXFs': state = ""; break;
case 'BrtBeginCellXFs': state = "CELLXFS"; break;
case 'BrtEndCellXFs': state = ""; break;
case 'BrtBeginStyles': state = "STYLES"; break;
case 'BrtEndStyles': state = ""; break;
case 'BrtBeginDXFs': state = "DXFS"; break;
case 'BrtEndDXFs': state = ""; break;
case 'BrtBeginTableStyles': state = "TABLESTYLES"; break;
case 'BrtEndTableStyles': state = ""; break;
case 'BrtFRTBegin': pass = true; break;
case 'BrtFRTEnd': pass = false; break;
//default: if(!pass) throw new Error("Unexpected record " + RT + " " + R.n);
}
});
return styles;
}
var ct2type = {
@ -1449,6 +1516,9 @@ var parse_ws_bin = function(data) {
case 'str': if(p.v) p.v = utf8read(p.v); break;
}
if(val[3]) p.f = val[3];
if(styles.CellXf[val[0].iStyleRef]) try {
p.w = SSF.format(styles.CellXf[val[0].iStyleRef].ifmt,p.v,_ssfopts);
} catch(e) { }
s[encode_cell({c:val[0].c,r:row.r})] = p;
break; // TODO
@ -1478,8 +1548,8 @@ var parse_ws_bin = function(data) {
case 'BrtPrintOptions': break; // TODO
case 'BrtMargins': break; // TODO
case 'BrtPageSetup': break; // TODO
case 'BrtFRTBegin': pass = true; break; // TODO
case 'BrtFRTEnd': pass = false; break; // TODO
case 'BrtFRTBegin': pass = true; break;
case 'BrtFRTEnd': pass = false; break;
case 'BrtEndSheet': break; // TODO
//default: if(!pass) throw new Error("Unexpected record " + R.n);
}
@ -1786,10 +1856,10 @@ var RecordEnum = {
0x0028: { n:"BrtIndexRowBlock", f:parsenoop },
0x002A: { n:"BrtIndexBlock", f:parsenoop },
0x002B: { n:"BrtFont", f:parsenoop },
0x002C: { n:"BrtFmt", f:parsenoop },
0x002C: { n:"BrtFmt", f:parse_BrtFmt },
0x002D: { n:"BrtFill", f:parsenoop },
0x002E: { n:"BrtBorder", f:parsenoop },
0x002F: { n:"BrtXF", f:parsenoop },
0x002F: { n:"BrtXF", f:parse_BrtXF },
0x0030: { n:"BrtStyle", f:parsenoop },
0x0031: { n:"BrtCellMeta", f:parsenoop },
0x0032: { n:"BrtValueMeta", f:parsenoop },
@ -2698,8 +2768,8 @@ function sheet_to_row_object_array(sheet, opts){
for (C = r.s.c; C <= r.e.c; ++C) {
val = sheet[encode_cell({c: C,r: R})];
if(!val || !val.t) continue;
v = (val || {}).v;
switch(val.t){
if(typeof val.w !== 'undefined') { row[hdr[C]] = val.w; isempty = false; }
else switch(val.t){
case 's': case 'str': case 'b': case 'n':
if(val.v !== undefined) {
row[hdr[C]] = val.v;
@ -2718,6 +2788,7 @@ function sheet_to_row_object_array(sheet, opts){
function sheet_to_csv(sheet, opts) {
var stringify = function stringify(val) {
if(!val.t) return "";
if(typeof val.w !== 'undefined') return '"' + val.w.replace(/"/,'""') + '"';
switch(val.t){
case 'n': return String(val.v);
case 's': case 'str':