Google Docs Sheet order incompatibility

Fixes #13.

Google Docs does not emit worksheet information, and furthermore does not follow
the sheet order as prescribed in the `[Content-Types].xml` metadata.  This
workaround forces it to treat the sheet list in Workbook as the map to the files
`xl/worksheets/sheet##.xml` even though the rIds are different.
This commit is contained in:
SheetJS 2013-03-19 15:28:03 -04:00
parent 28873fc0b5
commit 91266af9aa
2 changed files with 11 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "xlsx",
"version": "0.1.2",
"version": "0.1.3",
"author": "Niggler",
"description": "(one day) a full-featured XLSX parser and writer. For now, primitive parser",
"keywords": [

15
xlsx.js
View File

@ -213,7 +213,7 @@ function parseProps(data) {
}
}
var parts = parseVector(q["TitlesOfParts"]).map(utf8read);
p["SheetNames"] = parts.slice(widx, widx + p["Worksheets"])
p["SheetNames"] = parts.slice(widx, widx + p["Worksheets"]);
}
p["Creator"] = q["dc:creator"];
p["LastModifiedBy"] = q["cp:lastModifiedBy"];
@ -322,19 +322,24 @@ function parseZip(zip) {
var deps = {};
if(dir.calcchain) deps=parseDeps(zip.files[dir.calcchain.replace(/^\//,'')].data);
if(dir.strs[0]) strs=parseStrs(zip.files[dir.strs[0].replace(/^\//,'')].data);
var sheets = {};
var sheets = {}, i=0;
if(!props.Worksheets) {
/* Google Docs doesn't generate the appropriate metadata, so we impute: */
var wbsheets = wb.Sheets;
props.Worksheets = wbsheets.length;
props.SheetNames = [];
for(var j = 0; j != wbsheets.length; ++j) {
props.SheetNames[j] = wbsheets[j].name;
}
for(i = 0; i != props.Worksheets; ++i) {
sheets[props.SheetNames[i]]=parseSheet(zip.files['xl/worksheets/sheet' + (i+1) + '.xml'].data);
}
}
for(var i = 0; i != props.Worksheets; ++i) {
sheets[props.SheetNames[i]]=parseSheet(zip.files[dir.sheets[i].replace(/^\//,'')].data);
else {
for(i = 0; i != props.Worksheets; ++i) {
sheets[props.SheetNames[i]]=parseSheet(zip.files[dir.sheets[i].replace(/^\//,'')].data);
}
}
return {
Directory: dir,
Workbook: wb,