diff --git a/bits/88_write.js b/bits/88_write.js index f1411e1..418c0f4 100644 --- a/bits/88_write.js +++ b/bits/88_write.js @@ -1,12 +1,7 @@ function writeSync(wb, opts) { var o = opts||{}; - - if (typeof module != 'undefined' && typeof 'require' != 'undefined') { - style_builder = new StyleBuilder(opts); - } - else if (typeof $ != 'undefined' || typeof 'jQuery' != 'undefined') { - style_builder = new StyleBuilder(opts); - } + console.log("Creating stylebuilder") + style_builder = new StyleBuilder(opts); var z = write_zip(wb, o); switch(o.type) { diff --git a/bits/91_xmlbuilder.js b/bits/91_xmlbuilder.js index b2e4e26..dbf9c4a 100644 --- a/bits/91_xmlbuilder.js +++ b/bits/91_xmlbuilder.js @@ -49,13 +49,17 @@ var XmlNode = (function () { return this; } + XmlNode.prototype.escapeString = function(str) { + return str.replace(/\"/g,'"') // TODO Extend with four other codes + } + XmlNode.prototype.toXml = function (node) { if (!node) node = this; var xml = node._prefix; xml += '<' + node.tagName; if (node._attributes) { for (var key in node._attributes) { - xml += ' ' + key + '="' + node._attributes[key] + '"' + xml += ' ' + key + '="' + this.escapeString(''+node._attributes[key]) + '"' } } if (node._children && node._children.length > 0) { diff --git a/bits/92_stylebuilder.js b/bits/92_stylebuilder.js index ef1c75b..954e8ac 100644 --- a/bits/92_stylebuilder.js +++ b/bits/92_stylebuilder.js @@ -35,9 +35,7 @@ if ((typeof 'module' != 'undefined' && typeof require != 'undefined') || (typeo 47: 'mmss.0', 48: '##0.0E+0', 49: '@', - 56: '"上午/下午 "hh"時"mm"分"ss"秒 "', - 65535: 'General' - }; + 56: '"上午/下午 "hh"時"mm"分"ss"秒 "' }; var fmt_table = {}; for (var idx in table_fmt) { @@ -99,7 +97,7 @@ if ((typeof 'module' != 'undefined' && typeof require != 'undefined') || (typeo // the second style MUST be gray125 for some reason var defaultStyle = options.defaultCellStyle || {}; - if (!defaultStyle.font) defaultStyle.font = {name: 'Calibri', sz: '11'}; + if (!defaultStyle.font) defaultStyle.font = {name: 'Calibri', sz: '12'}; if (!defaultStyle.font.name) defaultStyle.font.name = 'Calibri'; if (!defaultStyle.font.sz) defaultStyle.font.sz = 11; if (!defaultStyle.fill) defaultStyle.fill = { fgColor: { patternType: "none"}}; diff --git a/test-csv.js b/test-csv.js new file mode 100644 index 0000000..e69de29 diff --git a/test.js b/test.js index d4601ad..0521436 100644 --- a/test.js +++ b/test.js @@ -107,9 +107,18 @@ function parsetest(x, wb, full, ext) { wb.SheetNames.forEach(function(ws, i) { var name = getfile(dir, x, i, ".csv"); it('#' + i + ' (' + ws + ')', fs.existsSync(name) ? function() { - var file = fs.readFileSync(name, 'utf-8'); - var csv = X.utils.make_csv(wb.Sheets[ws]); - assert.equal(fixcsv(csv), fixcsv(file), "CSV badness"); + var file = fixcsv(fs.readFileSync(name, 'utf-8')); + var csv = fixcsv(X.utils.make_csv(wb.Sheets[ws])); + var result = (file == csv); + if (!result) { + console.error(dir + x); + console.error("========== actual =============") + console.error(csv); + console.error("---------- expected -----------") + console.error(file); + console.error("LENGTHS: "+[csv.length, file.length]) + } + assert.equal(result, true, "CSV badness"); } : null); }); }); @@ -152,7 +161,9 @@ describe('should parse test files', function() { it(x + ' [' + ext + ']', function(){ var wb = wbtable[dir + x]; if(!wb) wb = X.readFile(dir + x, opts); - parsetest(x, X.read(X.write(wb, {type:"buffer", bookType:ext.replace(/\./,"")}), {WTF:opts.WTF}), ext.replace(/\./,"") !== "xlsb", ext); + //wb = X.read(X.write(wb, {type:"buffer", bookType:ext.replace(/\./,"")}), {WTF:opts.WTF}) +// wb = X.read(X.write(wb, {type:"buffer", bookType:'xlsx'})); + parsetest(x, wb, ext.replace(/\./,"") !== "xlsb", ext); }); }); }); diff --git a/xlsx.js b/xlsx.js index 5e60172..620d3f5 100644 --- a/xlsx.js +++ b/xlsx.js @@ -5184,13 +5184,8 @@ function readFileSync(data, opts) { function writeSync(wb, opts) { var o = opts||{}; - - if (typeof module != 'undefined' && typeof 'require' != 'undefined') { - style_builder = new StyleBuilder(opts); - } - else if (typeof $ != 'undefined' || typeof 'jQuery' != 'undefined') { - style_builder = new StyleBuilder(opts); - } + console.log("Creating stylebuilder") + style_builder = new StyleBuilder(opts); var z = write_zip(wb, o); switch(o.type) { @@ -5466,13 +5461,17 @@ var XmlNode = (function () { return this; } + XmlNode.prototype.escapeString = function(str) { + return str.replace(/\"/g,'"') // TODO Extend with four other codes + } + XmlNode.prototype.toXml = function (node) { if (!node) node = this; var xml = node._prefix; xml += '<' + node.tagName; if (node._attributes) { for (var key in node._attributes) { - xml += ' ' + key + '="' + node._attributes[key] + '"' + xml += ' ' + key + '="' + this.escapeString(''+node._attributes[key]) + '"' } } if (node._children && node._children.length > 0) { @@ -5526,9 +5525,7 @@ if ((typeof 'module' != 'undefined' && typeof require != 'undefined') || (typeo 47: 'mmss.0', 48: '##0.0E+0', 49: '@', - 56: '"上午/下午 "hh"時"mm"分"ss"秒 "', - 65535: 'General' - }; + 56: '"上午/下午 "hh"時"mm"分"ss"秒 "' }; var fmt_table = {}; for (var idx in table_fmt) { @@ -5590,7 +5587,7 @@ if ((typeof 'module' != 'undefined' && typeof require != 'undefined') || (typeo // the second style MUST be gray125 for some reason var defaultStyle = options.defaultCellStyle || {}; - if (!defaultStyle.font) defaultStyle.font = {name: 'Calibri', sz: '11'}; + if (!defaultStyle.font) defaultStyle.font = {name: 'Calibri', sz: '12'}; if (!defaultStyle.font.name) defaultStyle.font.name = 'Calibri'; if (!defaultStyle.font.sz) defaultStyle.font.sz = 11; if (!defaultStyle.fill) defaultStyle.fill = { fgColor: { patternType: "none"}};