diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..575a049
Binary files /dev/null and b/.DS_Store differ
diff --git a/.gitignore b/.gitignore
index 2fc4471..f851342 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,5 @@ tmp
*.xlsx
*.xlsm
*.xlsb
+lab/
+.idea/
diff --git a/bits/47_styxml.js b/bits/47_styxml.js
index 88b2603..9cb869b 100644
--- a/bits/47_styxml.js
+++ b/bits/47_styxml.js
@@ -1,83 +1,122 @@
/* 18.8.21 fills CT_Fills */
function parse_fills(t, opts) {
- styles.Fills = [];
- var fill = {};
- t[0].match(tagregex).forEach(function(x) {
- var y = parsexmltag(x);
- switch(y[0]) {
- case '': 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 0000000..3ec8796
Binary files /dev/null and b/out.txt differ
diff --git a/test-acid.js b/test-acid.js
new file mode 100644
index 0000000..4ac7f48
--- /dev/null
+++ b/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/test-csv.js b/test-csv.js
index e69de29..44f862f 100644
--- a/test-csv.js
+++ b/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': 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;
}