From 5f9576a6d2892d6b2e8afa3b7be1ad651c956ea9 Mon Sep 17 00:00:00 2001 From: Pieter Sheth-Voss Date: Wed, 15 Apr 2015 15:07:45 -0400 Subject: [PATCH] Read borders and alignments --- .DS_Store | Bin 0 -> 12292 bytes .gitignore | 2 + bits/47_styxml.js | 437 ++++++++++++++++++++++++++++--------------- bits/66_wscommon.js | 7 +- example.js | 150 +++++++++++++++ out.txt | Bin 0 -> 22328 bytes test-acid.js | 20 ++ test-csv.js | 43 +++++ test-open.js | 8 + test-style.js | 5 +- tests.lst | 2 - xlsx.js | 444 ++++++++++++++++++++++++++++---------------- 12 files changed, 804 insertions(+), 314 deletions(-) create mode 100644 .DS_Store create mode 100644 example.js create mode 100644 out.txt create mode 100644 test-acid.js create mode 100644 test-open.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..575a0499c1a6fd68f1bdb95de98723abddd8e212 GIT binary patch literal 12292 zcmeHMTWl3Y7@n^!WtZ-uTPWC8OO7^y8cRIfp%{C5L9BpOPfJ@U)N{@*?aFqyp54?4s)5!f;qia zgJM82pcqgLCA|XY-^Lxc8-1<%$8t!2gl~{(gwl!!a4*ghcV`piG1SgggWg ziOLiQ2%mU_$p|MT3RfCaMh}Qw5rr6#?qrYi?u5w*CnQRD2IvHfva9K;^aT6XWCNTe?=g zVolSwjDPsZ(PNJvf8xYRxn)GJ4OTIWf>VX|?*=0sa{ooAr}lqwdjAW`jM&00cWtdS z+IyU=@1>kWcE4F35CQE}?a0|9VzU+5w42Sl>CkR=UEV3^&iZbC$P0MyY|eMx4nJ^0 z$M<@BLi=DiHP8%G&+fp_g{{J|-!$`qeZNg(IwN))jZ8x=;=EDTL>|8)tmrTg5 z>e|Wjs@j{E-CQ>BV$tHtC5Ew^DE2~UzhmdRMmf*D=^$%+mg5a{k2ryoaqUho zJ!Ds)LDz*>bxq9ZvuM5@zQz44^Q1fovnjVUO*q_A7c)8o+OwICIyqC!COJ=a$$Cjwodm{olix|TY&qM= zwzE$9vgNZ!*m3qUJHy^*=hz4AGxim`#C~8uv&-x^_B;Cn3_6yg3e~7V9d1VgtI&uh zG@}Kr*pB;kn3BJI2T);(q zkDu@hF3aT=P3ifbspU$&B+m zX>H6B#FerXT9jfFBAgPL(D@8yPgd95cvI~%k|t@@K3GUd=6rrSG|`*H9y2weKkmGu zo~lK3LZr1}Wy~;(#W~;WmI~?fYH}G_8J!niX{)D! zpy_|5+rLrmm+WiyBUdbdQY^$`#BnQWbsgz+E80n=J8&<$(ThFk!(P(qARfd4xX5Fa z)Ov{Y`Y5UO2#(?yp22f?9xvcUyn-~X?5c;%-UPz?MF7(hu|s;z|LS575IC?>8Y)xKJj-aY7M}6HfobkjioD%6*a%PDrE{O8@wW0RG3Oy8qSvFVv?p k#eiZ!F`yVw3@8Q^1BwB~fMP%~pcqgLC': case '': break; + styles.Fills = []; + var fill = {}; + t[0].match(tagregex).forEach(function (x) { + var y = parsexmltag(x); + switch (y[0]) { + case '': + case '': + break; - /* 18.8.20 fill CT_Fill */ - case '': break; - case '': styles.Fills.push(fill); fill = {}; break; + /* 18.8.20 fill CT_Fill */ + case '': + break; + case '': + styles.Fills.push(fill); + fill = {}; + break; - /* 18.8.32 patternFill CT_PatternFill */ - case '': case '': break; + /* 18.8.32 patternFill CT_PatternFill */ + case '': + case '': + break; - /* 18.8.3 bgColor CT_Color */ - case '': case '': break; + if (y.rgb) fill.bgColor.rgb = y.rgb;//.substring(y.rgb.length - 6); + break; + case '': + case '': + break; - /* 18.8.19 fgColor CT_Color */ - case '': case '': break; + /* 18.8.19 fgColor CT_Color */ + case '': + case '': + break; - default: if(opts.WTF) throw 'unrecognized ' + y[0] + ' in fills'; - } - }); + default: + if (opts.WTF) throw 'unrecognized ' + y[0] + ' in fills'; + } + }); } function parse_fonts(t, opts) { styles.Fonts = []; var font = {}; - t[0].match(tagregex).forEach(function(x) { + t[0].match(tagregex).forEach(function (x) { var y = parsexmltag(x); - switch(y[0]) { + switch (y[0]) { - case '': case '': break; + case '': + case '': + break; case '': styles.Fonts.push(font); ;font = {}; break; + case '': + styles.Fonts.push(font); + ; + font = {}; + break; case '': + case '': break; - case '': case '': break; - case '': font.bold = true;break; - case '': font.underline = true;break; - case '': font.italic = true;break; - case '': font.strike = true;break; - case '': font.outline = true;break; - case '': font.shadow = true;break; + case '': + font.bold = true; + break; + case '': + font.underline = true; + break; + case '': + font.italic = true; + break; + case '': + font.strike = true; + break; + case '': + font.outline = true; + break; + case '': + font.shadow = true; + break; case '': + case '': break; - case '': case '': break; case '': + case '': break; - case '': case '': break; case '':case '': break; + case '': + case '': + break; } }); } function parse_borders(t, opts) { styles.Borders = []; - var border = {}; - t[0].match(tagregex).forEach(function(x) { + var border = {}, sub_border = {}; + t[0].match(tagregex).forEach(function (x) { var y = parsexmltag(x); - switch(y[0]) { - case '': case '': break; - case '': break; + switch (y[0]) { + case '': + case '': + break; + case '': + border = {}; + if (y.diagonalUp) { border.diagonalUp = y.diagonalUp; } + if (y.diagonalDown) { border.diagonalDown = y.diagonalDown; } + styles.Borders.push(border); + + break; + break; case '': - styles.Fonts.push(border); - border = {}; break; + break; + + case '': case '': break; - - case '': + case '': + break; + default: break; - case '': case '': break; } }); @@ -119,111 +203,153 @@ function parse_borders(t, opts) { /* 18.8.31 numFmts CT_NumFmts */ function parse_numFmts(t, opts) { - styles.NumberFmt = []; - var k = keys(SSF._table); - for(var i=0; i < k.length; ++i) styles.NumberFmt[k[i]] = SSF._table[k[i]]; - var m = t[0].match(tagregex); - for(i=0; i < m.length; ++i) { - var y = parsexmltag(m[i]); - switch(y[0]) { - case '': case '': case '': break; - case '0) SSF.load(f,j); - } break; - default: if(opts.WTF) throw 'unrecognized ' + y[0] + ' in numFmts'; - } - } + styles.NumberFmt = []; + var k = keys(SSF._table); + for (var i = 0; i < k.length; ++i) styles.NumberFmt[k[i]] = SSF._table[k[i]]; + var m = t[0].match(tagregex); + for (i = 0; i < m.length; ++i) { + var y = parsexmltag(m[i]); + switch (y[0]) { + case '': + case '': + case '': + break; + case ' 0) SSF.load(f, j); + } + break; + default: + if (opts.WTF) throw 'unrecognized ' + y[0] + ' in numFmts'; + } + } } function write_numFmts(NF, opts) { - var o = [""]; - [[5,8],[23,26],[41,44],[63,66],[164,392]].forEach(function(r) { - for(var i = r[0]; i <= r[1]; ++i) if(NF[i] !== undefined) o[o.length] = (writextag('numFmt',null,{numFmtId:i,formatCode:escapexml(NF[i])})); - }); - if(o.length === 1) return ""; - o[o.length] = (""); - o[0] = writextag('numFmts', null, { count:o.length-2 }).replace("/>", ">"); - return o.join(""); + var o = [""]; + [ + [5, 8], + [23, 26], + [41, 44], + [63, 66], + [164, 392] + ].forEach(function (r) { + for (var i = r[0]; i <= r[1]; ++i) if (NF[i] !== undefined) o[o.length] = (writextag('numFmt', null, {numFmtId: i, formatCode: escapexml(NF[i])})); + }); + if (o.length === 1) return ""; + o[o.length] = (""); + o[0] = writextag('numFmts', null, { count: o.length - 2 }).replace("/>", ">"); + return o.join(""); } /* 18.8.10 cellXfs CT_CellXfs */ function parse_cellXfs(t, opts) { - styles.CellXf = []; - t[0].match(tagregex).forEach(function(x) { - var y = parsexmltag(x); - switch(y[0]) { - case '': case '': case '': break; + styles.CellXf = []; + var xf; + t[0].match(tagregex).forEach(function (x) { + var y = parsexmltag(x); + switch (y[0]) { + case '': + case '': + case '': + break; - /* 18.8.45 xf CT_Xf */ - case '': break; + /* 18.8.45 xf CT_Xf */ + case '': + break; - /* 18.8.1 alignment CT_CellAlignment */ - case '': break; + /* 18.8.1 alignment CT_CellAlignment */ + case '': + var alignment = {} + if (y.vertical) { alignment.vertical = y.vertical;} + if (y.horizontal) { alignment.horizontal = y.horizontal;} + if (y.indent) { alignment.indent = y.indent; } + if (y.wrapText) { alignment.wrapText = y.wrapText; } + xf.alignment = alignment; - /* 18.8.33 protection CT_CellProtection */ - case '': case '': break; + break; - case '': break; - case '': + case '': + break; + + case '': + break; + case '"); - if(o.length === 2) return ""; - o[0] = writextag('cellXfs',null, {count:o.length-2}).replace("/>",">"); - return o.join(""); + var o = []; + o[o.length] = (writextag('cellXfs', null)); + cellXfs.forEach(function (c) { + o[o.length] = (writextag('xf', null, c)); + }); + o[o.length] = (""); + if (o.length === 2) return ""; + o[0] = writextag('cellXfs', null, {count: o.length - 2}).replace("/>", ">"); + return o.join(""); } /* 18.8 Styles CT_Stylesheet*/ -var parse_sty_xml= (function make_pstyx() { -var numFmtRegex = /]*)>.*<\/numFmts>/; -var cellXfRegex = /]*)>.*<\/cellXfs>/; -var fillsRegex = /]*)>.*<\/fills>/; -var bordersRegex = /]*)>.*<\/borders>/; +var parse_sty_xml = (function make_pstyx() { + var numFmtRegex = /]*)>.*<\/numFmts>/; + var cellXfRegex = /]*)>.*<\/cellXfs>/; + var fillsRegex = /]*)>.*<\/fills>/; + var bordersRegex = /]*)>.*<\/borders>/; -return function parse_sty_xml(data, opts) { - /* 18.8.39 styleSheet CT_Stylesheet */ - var t; + return function parse_sty_xml(data, opts) { + /* 18.8.39 styleSheet CT_Stylesheet */ + var t; - /* numFmts CT_NumFmts ? */ - if((t=data.match(numFmtRegex))) parse_numFmts(t, opts); + /* numFmts CT_NumFmts ? */ + if ((t = data.match(numFmtRegex))) parse_numFmts(t, opts); - /* fonts CT_Fonts ? */ - if((t=data.match(/]*)>.*<\/fonts>/))) parse_fonts(t, opts) + /* fonts CT_Fonts ? */ + if ((t = data.match(/]*)>.*<\/fonts>/))) parse_fonts(t, opts) - /* fills CT_Fills */ - if((t=data.match(fillsRegex))) parse_fills(t, opts); + /* fills CT_Fills */ + if ((t = data.match(fillsRegex))) parse_fills(t, opts); - /* borders CT_Borders ? */ -// if ((t=data.match(bordersRegex))) parse_borders(t, opts); - /* cellStyleXfs CT_CellStyleXfs ? */ + /* borders CT_Borders ? */ + if ((t = data.match(bordersRegex))) parse_borders(t, opts); + /* cellStyleXfs CT_CellStyleXfs ? */ - /* cellXfs CT_CellXfs ? */ - if((t=data.match(cellXfRegex))) parse_cellXfs(t, opts); + /* cellXfs CT_CellXfs ? */ + if ((t = data.match(cellXfRegex))) parse_cellXfs(t, opts); - /* dxfs CT_Dxfs ? */ - /* tableStyles CT_TableStyles ? */ - /* colors CT_Colors ? */ - /* extLst CT_ExtensionList ? */ + /* dxfs CT_Dxfs ? */ + /* tableStyles CT_TableStyles ? */ + /* colors CT_Colors ? */ + /* extLst CT_ExtensionList ? */ - return styles; -}; + return styles; + }; })(); var STYLES_XML_ROOT = writextag('styleSheet', null, { - 'xmlns': XMLNS.main[0], - 'xmlns:vt': XMLNS.vt + 'xmlns': XMLNS.main[0], + 'xmlns:vt': XMLNS.vt }); RELS.STY = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"; @@ -234,17 +360,20 @@ function write_sty_xml(wb, opts) { return style_builder.toXml(); } - var o = [XML_HEADER, STYLES_XML_ROOT], w; - if((w = write_numFmts(wb.SSF)) != null) o[o.length] = w; - o[o.length] = (''); - o[o.length] = (''); - o[o.length] = (''); - o[o.length] = (''); - if((w = write_cellXfs(opts.cellXfs))) o[o.length] = (w); - o[o.length] = (''); - o[o.length] = (''); - o[o.length] = (''); + var o = [XML_HEADER, STYLES_XML_ROOT], w; + if ((w = write_numFmts(wb.SSF)) != null) o[o.length] = w; + o[o.length] = (''); + o[o.length] = (''); + o[o.length] = (''); + o[o.length] = (''); + if ((w = write_cellXfs(opts.cellXfs))) o[o.length] = (w); + o[o.length] = (''); + o[o.length] = (''); + o[o.length] = (''); - if(o.length>2){ o[o.length] = (''); o[1]=o[1].replace("/>",">"); } - return o.join(""); + if (o.length > 2) { + o[o.length] = (''); + o[1] = o[1].replace("/>", ">"); + } + return o.join(""); } diff --git a/bits/66_wscommon.js b/bits/66_wscommon.js index 270b845..980297f 100644 --- a/bits/66_wscommon.js +++ b/bits/66_wscommon.js @@ -34,6 +34,7 @@ function get_cell_style(styles, cell, opts) { function get_cell_style_csf(cellXf) { if (cellXf) { + var s = {} if (typeof cellXf.numFmtId != undefined) { @@ -48,8 +49,12 @@ function get_cell_style_csf(cellXf) { s.font = styles.Fonts[cellXf.fontId]; } if (cellXf.borderId) { -// s.border = styles.Borders[cellXf.borderId]; + s.border = styles.Borders[cellXf.borderId]; } + if (cellXf.applyAlignment==1) { + s.alignment = cellXf.alignment; + } + return s; } diff --git a/example.js b/example.js new file mode 100644 index 0000000..5318605 --- /dev/null +++ b/example.js @@ -0,0 +1,150 @@ +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"}}}} + ] + ]).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) diff --git a/out.txt b/out.txt new file mode 100644 index 0000000000000000000000000000000000000000..3ec8796579a220a52f77c90d3a5deec39d7440b2 GIT binary patch literal 22328 zcmeHPTW=)Cb*5}NfE5_A5`~mrb!~ygd@|~*cOLg~LxHDYaiB=-n zms6+Cz0RqsuCvFVfAzHu`gi%twELfb{hinU^p%Yb`gtACOmA@Jdy}9t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>iA&lC2(1Se_ne zMTDYE41D|j*AW4q;Osd1!I4uN?~z|s$VY+~KgjPqeV*0}MnBCK&^TX^R zn+XQI$FYbp8s&@ySaQcGYB)ZhJ65p(MdA5?37XR{#7J@(LjktJ<4O{2ui|W1xOG': case '': break; + styles.Fills = []; + var fill = {}; + t[0].match(tagregex).forEach(function (x) { + var y = parsexmltag(x); + switch (y[0]) { + case '': + case '': + break; - /* 18.8.20 fill CT_Fill */ - case '': break; - case '': styles.Fills.push(fill); fill = {}; break; + /* 18.8.20 fill CT_Fill */ + case '': + break; + case '': + styles.Fills.push(fill); + fill = {}; + break; - /* 18.8.32 patternFill CT_PatternFill */ - case '': case '': break; + /* 18.8.32 patternFill CT_PatternFill */ + case '': + case '': + break; - /* 18.8.3 bgColor CT_Color */ - case '': case '': break; + if (y.rgb) fill.bgColor.rgb = y.rgb;//.substring(y.rgb.length - 6); + break; + case '': + case '': + break; - /* 18.8.19 fgColor CT_Color */ - case '': case '': break; + /* 18.8.19 fgColor CT_Color */ + case '': + case '': + break; - default: if(opts.WTF) throw 'unrecognized ' + y[0] + ' in fills'; - } - }); + default: + if (opts.WTF) throw 'unrecognized ' + y[0] + ' in fills'; + } + }); } function parse_fonts(t, opts) { styles.Fonts = []; var font = {}; - t[0].match(tagregex).forEach(function(x) { + t[0].match(tagregex).forEach(function (x) { var y = parsexmltag(x); - switch(y[0]) { + switch (y[0]) { - case '': case '': break; + case '': + case '': + break; case '': styles.Fonts.push(font); ;font = {}; break; + case '': + styles.Fonts.push(font); + ; + font = {}; + break; case '': + case '': break; - case '': case '': break; - case '': font.bold = true;break; - case '': font.underline = true;break; - case '': font.italic = true;break; - case '': font.strike = true;break; - case '': font.outline = true;break; - case '': font.shadow = true;break; + case '': + font.bold = true; + break; + case '': + font.underline = true; + break; + case '': + font.italic = true; + break; + case '': + font.strike = true; + break; + case '': + font.outline = true; + break; + case '': + font.shadow = true; + break; case '': + case '': break; - case '': case '': break; case '': + case '': break; - case '': case '': break; case '':case '': break; + case '': + case '': + break; } }); } function parse_borders(t, opts) { styles.Borders = []; - var border = {}; - t[0].match(tagregex).forEach(function(x) { + var border = {}, sub_border = {}; + t[0].match(tagregex).forEach(function (x) { var y = parsexmltag(x); - switch(y[0]) { - case '': case '': break; - case '': break; + switch (y[0]) { + case '': + case '': + break; + case '': + border = {}; + if (y.diagonalUp) { border.diagonalUp = y.diagonalUp; } + if (y.diagonalDown) { border.diagonalDown = y.diagonalDown; } + styles.Borders.push(border); + + break; + break; case '': - styles.Fonts.push(border); - border = {}; break; + break; + + case '': case '': break; - - case '': + case '': + break; + default: break; - case '': case '': break; } }); @@ -2311,111 +2395,153 @@ function parse_borders(t, opts) { /* 18.8.31 numFmts CT_NumFmts */ function parse_numFmts(t, opts) { - styles.NumberFmt = []; - var k = keys(SSF._table); - for(var i=0; i < k.length; ++i) styles.NumberFmt[k[i]] = SSF._table[k[i]]; - var m = t[0].match(tagregex); - for(i=0; i < m.length; ++i) { - var y = parsexmltag(m[i]); - switch(y[0]) { - case '': case '': case '': break; - case '0) SSF.load(f,j); - } break; - default: if(opts.WTF) throw 'unrecognized ' + y[0] + ' in numFmts'; - } - } + styles.NumberFmt = []; + var k = keys(SSF._table); + for (var i = 0; i < k.length; ++i) styles.NumberFmt[k[i]] = SSF._table[k[i]]; + var m = t[0].match(tagregex); + for (i = 0; i < m.length; ++i) { + var y = parsexmltag(m[i]); + switch (y[0]) { + case '': + case '': + case '': + break; + case ' 0) SSF.load(f, j); + } + break; + default: + if (opts.WTF) throw 'unrecognized ' + y[0] + ' in numFmts'; + } + } } function write_numFmts(NF, opts) { - var o = [""]; - [[5,8],[23,26],[41,44],[63,66],[164,392]].forEach(function(r) { - for(var i = r[0]; i <= r[1]; ++i) if(NF[i] !== undefined) o[o.length] = (writextag('numFmt',null,{numFmtId:i,formatCode:escapexml(NF[i])})); - }); - if(o.length === 1) return ""; - o[o.length] = (""); - o[0] = writextag('numFmts', null, { count:o.length-2 }).replace("/>", ">"); - return o.join(""); + var o = [""]; + [ + [5, 8], + [23, 26], + [41, 44], + [63, 66], + [164, 392] + ].forEach(function (r) { + for (var i = r[0]; i <= r[1]; ++i) if (NF[i] !== undefined) o[o.length] = (writextag('numFmt', null, {numFmtId: i, formatCode: escapexml(NF[i])})); + }); + if (o.length === 1) return ""; + o[o.length] = (""); + o[0] = writextag('numFmts', null, { count: o.length - 2 }).replace("/>", ">"); + return o.join(""); } /* 18.8.10 cellXfs CT_CellXfs */ function parse_cellXfs(t, opts) { - styles.CellXf = []; - t[0].match(tagregex).forEach(function(x) { - var y = parsexmltag(x); - switch(y[0]) { - case '': case '': case '': break; + styles.CellXf = []; + var xf; + t[0].match(tagregex).forEach(function (x) { + var y = parsexmltag(x); + switch (y[0]) { + case '': + case '': + case '': + break; - /* 18.8.45 xf CT_Xf */ - case '': break; + /* 18.8.45 xf CT_Xf */ + case '': + break; - /* 18.8.1 alignment CT_CellAlignment */ - case '': break; + /* 18.8.1 alignment CT_CellAlignment */ + case '': + var alignment = {} + if (y.vertical) { alignment.vertical = y.vertical;} + if (y.horizontal) { alignment.horizontal = y.horizontal;} + if (y.indent) { alignment.indent = y.indent; } + if (y.wrapText) { alignment.wrapText = y.wrapText; } + xf.alignment = alignment; - /* 18.8.33 protection CT_CellProtection */ - case '': case '': break; + break; - case '': break; - case '': + case '': + break; + + case '': + break; + case '"); - if(o.length === 2) return ""; - o[0] = writextag('cellXfs',null, {count:o.length-2}).replace("/>",">"); - return o.join(""); + var o = []; + o[o.length] = (writextag('cellXfs', null)); + cellXfs.forEach(function (c) { + o[o.length] = (writextag('xf', null, c)); + }); + o[o.length] = (""); + if (o.length === 2) return ""; + o[0] = writextag('cellXfs', null, {count: o.length - 2}).replace("/>", ">"); + return o.join(""); } /* 18.8 Styles CT_Stylesheet*/ -var parse_sty_xml= (function make_pstyx() { -var numFmtRegex = /]*)>.*<\/numFmts>/; -var cellXfRegex = /]*)>.*<\/cellXfs>/; -var fillsRegex = /]*)>.*<\/fills>/; -var bordersRegex = /]*)>.*<\/borders>/; +var parse_sty_xml = (function make_pstyx() { + var numFmtRegex = /]*)>.*<\/numFmts>/; + var cellXfRegex = /]*)>.*<\/cellXfs>/; + var fillsRegex = /]*)>.*<\/fills>/; + var bordersRegex = /]*)>.*<\/borders>/; -return function parse_sty_xml(data, opts) { - /* 18.8.39 styleSheet CT_Stylesheet */ - var t; + return function parse_sty_xml(data, opts) { + /* 18.8.39 styleSheet CT_Stylesheet */ + var t; - /* numFmts CT_NumFmts ? */ - if((t=data.match(numFmtRegex))) parse_numFmts(t, opts); + /* numFmts CT_NumFmts ? */ + if ((t = data.match(numFmtRegex))) parse_numFmts(t, opts); - /* fonts CT_Fonts ? */ - if((t=data.match(/]*)>.*<\/fonts>/))) parse_fonts(t, opts) + /* fonts CT_Fonts ? */ + if ((t = data.match(/]*)>.*<\/fonts>/))) parse_fonts(t, opts) - /* fills CT_Fills */ - if((t=data.match(fillsRegex))) parse_fills(t, opts); + /* fills CT_Fills */ + if ((t = data.match(fillsRegex))) parse_fills(t, opts); - /* borders CT_Borders ? */ -// if ((t=data.match(bordersRegex))) parse_borders(t, opts); - /* cellStyleXfs CT_CellStyleXfs ? */ + /* borders CT_Borders ? */ + if ((t = data.match(bordersRegex))) parse_borders(t, opts); + /* cellStyleXfs CT_CellStyleXfs ? */ - /* cellXfs CT_CellXfs ? */ - if((t=data.match(cellXfRegex))) parse_cellXfs(t, opts); + /* cellXfs CT_CellXfs ? */ + if ((t = data.match(cellXfRegex))) parse_cellXfs(t, opts); - /* dxfs CT_Dxfs ? */ - /* tableStyles CT_TableStyles ? */ - /* colors CT_Colors ? */ - /* extLst CT_ExtensionList ? */ + /* dxfs CT_Dxfs ? */ + /* tableStyles CT_TableStyles ? */ + /* colors CT_Colors ? */ + /* extLst CT_ExtensionList ? */ - return styles; -}; + return styles; + }; })(); var STYLES_XML_ROOT = writextag('styleSheet', null, { - 'xmlns': XMLNS.main[0], - 'xmlns:vt': XMLNS.vt + 'xmlns': XMLNS.main[0], + 'xmlns:vt': XMLNS.vt }); RELS.STY = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"; @@ -2426,19 +2552,22 @@ function write_sty_xml(wb, opts) { return style_builder.toXml(); } - var o = [XML_HEADER, STYLES_XML_ROOT], w; - if((w = write_numFmts(wb.SSF)) != null) o[o.length] = w; - o[o.length] = (''); - o[o.length] = (''); - o[o.length] = (''); - o[o.length] = (''); - if((w = write_cellXfs(opts.cellXfs))) o[o.length] = (w); - o[o.length] = (''); - o[o.length] = (''); - o[o.length] = (''); + var o = [XML_HEADER, STYLES_XML_ROOT], w; + if ((w = write_numFmts(wb.SSF)) != null) o[o.length] = w; + o[o.length] = (''); + o[o.length] = (''); + o[o.length] = (''); + o[o.length] = (''); + if ((w = write_cellXfs(opts.cellXfs))) o[o.length] = (w); + o[o.length] = (''); + o[o.length] = (''); + o[o.length] = (''); - if(o.length>2){ o[o.length] = (''); o[1]=o[1].replace("/>",">"); } - return o.join(""); + if (o.length > 2) { + o[o.length] = (''); + o[1] = o[1].replace("/>", ">"); + } + return o.join(""); } /* [MS-XLSB] 2.4.651 BrtFmt */ function parse_BrtFmt(data, length) { @@ -2892,6 +3021,7 @@ function get_cell_style(styles, cell, opts) { function get_cell_style_csf(cellXf) { if (cellXf) { + var s = {} if (typeof cellXf.numFmtId != undefined) { @@ -2906,8 +3036,12 @@ function get_cell_style_csf(cellXf) { s.font = styles.Fonts[cellXf.fontId]; } if (cellXf.borderId) { -// s.border = styles.Borders[cellXf.borderId]; + s.border = styles.Borders[cellXf.borderId]; } + if (cellXf.applyAlignment==1) { + s.alignment = cellXf.alignment; + } + return s; }