forked from sheetjs/sheetjs
version bump 0.3.2: cleanup
- updated jszip to version 2 (20121106) - added some .match guards (2) - updated package.json
This commit is contained in:
parent
9e41edcbd2
commit
0b642080bf
@ -2,7 +2,7 @@ function parsexmltag(tag) {
|
||||
var words = tag.split(/\s+/);
|
||||
var z = {'0': words[0]};
|
||||
if(words.length === 1) return z;
|
||||
tag.match(/(\w+)="([^"]*)"/g).map(
|
||||
(tag.match(/(\w+)="([^"]*)"/g) || []).map(
|
||||
function(x){var y=x.match(/(\w+)="([^"]*)"/); z[y[1]] = y[2]; });
|
||||
return z;
|
||||
}
|
||||
@ -53,7 +53,7 @@ function matchtag(f,g) {return new RegExp('<'+f+'(?: xml:space="preserve")?>([^\
|
||||
function parseVector(data) {
|
||||
var h = parsexmltag(data);
|
||||
|
||||
var matches = data.match(new RegExp("<vt:" + h.baseType + ">(.*?)</vt:" + h.baseType + ">", 'g'));
|
||||
var matches = data.match(new RegExp("<vt:" + h.baseType + ">(.*?)</vt:" + h.baseType + ">", 'g'))||[];
|
||||
if(matches.length != h.size) throw "unexpected vector length " + matches.length + " != " + h.size;
|
||||
var res = [];
|
||||
matches.forEach(function(x) {
|
||||
|
@ -6,7 +6,7 @@ var parse_sst = (function(){
|
||||
/* 18.4.7 rPr CT_RPrElt */
|
||||
var parse_rpr = function(rpr, intro, outro) {
|
||||
var font = {};
|
||||
rpr.match(/<[^>]*>/g).forEach(function(x) {
|
||||
(rpr.match(/<[^>]*>/g)||[]).forEach(function(x) {
|
||||
var y = parsexmltag(x);
|
||||
switch(y[0]) {
|
||||
/* 18.8.12 condense CT_BooleanProperty */
|
||||
@ -130,7 +130,7 @@ var parse_sst = (function(){
|
||||
var s = [];
|
||||
/* 18.4.9 sst CT_Sst */
|
||||
var sst = data.match(new RegExp("<sst([^>]*)>([\\s\\S]*)<\/sst>","m"));
|
||||
if(sst) {
|
||||
if(isval(sst)) {
|
||||
s = sst[2].replace(/<si>/g,"").split(/<\/si>/).map(parse_si);
|
||||
sst = parsexmltag(sst[1]); s.Count = sst.count; s.Unique = sst.uniqueCount;
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ function parseProps(data) {
|
||||
function parseDeps(data) {
|
||||
var d = [];
|
||||
var l = 0, i = 1;
|
||||
data.match(/<[^>]*>/g).forEach(function(x) {
|
||||
(data.match(/<[^>]*>/g)||[]).forEach(function(x) {
|
||||
var y = parsexmltag(x);
|
||||
switch(y[0]) {
|
||||
case '<?xml': break;
|
||||
@ -445,23 +445,30 @@ function parseStyles(data) {
|
||||
return styles;
|
||||
}
|
||||
|
||||
function getdata(data) {
|
||||
if(!data) return {};
|
||||
if(data.data) return data.data;
|
||||
if(data._data && data._data.getContent) return Array.prototype.slice.call(data._data.getContent(),0).map(function(x) { return String.fromCharCode(x); }).join("");
|
||||
return {};
|
||||
}
|
||||
|
||||
function parseZip(zip) {
|
||||
var entries = Object.keys(zip.files);
|
||||
var keys = entries.filter(function(x){return x.substr(-1) != '/';}).sort();
|
||||
var dir = parseCT((zip.files['[Content_Types].xml']||{}).data);
|
||||
var dir = parseCT(getdata(zip.files['[Content_Types].xml']));
|
||||
|
||||
strs = {};
|
||||
if(dir.sst) strs=parse_sst(zip.files[dir.sst.replace(/^\//,'')].data);
|
||||
if(dir.sst) strs=parse_sst(getdata(zip.files[dir.sst.replace(/^\//,'')]));
|
||||
|
||||
styles = {};
|
||||
if(dir.style) styles = parseStyles(zip.files[dir.style.replace(/^\//,'')].data);
|
||||
if(dir.style) styles = parseStyles(getdata(zip.files[dir.style.replace(/^\//,'')]));
|
||||
|
||||
var wb = parseWB(zip.files[dir.workbooks[0].replace(/^\//,'')].data);
|
||||
var propdata = dir.coreprops.length !== 0 ? zip.files[dir.coreprops[0].replace(/^\//,'')].data : "";
|
||||
propdata += dir.extprops.length !== 0 ? zip.files[dir.extprops[0].replace(/^\//,'')].data : "";
|
||||
var wb = parseWB(getdata(zip.files[dir.workbooks[0].replace(/^\//,'')]));
|
||||
var propdata = dir.coreprops.length !== 0 ? getdata(zip.files[dir.coreprops[0].replace(/^\//,'')]) : "";
|
||||
propdata += dir.extprops.length !== 0 ? getdata(zip.files[dir.extprops[0].replace(/^\//,'')]) : "";
|
||||
var props = propdata !== "" ? parseProps(propdata) : {};
|
||||
var deps = {};
|
||||
if(dir.calcchain) deps=parseDeps(zip.files[dir.calcchain.replace(/^\//,'')].data);
|
||||
if(dir.calcchain) deps=parseDeps(getdata(zip.files[dir.calcchain.replace(/^\//,'')]));
|
||||
var sheets = {}, i=0;
|
||||
if(!props.Worksheets) {
|
||||
/* Google Docs doesn't generate the appropriate metadata, so we impute: */
|
||||
@ -472,12 +479,12 @@ function parseZip(zip) {
|
||||
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);
|
||||
sheets[props.SheetNames[i]]=parseSheet(getdata(zip.files['xl/worksheets/sheet' + (i+1) + '.xml']));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i = 0; i != props.Worksheets; ++i) {
|
||||
sheets[props.SheetNames[i]]=parseSheet(zip.files[dir.sheets[i].replace(/^\//,'')].data);
|
||||
sheets[props.SheetNames[i]]=parseSheet(getdata(zip.files[dir.sheets[i].replace(/^\//,'')]));
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "xlsx",
|
||||
"version": "0.3.1",
|
||||
"author": "Niggler",
|
||||
"version": "0.3.2",
|
||||
"author": "sheetjs",
|
||||
"description": "(one day) a full-featured XLSX parser and writer. For now, primitive parser",
|
||||
"keywords": [
|
||||
"xlsx", "office", "excel", "spreadsheet"
|
||||
@ -20,14 +20,14 @@
|
||||
},
|
||||
"repository": {
|
||||
"type":"git",
|
||||
"url": "git://github.com/Niggler/js-xlsx.git"
|
||||
"url": "git://github.com/SheetJS/js-xlsx.git"
|
||||
},
|
||||
"scripts": {
|
||||
"pretest": "git submodule init && git submodule update",
|
||||
"test": "make mocha",
|
||||
"test-jasmine": "jasmine-node --verbose tests/"
|
||||
},
|
||||
"bugs": { "url": "https://github.com/Niggler/js-xlsx/issues" },
|
||||
"bugs": { "url": "https://github.com/SheetJS/js-xlsx/issues" },
|
||||
"license": "Apache-2.0",
|
||||
"engines": { "node": ">=0.6" }
|
||||
}
|
||||
|
35
xlsx.js
35
xlsx.js
@ -228,7 +228,7 @@ function parsexmltag(tag) {
|
||||
var words = tag.split(/\s+/);
|
||||
var z = {'0': words[0]};
|
||||
if(words.length === 1) return z;
|
||||
tag.match(/(\w+)="([^"]*)"/g).map(
|
||||
(tag.match(/(\w+)="([^"]*)"/g) || []).map(
|
||||
function(x){var y=x.match(/(\w+)="([^"]*)"/); z[y[1]] = y[2]; });
|
||||
return z;
|
||||
}
|
||||
@ -279,7 +279,7 @@ function matchtag(f,g) {return new RegExp('<'+f+'(?: xml:space="preserve")?>([^\
|
||||
function parseVector(data) {
|
||||
var h = parsexmltag(data);
|
||||
|
||||
var matches = data.match(new RegExp("<vt:" + h.baseType + ">(.*?)</vt:" + h.baseType + ">", 'g'));
|
||||
var matches = data.match(new RegExp("<vt:" + h.baseType + ">(.*?)</vt:" + h.baseType + ">", 'g'))||[];
|
||||
if(matches.length != h.size) throw "unexpected vector length " + matches.length + " != " + h.size;
|
||||
var res = [];
|
||||
matches.forEach(function(x) {
|
||||
@ -298,7 +298,7 @@ var parse_sst = (function(){
|
||||
/* 18.4.7 rPr CT_RPrElt */
|
||||
var parse_rpr = function(rpr, intro, outro) {
|
||||
var font = {};
|
||||
rpr.match(/<[^>]*>/g).forEach(function(x) {
|
||||
(rpr.match(/<[^>]*>/g)||[]).forEach(function(x) {
|
||||
var y = parsexmltag(x);
|
||||
switch(y[0]) {
|
||||
/* 18.8.12 condense CT_BooleanProperty */
|
||||
@ -422,7 +422,7 @@ var parse_sst = (function(){
|
||||
var s = [];
|
||||
/* 18.4.9 sst CT_Sst */
|
||||
var sst = data.match(new RegExp("<sst([^>]*)>([\\s\\S]*)<\/sst>","m"));
|
||||
if(sst) {
|
||||
if(isval(sst)) {
|
||||
s = sst[2].replace(/<si>/g,"").split(/<\/si>/).map(parse_si);
|
||||
sst = parsexmltag(sst[1]); s.Count = sst.count; s.Unique = sst.uniqueCount;
|
||||
}
|
||||
@ -653,7 +653,7 @@ function parseProps(data) {
|
||||
function parseDeps(data) {
|
||||
var d = [];
|
||||
var l = 0, i = 1;
|
||||
data.match(/<[^>]*>/g).forEach(function(x) {
|
||||
(data.match(/<[^>]*>/g)||[]).forEach(function(x) {
|
||||
var y = parsexmltag(x);
|
||||
switch(y[0]) {
|
||||
case '<?xml': break;
|
||||
@ -876,23 +876,30 @@ function parseStyles(data) {
|
||||
return styles;
|
||||
}
|
||||
|
||||
function getdata(data) {
|
||||
if(!data) return {};
|
||||
if(data.data) return data.data;
|
||||
if(data._data && data._data.getContent) return Array.prototype.slice.call(data._data.getContent(),0).map(function(x) { return String.fromCharCode(x); }).join("");
|
||||
return {};
|
||||
}
|
||||
|
||||
function parseZip(zip) {
|
||||
var entries = Object.keys(zip.files);
|
||||
var keys = entries.filter(function(x){return x.substr(-1) != '/';}).sort();
|
||||
var dir = parseCT((zip.files['[Content_Types].xml']||{}).data);
|
||||
var dir = parseCT(getdata(zip.files['[Content_Types].xml']));
|
||||
|
||||
strs = {};
|
||||
if(dir.sst) strs=parse_sst(zip.files[dir.sst.replace(/^\//,'')].data);
|
||||
if(dir.sst) strs=parse_sst(getdata(zip.files[dir.sst.replace(/^\//,'')]));
|
||||
|
||||
styles = {};
|
||||
if(dir.style) styles = parseStyles(zip.files[dir.style.replace(/^\//,'')].data);
|
||||
if(dir.style) styles = parseStyles(getdata(zip.files[dir.style.replace(/^\//,'')]));
|
||||
|
||||
var wb = parseWB(zip.files[dir.workbooks[0].replace(/^\//,'')].data);
|
||||
var propdata = dir.coreprops.length !== 0 ? zip.files[dir.coreprops[0].replace(/^\//,'')].data : "";
|
||||
propdata += dir.extprops.length !== 0 ? zip.files[dir.extprops[0].replace(/^\//,'')].data : "";
|
||||
var wb = parseWB(getdata(zip.files[dir.workbooks[0].replace(/^\//,'')]));
|
||||
var propdata = dir.coreprops.length !== 0 ? getdata(zip.files[dir.coreprops[0].replace(/^\//,'')]) : "";
|
||||
propdata += dir.extprops.length !== 0 ? getdata(zip.files[dir.extprops[0].replace(/^\//,'')]) : "";
|
||||
var props = propdata !== "" ? parseProps(propdata) : {};
|
||||
var deps = {};
|
||||
if(dir.calcchain) deps=parseDeps(zip.files[dir.calcchain.replace(/^\//,'')].data);
|
||||
if(dir.calcchain) deps=parseDeps(getdata(zip.files[dir.calcchain.replace(/^\//,'')]));
|
||||
var sheets = {}, i=0;
|
||||
if(!props.Worksheets) {
|
||||
/* Google Docs doesn't generate the appropriate metadata, so we impute: */
|
||||
@ -903,12 +910,12 @@ function parseZip(zip) {
|
||||
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);
|
||||
sheets[props.SheetNames[i]]=parseSheet(getdata(zip.files['xl/worksheets/sheet' + (i+1) + '.xml']));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i = 0; i != props.Worksheets; ++i) {
|
||||
sheets[props.SheetNames[i]]=parseSheet(zip.files[dir.sheets[i].replace(/^\//,'')].data);
|
||||
sheets[props.SheetNames[i]]=parseSheet(getdata(zip.files[dir.sheets[i].replace(/^\//,'')]));
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user