From 1ca3c3e6b57a6214b62ab000d6770b71b4e4d55a Mon Sep 17 00:00:00 2001 From: Pieter Sheth-Voss Date: Fri, 26 Jun 2015 13:04:45 -0400 Subject: [PATCH 1/5] Remove lab, .idea, test-csv, test-acid, etc. from repo --- .gitignore | 6 + test-style.js | 661 -------------------------------------------------- 2 files changed, 6 insertions(+), 661 deletions(-) delete mode 100644 test-style.js diff --git a/.gitignore b/.gitignore index b64031e..18554cd 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,9 @@ tmp *.htm *.html *.sheetjs + +lab/ +test_files +example.js +example2.js +.idea diff --git a/test-style.js b/test-style.js deleted file mode 100644 index 0f57293..0000000 --- a/test-style.js +++ /dev/null @@ -1,661 +0,0 @@ -var XLSX = require('./'); - -var JSZip = require('jszip'); -var fs = require('fs'); -var cheerio = require('cheerio'); - -var assert = require('assert'); - -function JSDateToExcelDate(inDate) { - return 25569.0 + ((inDate.getTime() - (inDate.getTimezoneOffset() * 60 * 1000)) / (1000 * 60 * 60 * 24)); -} - -var defaultCellStyle = { font: { name: "Verdana", sz: 11, color: "FF00FF88"}, fill: {fgColor: {rgb: "FFFFAA00"}}}; - -// test to see if everything on the left equals its counterpart on the right -// but the right hand object may have other attributes which we might not care about -function basicallyEquals(left, right) { - if (Array.isArray(left) && Array.isArray(right)) { - for (var i=0; i Date: Fri, 26 Jun 2015 13:07:56 -0400 Subject: [PATCH 2/5] Remove lab, .idea, test-csv, test-acid, etc. from repo --- .DS_Store | Bin 12292 -> 0 bytes .idea/scopes/scope_settings.xml | 5 ---- lab/wb/xl/styles-1.xml | 0 test-acid.js | 20 --------------- test-csv.js | 43 -------------------------------- test-open.js | 8 ------ 6 files changed, 76 deletions(-) delete mode 100644 .DS_Store delete mode 100644 .idea/scopes/scope_settings.xml delete mode 100644 lab/wb/xl/styles-1.xml delete mode 100644 test-acid.js delete mode 100644 test-csv.js delete mode 100644 test-open.js diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 575a0499c1a6f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~pcqgLC - - - \ No newline at end of file diff --git a/lab/wb/xl/styles-1.xml b/lab/wb/xl/styles-1.xml deleted file mode 100644 index e69de29..0000000 diff --git a/test-acid.js b/test-acid.js deleted file mode 100644 index 4ac7f48..0000000 --- a/test-acid.js +++ /dev/null @@ -1,20 +0,0 @@ -var X = require('./'); -var opts = { cellNF: true, - type: 'file', - cellHTML: true, - cellFormula: true, - cellStyles: false, - cellDates: false, - sheetStubs: false, - sheetRows: 0, - bookDeps: false, - bookSheets: false, - bookProps: false, - bookFiles: false, - bookVBA: false, - WTF: false } -; -var FILENAME = './test_files/number_format_entities-2.xlsx'; -wb = X.read(X.write(X.readFile(FILENAME,opts), {type:"buffer", bookType:'xlsx'}), {WTF:true, cellNF: true}) - -X.writeFile(wb,'/tmp/wb3.xlsx'); diff --git a/test-csv.js b/test-csv.js deleted file mode 100644 index 44f862f..0000000 --- a/test-csv.js +++ /dev/null @@ -1,43 +0,0 @@ -var argv = require('minimist')(process.argv.slice(2)); - -var XLSX = require('./'); -var fs = require('fs') -var INFILE = './test_files/pivot_table_test.xlsm'; -var TESTFILE = './test_files/pivot_table_test.xlsm.'; -//var INFILE = './test_files/formula_stress_test.xlsb'; -//var TESTFILE = './test_files/formula_stress_test.xls.'; -var INFILE ='./test_files/apachepoi_Tables.xlsx'; -var TESTFILE='./test_files/apachepoi_Tables.xlsx.'; -var INFILE = './test_files/apachepoi_45540_classic_Footer.xlsx'; -var TESTFILE = './test_files/apachepoi_45540_classic_Footer.xlsx.'; -var SHEET=argv.p || 0; - -function stripbom(x) { return x.replace(/^\ufeff/,""); } -function fixcsv(x) { return stripbom(x).replace(/\t/g,",").replace(/#{255}/g,"").replace(/"/g,"").replace(/[\n\r]+/g,"\n").replace(/\n*$/,""); } - - -wb = XLSX.readFile(INFILE, {cellNF: true}); - -//XLSX.writeFile(wb, '/tmp/test-csv.xlsx'); -//var wb = XLSX.readFile('/tmp/test-csv.xlsx', {cellNF: true}); - -wb = XLSX.read(XLSX.write(wb, {type:"buffer", bookType:'xlsx'}), {cellNF: true}) - - -var csv = fixcsv(XLSX.utils.make_csv(wb.Sheets[wb.SheetNames[SHEET]])) -console.log('==================') -console.log( csv); -console.log('------------') -var exp = fixcsv(fs.readFileSync(TESTFILE + SHEET+ '.csv','utf8')) -console.log(exp) -console.log('.............') -console.log(csv==exp); - -console.log(csv.length, exp.length) -if (argv.d) { -for (var i=0; i Date: Fri, 26 Jun 2015 13:10:56 -0400 Subject: [PATCH 3/5] Remove lab, .idea, test-csv, test-acid, etc. from repo --- example.js | 151 ----------------------------------------------------- 1 file changed, 151 deletions(-) delete mode 100644 example.js diff --git a/example.js b/example.js deleted file mode 100644 index f0b068b..0000000 --- a/example.js +++ /dev/null @@ -1,151 +0,0 @@ -var XLSX = require('./'); -var Workbook = require('../workbook'); - -///http://daveaddey.com/?p=40 -function JSDateToExcelDate(inDate) { - return 25569.0 + ((inDate.getTime() - (inDate.getTimezoneOffset() * 60 * 1000)) / (1000 * 60 * 60 * 24)); -} - -var workbook = new Workbook(XLSX) - .addRowsToSheet("Main", [ - [ - { - v: "This is a submerged cell", - s:{ - border: { - left: {style: 'thick', color: {auto: 1}}, - top: {style: 'thick', color: {auto: 1}}, - bottom: {style: 'thick', color: {auto: 1}} - } - } - }, - { - v: "Pirate ship", - s:{ - border: { - top: {style: 'thick', color: {auto: 1}}, - bottom: {style: 'thick', color: {auto: 1}} - } - } - }, - { - v: "Sunken treasure", - s:{ - border: { - right: {style: 'thick', color: {auto: 1}}, - top: {style: 'thick', color: {auto: 1}}, - bottom: {style: 'thick', color: {auto: 1}} - } - } - }], - [ - {"v": "Blank"}, - {"v": "Red", "s": {fill: { fgColor: { rgb: "FFFF0000"}}}}, - {"v": "Green", "s": {fill: { fgColor: { rgb: "FF00FF00"}}}}, - {"v": "Blue", "s": {fill: { fgColor: { rgb: "FF0000FF"}}}} - ], - [ - {"v": "Default"}, - {"v": "Arial", "s": {font: {name: "Arial", sz: 24, color: {theme: "5"}}}}, - {"v": "Times New Roman", "s": {font: {name: "Times New Roman", sz: 16, color: {rgb: "FF2222FF"}}}}, - {"v": "Courier New", "s": {font: {name: "Courier New", sz: 14}}} - ], - [ - 0.618033989, - {"v": 0.618033989}, - {"v": 0.618033989, "t": "n"}, - {"v": 0.618033989, "t": "n", "s": { "numFmt": "0.00%"}}, - {"v": 0.618033989, "t": "n", "s": { "numFmt": "0.00%"}, fill: { fgColor: { rgb: "FFFFCC00"}}} - ], - [ - {"v": 0.618033989, "t": "n", "s": { "numFmt": "0%"}}, - {"v": 0.618033989, "t": "n", "s": { "numFmt": "0.0%"}}, - {"v": 0.618033989, "t": "n", "s": { "numFmt": "0.00%"}}, - {"v": 0.618033989, "t": "n", "s": { "numFmt": "0.000%"}}, - {"v": 0.618033989, "t": "n", "s": { "numFmt": "0.0000%"}}, - {"v": 0, "t": "n", "s": { numFmt: "0.00%;\\(0.00%\\);\\-;@"}, fill: { fgColor: { rgb: "FFFFCC00"}}} - ], - [ - {v: (new Date()).toLocaleString()}, - {v: JSDateToExcelDate(new Date()), t: 'd'}, - {v: JSDateToExcelDate(new Date()), s: {numFmt: 'd-mmm-yy'}} - ] - , - [ - {v: "left", "s": { alignment: {horizontal: "left"}}}, - {v: "left", "s": { alignment: {horizontal: "center"}}}, - {v: "left", "s": { alignment: {horizontal: "right"}}} - ],[ - {v: "vertical", "s": { alignment: {vertical: "top"}}}, - {v: "vertical", "s": { alignment: {vertical: "center"}}}, - {v: "vertical", "s": { alignment: {vertical: "bottom"}}} - ],[ - {v: "indent", "s": { alignment: {indent: "1"}}}, - {v: "indent", "s": { alignment: {indent: "2"}}}, - {v: "indent", "s": { alignment: {indent: "3"}}} - ], - [{ - v: "In publishing and graphic design, lorem ipsum is a filler text commonly used to demonstrate the graphic elements of a document or visual presentation. ", - s: { alignment: { wrapText: 1, alignment: 'right', vertical: 'center', indent: 1}} - } - ], - [ - {v: 41684.35264774306, s: {numFmt: 'm/d/yy'}}, - {v: 41684.35264774306, s: {numFmt: 'd-mmm-yy'}}, - {v: 41684.35264774306, s: {numFmt: 'h:mm:ss AM/PM'}}, - {v: JSDateToExcelDate(new Date()), s: {numFmt: 'm/d/yy'}}, - {v: 42065.02247239584, s: {numFmt: 'm/d/yy'}}, - {v: JSDateToExcelDate(new Date()), s: {numFmt: 'm/d/yy h:mm:ss AM/PM'}} - ], - [ - {v: "Apple", s: {border: {top: { style: "thin"}, left: { style: "thin"}, right: { style: "thin"}, bottom: { style: "thin"}}}}, - {}, - { - v: "Apple", - s: { - border: { - diagonalUp: 1, diagonalDown: 1, - top: { style: "dashed", color: {auto: 1}}, - right: { style: "medium", color: {theme: "5"}}, - bottom: { style: "hair", color: {theme: 5, tint: "-0.3"}}, - left: { style: "thin", color: {rgb: "FFFFAA00"}}, - diagonal: {style: "dotted", color: {auto: 1}} - } - } - }, - {}, - { - v: "Pear", - s: { - border: { - diagonalUp: 1, diagonalDown: 1, - top: { style: "dashed", color: {auto: 1}}, - right: { style: "dotted", color: {theme: "5"}}, - bottom: { style: "mediumDashed", color: {theme: 5, tint: "-0.3"}}, - left: { style: "double", color: {rgb: "FFFFAA00"}}, - diagonal: {style: "hair", color: {auto: 1}} - } - } - } - ], - [ - {v: "Up 90", s: {alignment: {textRotation: 90}}}, - {v: "Up 45", s: {alignment: {textRotation: 45}}}, - {v: "Horizontal", s: {alignment: {textRotation: 0}}}, - {v: "Down 45", s: {alignment: {textRotation: 135}}}, - {v: "Down 90", s: {alignment: {textRotation: 180}}}, - {v: "Vertical", s: {alignment: {textRotation: 255}}} - ], - [ - {v: "Font color test", s: { font: {fgColor: {rgb: "FFC6EFCE"}}}}, - {v: "right to left", s: {alignment: {readingOrder: 2}}} - ] - ]).mergeCells("Main", { - "s": {"c": 0, "r": 0 }, - "e": {"c": 2, "r": 0 } - }).finalize(); - - -var OUTFILE = '/tmp/wb.xlsx'; -XLSX.writeFile(workbook, OUTFILE, {defaultCellStyle: { font: { name: "Verdana", sz: 11, color: "FF00FF88"}, fill: {fgColor: {rgb: "FFFFAA00"}}}}); -console.log("Results written to " + OUTFILE) From dcf6f174553be080a15d13fef7eef91b1f78c456 Mon Sep 17 00:00:00 2001 From: Pieter Sheth-Voss Date: Tue, 11 Aug 2015 17:20:09 -0400 Subject: [PATCH 4/5] Retain styles for blank cells --- bits/67_wsxml.js | 9 ++++++--- xlsx.js | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bits/67_wsxml.js b/bits/67_wsxml.js index 6ee52cf..61392ab 100644 --- a/bits/67_wsxml.js +++ b/bits/67_wsxml.js @@ -126,7 +126,7 @@ function write_ws_xml_cols(ws, cols) { } function write_ws_xml_cell(cell, ref, ws, opts, idx, wb) { - if(cell.v === undefined) return ""; + if(cell.v === undefined && cell.s === undefined) return ""; var vv = ""; var oldt = cell.t, oldv = cell.v; switch(cell.t) { @@ -213,7 +213,7 @@ return function parse_ws_xml_data(sdata, s, opts, guess) { if(opts.cellFormula && (cref=d.match(match_f))!== null) p.f=unescapexml(cref[1]); /* SCHEMA IS ACTUALLY INCORRECT HERE. IF A CELL HAS NO T, EMIT "" */ - if(tag.t === undefined && p.v === undefined) { + if(tag.t === undefined && tag.s === undefined && p.v === undefined) { if(!opts.sheetStubs) continue; p.t = "stub"; } @@ -222,7 +222,10 @@ return function parse_ws_xml_data(sdata, s, opts, guess) { if(guess.e.c < idx) guess.e.c = idx; /* 18.18.11 t ST_CellType */ switch(p.t) { - case 'n': p.v = parseFloat(p.v); break; + case 'n': + p.v = parseFloat(p.v); + if(isNaN(p.v)) p.v = "" // we don't want NaN if p.v is null + break; case 's': sstr = strs[parseInt(p.v, 10)]; p.v = sstr.t; diff --git a/xlsx.js b/xlsx.js index faaf85f..b44fe15 100644 --- a/xlsx.js +++ b/xlsx.js @@ -7651,7 +7651,7 @@ function write_ws_xml_cols(ws, cols) { } function write_ws_xml_cell(cell, ref, ws, opts, idx, wb) { - if(cell.v === undefined) return ""; + if(cell.v === undefined && cell.s === undefined) return ""; var vv = ""; var oldt = cell.t, oldv = cell.v; switch(cell.t) { @@ -7738,7 +7738,7 @@ return function parse_ws_xml_data(sdata, s, opts, guess) { if(opts.cellFormula && (cref=d.match(match_f))!== null) p.f=unescapexml(cref[1]); /* SCHEMA IS ACTUALLY INCORRECT HERE. IF A CELL HAS NO T, EMIT "" */ - if(tag.t === undefined && p.v === undefined) { + if(tag.t === undefined && tag.s === undefined && p.v === undefined) { if(!opts.sheetStubs) continue; p.t = "stub"; } @@ -7747,7 +7747,10 @@ return function parse_ws_xml_data(sdata, s, opts, guess) { if(guess.e.c < idx) guess.e.c = idx; /* 18.18.11 t ST_CellType */ switch(p.t) { - case 'n': p.v = parseFloat(p.v); break; + case 'n': + p.v = parseFloat(p.v); + if(isNaN(p.v)) p.v = "" // we don't want NaN if p.v is null + break; case 's': sstr = strs[parseInt(p.v, 10)]; p.v = sstr.t; From 0d1281cc9433ec0e72dad41a7c6f4a367de61701 Mon Sep 17 00:00:00 2001 From: Pieter Sheth-Voss Date: Tue, 11 Aug 2015 17:23:56 -0400 Subject: [PATCH 5/5] Added test files --- tests/test-acid.js | 20 ++ tests/test-csv.js | 43 +++ tests/test-min.js | 10 + tests/test-open.js | 8 + tests/test-style.js | 694 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 775 insertions(+) create mode 100644 tests/test-acid.js create mode 100644 tests/test-csv.js create mode 100644 tests/test-min.js create mode 100644 tests/test-open.js create mode 100644 tests/test-style.js diff --git a/tests/test-acid.js b/tests/test-acid.js new file mode 100644 index 0000000..4ac7f48 --- /dev/null +++ b/tests/test-acid.js @@ -0,0 +1,20 @@ +var X = require('./'); +var opts = { cellNF: true, + type: 'file', + cellHTML: true, + cellFormula: true, + cellStyles: false, + cellDates: false, + sheetStubs: false, + sheetRows: 0, + bookDeps: false, + bookSheets: false, + bookProps: false, + bookFiles: false, + bookVBA: false, + WTF: false } +; +var FILENAME = './test_files/number_format_entities-2.xlsx'; +wb = X.read(X.write(X.readFile(FILENAME,opts), {type:"buffer", bookType:'xlsx'}), {WTF:true, cellNF: true}) + +X.writeFile(wb,'/tmp/wb3.xlsx'); diff --git a/tests/test-csv.js b/tests/test-csv.js new file mode 100644 index 0000000..44f862f --- /dev/null +++ b/tests/test-csv.js @@ -0,0 +1,43 @@ +var argv = require('minimist')(process.argv.slice(2)); + +var XLSX = require('./'); +var fs = require('fs') +var INFILE = './test_files/pivot_table_test.xlsm'; +var TESTFILE = './test_files/pivot_table_test.xlsm.'; +//var INFILE = './test_files/formula_stress_test.xlsb'; +//var TESTFILE = './test_files/formula_stress_test.xls.'; +var INFILE ='./test_files/apachepoi_Tables.xlsx'; +var TESTFILE='./test_files/apachepoi_Tables.xlsx.'; +var INFILE = './test_files/apachepoi_45540_classic_Footer.xlsx'; +var TESTFILE = './test_files/apachepoi_45540_classic_Footer.xlsx.'; +var SHEET=argv.p || 0; + +function stripbom(x) { return x.replace(/^\ufeff/,""); } +function fixcsv(x) { return stripbom(x).replace(/\t/g,",").replace(/#{255}/g,"").replace(/"/g,"").replace(/[\n\r]+/g,"\n").replace(/\n*$/,""); } + + +wb = XLSX.readFile(INFILE, {cellNF: true}); + +//XLSX.writeFile(wb, '/tmp/test-csv.xlsx'); +//var wb = XLSX.readFile('/tmp/test-csv.xlsx', {cellNF: true}); + +wb = XLSX.read(XLSX.write(wb, {type:"buffer", bookType:'xlsx'}), {cellNF: true}) + + +var csv = fixcsv(XLSX.utils.make_csv(wb.Sheets[wb.SheetNames[SHEET]])) +console.log('==================') +console.log( csv); +console.log('------------') +var exp = fixcsv(fs.readFileSync(TESTFILE + SHEET+ '.csv','utf8')) +console.log(exp) +console.log('.............') +console.log(csv==exp); + +console.log(csv.length, exp.length) +if (argv.d) { +for (var i=0; i