From 3d0315358ae6fa18285beb8c9aa73af39184e742 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Sat, 23 Mar 2013 01:05:39 -0400 Subject: [PATCH] whitespace cleanup --- xlsx.js | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/xlsx.js b/xlsx.js index f9c09f8..cb6d199 100644 --- a/xlsx.js +++ b/xlsx.js @@ -8,7 +8,7 @@ var ct2type = { "application/vnd.openxmlformats-officedocument.extended-properties+xml": "extprops", "application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml": "calcchains", "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml":"sheets", - "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml": "strs", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml": "strs", "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml":"styles", "application/vnd.openxmlformats-officedocument.theme+xml":"themes", "foo": "bar" @@ -89,7 +89,7 @@ function parsexmltag(tag) { if(words.length === 1) return z; tag.match(/(\w+)="([^"]*)"/g).map( function(x){var y=x.match(/(\w+)="([^"]*)"/); z[y[1]] = y[2]; }); - return z; + return z; } @@ -105,16 +105,16 @@ function parseSheet(data) { //TODO: use a real xml parser //s.cells = {}; var q = ["v","f"]; if(!data.match(//)) - data.match(/([^]*)<\/sheetData>/m)[1].split("").forEach(function(x) { + data.match(/([^]*)<\/sheetData>/m)[1].split("").forEach(function(x) { if(x === "") return; var row = parsexmltag(x.match(/]*>/)[0]); //s.rows[row.r]=row.spans; - if(refguess.s.r > row.r - 1) refguess.s.r = row.r - 1; + if(refguess.s.r > row.r - 1) refguess.s.r = row.r - 1; if(refguess.e.r < row.r - 1) refguess.e.r = row.r - 1; var cells = x.substr(x.indexOf('>')+1).split(/ idx - 1) refguess.s.c = idx - 1; + if(refguess.s.c > idx - 1) refguess.s.c = idx - 1; if(refguess.e.c < idx - 1) refguess.e.c = idx - 1; var cell = parsexmltag((c.match(/]*>/)||[c])[0]); delete cell[0]; var d = c.substr(c.indexOf('>')+1); @@ -152,13 +152,13 @@ function matchtag(f,g) {return new RegExp('<'+f+'(?: xml:space="preserve")?>([^] function parseVector(data) { var h = parsexmltag(data); - + var matches = data.match(new RegExp("(.*?)", 'g')); if(matches.length != h.size) throw "unexpected vector length " + matches.length + " != " + h.size; var res = []; matches.forEach(function(x) { var v = x.replace(/<[/]?vt:variant>/g,"").match(/]*)>(.*)]*)>([\\s\\S]*)<\/sst>","m")); if(sst) { s = sst[2].replace(//g,"").split(/<\/si>/).map(function(x) { var z = {}; var y=x.match(/<(.*)>([\s\S]*)<\/.*/); if(y) z[y[1].split(" ")[0]]=utf8read(unescapexml(y[2])); return z;}); - + sst = parsexmltag(sst[1]); s.count = sst.count; s.uniqueCount = sst.uniqueCount; } if(debug) s.rawdata = data; @@ -199,7 +199,7 @@ function parseProps(data) { var strings = ["Application", "DocSecurity", "Company", "AppVersion"]; var bools = ["HyperlinksChanged","SharedDoc","LinksUpToDate","ScaleCrop"]; var xtra = ["HeadingPairs", "TitlesOfParts","dc:creator","cp:lastModifiedBy","dcterms:created", "dcterms:modified"]; - + strings.forEach(function(f){p[f] = (data.match(matchtag(f))||[])[1];}); bools.forEach(function(f){p[f] = (data.match(matchtag(f))||[])[1] == "true";}); xtra.forEach(function(f) { @@ -224,7 +224,7 @@ function parseProps(data) { p["LastModifiedBy"] = q["cp:lastModifiedBy"]; p["CreatedDate"] = new Date(q["dcterms:created"]); p["ModifiedDate"] = new Date(q["dcterms:modified"]); - + if(debug) p.rawdata = data; return p; } @@ -247,7 +247,7 @@ function parseDeps(data) { var ctext = {}; function parseCT(data) { - var ct = { workbooks: [], sheets: [], calcchains: [], themes: [], styles: [], + var ct = { workbooks: [], sheets: [], calcchains: [], themes: [], styles: [], coreprops: [], extprops: [], strs:[], xmlns: "" }; if(data == null) return data; data.match(/<[^>]*>/g).forEach(function(x) { @@ -256,7 +256,7 @@ function parseCT(data) { case '': delete y[0]; wb.WBProps = y; break; case '': case '': break; // aggregate workbookView case '': case '': break; // aggregate sheet - case '': case '': break; - case '': break; // LibreOffice - case '': break; + case '': break; // LibreOffice + case '': break; case '': delete y[0]; wb.CalcPr = y; break; - + case '': pass=false; break; - + case '': pass=false; break; + case '': break; case '': pass=true; break; case '': pass=false; break; /* Introduced for Excel2013 Baseline */ - case '': pass=false; break; // TODO: do something default: if(!pass) console.error("WB Tag",x,y); } }); if(wb.xmlns !== XMLNS_WB) throw "Unknown Namespace: " + wb.xmlns; - + var z; for(z in WBPropsDef) if(null == wb.WBProps[z]) wb.WBProps[z] = WBPropsDef[z]; wb.WBView.forEach(function(w){for(var z in WBViewDef) if(null==w[z]) w[z]=WBViewDef[z]; }); for(z in CalcPrDef) if(null == wb.CalcPr[z]) wb.CalcPr[z] = CalcPrDef[z]; - wb.Sheets.forEach(function(w){for(var z in SheetDef) if(null==w[z]) w[z]=SheetDef[z]; }); + wb.Sheets.forEach(function(w){for(var z in SheetDef) if(null==w[z]) w[z]=SheetDef[z]; }); if(debug) wb.rawdata = data; return wb; } @@ -468,7 +467,7 @@ function sheet_to_csv(sheet) { var out = ""; if(sheet["!ref"]) { var r = utils.decode_range(sheet["!ref"]); - for(var R = r.s.r; R <= r.e.r; ++R) { + for(var R = r.s.r; R <= r.e.r; ++R) { var row = []; for(var C = r.s.c; C <= r.e.c; ++C) { var val = sheet[utils.encode_cell({c:C,r:R})]; @@ -502,6 +501,6 @@ if(typeof require !== 'undefined' && typeof exports !== 'undefined') { var zip = XLSX.read(args[0], {type:'file'}); console.log(zip.Sheets); }; -if(typeof module !== 'undefined' && require.main === module) +if(typeof module !== 'undefined' && require.main === module) exports.main(process.argv.slice(2)); }