2017-03-19 06:50:30 +00:00
|
|
|
/* 18.8.5 borders CT_Borders */
|
|
|
|
function parse_borders(t, styles, themes, opts) {
|
|
|
|
styles.Borders = [];
|
2019-11-15 01:46:49 +00:00
|
|
|
var border = {};
|
2018-05-05 06:34:37 +00:00
|
|
|
var pass = false;
|
2019-11-01 03:09:14 +00:00
|
|
|
(t[0].match(tagregex)||[]).forEach(function(x) {
|
2017-03-19 06:50:30 +00:00
|
|
|
var y = parsexmltag(x);
|
2018-05-22 00:59:54 +00:00
|
|
|
switch(strip_ns(y[0])) {
|
2017-03-19 06:50:30 +00:00
|
|
|
case '<borders': case '<borders>': case '</borders>': break;
|
|
|
|
|
|
|
|
/* 18.8.4 border CT_Border */
|
2017-07-26 08:35:28 +00:00
|
|
|
case '<border': case '<border>': case '<border/>':
|
2019-11-15 01:46:49 +00:00
|
|
|
border = /*::(*/{}/*:: :any)*/;
|
2019-11-01 03:09:14 +00:00
|
|
|
if(y.diagonalUp) border.diagonalUp = parsexmlbool(y.diagonalUp);
|
|
|
|
if(y.diagonalDown) border.diagonalDown = parsexmlbool(y.diagonalDown);
|
2017-03-19 06:50:30 +00:00
|
|
|
styles.Borders.push(border);
|
|
|
|
break;
|
|
|
|
case '</border>': break;
|
|
|
|
|
|
|
|
/* note: not in spec, appears to be CT_BorderPr */
|
2017-07-05 22:27:54 +00:00
|
|
|
case '<left/>': break;
|
|
|
|
case '<left': case '<left>': break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '</left>': break;
|
|
|
|
|
|
|
|
/* note: not in spec, appears to be CT_BorderPr */
|
2017-07-05 22:27:54 +00:00
|
|
|
case '<right/>': break;
|
|
|
|
case '<right': case '<right>': break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '</right>': break;
|
|
|
|
|
|
|
|
/* 18.8.43 top CT_BorderPr */
|
2017-07-05 22:27:54 +00:00
|
|
|
case '<top/>': break;
|
|
|
|
case '<top': case '<top>': break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '</top>': break;
|
|
|
|
|
|
|
|
/* 18.8.6 bottom CT_BorderPr */
|
2017-07-05 22:27:54 +00:00
|
|
|
case '<bottom/>': break;
|
|
|
|
case '<bottom': case '<bottom>': break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '</bottom>': break;
|
|
|
|
|
|
|
|
/* 18.8.13 diagonal CT_BorderPr */
|
2017-07-05 22:27:54 +00:00
|
|
|
case '<diagonal': case '<diagonal>': case '<diagonal/>': break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '</diagonal>': break;
|
|
|
|
|
|
|
|
/* 18.8.25 horizontal CT_BorderPr */
|
2017-07-05 22:27:54 +00:00
|
|
|
case '<horizontal': case '<horizontal>': case '<horizontal/>': break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '</horizontal>': break;
|
|
|
|
|
|
|
|
/* 18.8.44 vertical CT_BorderPr */
|
2017-07-05 22:27:54 +00:00
|
|
|
case '<vertical': case '<vertical>': case '<vertical/>': break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '</vertical>': break;
|
|
|
|
|
|
|
|
/* 18.8.37 start CT_BorderPr */
|
2017-07-05 22:27:54 +00:00
|
|
|
case '<start': case '<start>': case '<start/>': break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '</start>': break;
|
|
|
|
|
|
|
|
/* 18.8.16 end CT_BorderPr */
|
2017-07-05 22:27:54 +00:00
|
|
|
case '<end': case '<end>': case '<end/>': break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '</end>': break;
|
|
|
|
|
|
|
|
/* 18.8.? color CT_Color */
|
2019-11-01 03:09:14 +00:00
|
|
|
case '<color': case '<color>':
|
|
|
|
break;
|
2017-07-05 22:27:54 +00:00
|
|
|
case '<color/>': case '</color>': break;
|
2017-03-19 06:50:30 +00:00
|
|
|
|
2018-05-05 06:34:37 +00:00
|
|
|
/* 18.2.10 extLst CT_ExtensionList ? */
|
|
|
|
case '<extLst': case '<extLst>': case '</extLst>': break;
|
|
|
|
case '<ext': pass = true; break;
|
|
|
|
case '</ext>': pass = false; break;
|
|
|
|
default: if(opts && opts.WTF) {
|
|
|
|
if(!pass) throw new Error('unrecognized ' + y[0] + ' in borders');
|
|
|
|
}
|
2017-03-19 06:50:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-05-29 06:18:23 +00:00
|
|
|
/* 18.8.21 fills CT_Fills */
|
2017-03-19 06:50:30 +00:00
|
|
|
function parse_fills(t, styles, themes, opts) {
|
2014-05-29 06:18:23 +00:00
|
|
|
styles.Fills = [];
|
|
|
|
var fill = {};
|
2018-05-05 06:34:37 +00:00
|
|
|
var pass = false;
|
2019-11-01 03:09:14 +00:00
|
|
|
(t[0].match(tagregex)||[]).forEach(function(x) {
|
2014-05-29 06:18:23 +00:00
|
|
|
var y = parsexmltag(x);
|
2018-05-22 00:59:54 +00:00
|
|
|
switch(strip_ns(y[0])) {
|
2014-05-29 06:18:23 +00:00
|
|
|
case '<fills': case '<fills>': case '</fills>': break;
|
|
|
|
|
|
|
|
/* 18.8.20 fill CT_Fill */
|
2017-08-05 06:32:57 +00:00
|
|
|
case '<fill>': case '<fill': case '<fill/>':
|
|
|
|
fill = {}; styles.Fills.push(fill); break;
|
|
|
|
case '</fill>': break;
|
2014-05-29 06:18:23 +00:00
|
|
|
|
2017-03-19 06:50:30 +00:00
|
|
|
/* 18.8.24 gradientFill CT_GradientFill */
|
2017-03-28 22:03:03 +00:00
|
|
|
case '<gradientFill>': break;
|
2017-07-26 08:35:28 +00:00
|
|
|
case '<gradientFill':
|
2017-03-28 22:03:03 +00:00
|
|
|
case '</gradientFill>': styles.Fills.push(fill); fill = {}; break;
|
2017-03-19 06:50:30 +00:00
|
|
|
|
2014-05-29 06:18:23 +00:00
|
|
|
/* 18.8.32 patternFill CT_PatternFill */
|
2017-03-19 06:50:30 +00:00
|
|
|
case '<patternFill': case '<patternFill>':
|
2014-05-29 06:18:23 +00:00
|
|
|
if(y.patternType) fill.patternType = y.patternType;
|
|
|
|
break;
|
2014-05-29 22:30:03 +00:00
|
|
|
case '<patternFill/>': case '</patternFill>': break;
|
2014-05-29 06:18:23 +00:00
|
|
|
|
|
|
|
/* 18.8.3 bgColor CT_Color */
|
|
|
|
case '<bgColor':
|
|
|
|
if(!fill.bgColor) fill.bgColor = {};
|
2014-06-29 18:29:45 +00:00
|
|
|
if(y.indexed) fill.bgColor.indexed = parseInt(y.indexed, 10);
|
|
|
|
if(y.theme) fill.bgColor.theme = parseInt(y.theme, 10);
|
|
|
|
if(y.tint) fill.bgColor.tint = parseFloat(y.tint);
|
2014-05-29 22:30:03 +00:00
|
|
|
/* Excel uses ARGB strings */
|
2017-03-19 06:50:30 +00:00
|
|
|
if(y.rgb) fill.bgColor.rgb = y.rgb.slice(-6);
|
2014-05-29 06:18:23 +00:00
|
|
|
break;
|
2014-06-05 07:06:20 +00:00
|
|
|
case '<bgColor/>': case '</bgColor>': break;
|
2014-05-29 06:18:23 +00:00
|
|
|
|
|
|
|
/* 18.8.19 fgColor CT_Color */
|
|
|
|
case '<fgColor':
|
|
|
|
if(!fill.fgColor) fill.fgColor = {};
|
2014-06-29 18:29:45 +00:00
|
|
|
if(y.theme) fill.fgColor.theme = parseInt(y.theme, 10);
|
|
|
|
if(y.tint) fill.fgColor.tint = parseFloat(y.tint);
|
2014-05-29 22:30:03 +00:00
|
|
|
/* Excel uses ARGB strings */
|
2019-11-01 03:09:14 +00:00
|
|
|
if(y.rgb != null) fill.fgColor.rgb = y.rgb.slice(-6);
|
2014-05-29 06:18:23 +00:00
|
|
|
break;
|
2014-10-26 05:26:18 +00:00
|
|
|
case '<fgColor/>': case '</fgColor>': break;
|
2014-05-29 06:18:23 +00:00
|
|
|
|
2017-03-19 06:50:30 +00:00
|
|
|
/* 18.8.38 stop CT_GradientStop */
|
|
|
|
case '<stop': case '<stop/>': break;
|
|
|
|
case '</stop>': break;
|
|
|
|
|
|
|
|
/* 18.8.? color CT_Color */
|
|
|
|
case '<color': case '<color/>': break;
|
|
|
|
case '</color>': break;
|
|
|
|
|
2018-05-05 06:34:37 +00:00
|
|
|
/* 18.2.10 extLst CT_ExtensionList ? */
|
|
|
|
case '<extLst': case '<extLst>': case '</extLst>': break;
|
|
|
|
case '<ext': pass = true; break;
|
|
|
|
case '</ext>': pass = false; break;
|
|
|
|
default: if(opts && opts.WTF) {
|
|
|
|
if(!pass) throw new Error('unrecognized ' + y[0] + ' in fills');
|
|
|
|
}
|
2014-05-29 06:18:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-19 06:50:30 +00:00
|
|
|
/* 18.8.23 fonts CT_Fonts */
|
|
|
|
function parse_fonts(t, styles, themes, opts) {
|
|
|
|
styles.Fonts = [];
|
|
|
|
var font = {};
|
2018-05-05 06:34:37 +00:00
|
|
|
var pass = false;
|
2019-11-01 03:09:14 +00:00
|
|
|
(t[0].match(tagregex)||[]).forEach(function(x) {
|
2017-03-19 06:50:30 +00:00
|
|
|
var y = parsexmltag(x);
|
2018-05-22 00:59:54 +00:00
|
|
|
switch(strip_ns(y[0])) {
|
2017-03-19 06:50:30 +00:00
|
|
|
case '<fonts': case '<fonts>': case '</fonts>': break;
|
|
|
|
|
|
|
|
/* 18.8.22 font CT_Font */
|
|
|
|
case '<font': case '<font>': break;
|
|
|
|
case '</font>': case '<font/>':
|
|
|
|
styles.Fonts.push(font);
|
|
|
|
font = {};
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* 18.8.29 name CT_FontName */
|
2020-03-15 07:42:05 +00:00
|
|
|
case '<name': if(y.val) font.name = utf8read(y.val); break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '<name/>': case '</name>': break;
|
|
|
|
|
2017-05-09 18:07:57 +00:00
|
|
|
/* 18.8.2 b CT_BooleanProperty */
|
|
|
|
case '<b': font.bold = y.val ? parsexmlbool(y.val) : 1; break;
|
|
|
|
case '<b/>': font.bold = 1; break;
|
2017-03-19 06:50:30 +00:00
|
|
|
|
|
|
|
/* 18.8.26 i CT_BooleanProperty */
|
2017-05-09 18:07:57 +00:00
|
|
|
case '<i': font.italic = y.val ? parsexmlbool(y.val) : 1; break;
|
|
|
|
case '<i/>': font.italic = 1; break;
|
2017-03-19 06:50:30 +00:00
|
|
|
|
|
|
|
/* 18.4.13 u CT_UnderlineProperty */
|
2017-05-09 18:07:57 +00:00
|
|
|
case '<u':
|
|
|
|
switch(y.val) {
|
|
|
|
case "none": font.underline = 0x00; break;
|
|
|
|
case "single": font.underline = 0x01; break;
|
|
|
|
case "double": font.underline = 0x02; break;
|
|
|
|
case "singleAccounting": font.underline = 0x21; break;
|
|
|
|
case "doubleAccounting": font.underline = 0x22; break;
|
|
|
|
} break;
|
|
|
|
case '<u/>': font.underline = 1; break;
|
2017-03-19 06:50:30 +00:00
|
|
|
|
|
|
|
/* 18.4.10 strike CT_BooleanProperty */
|
2017-05-09 18:07:57 +00:00
|
|
|
case '<strike': font.strike = y.val ? parsexmlbool(y.val) : 1; break;
|
|
|
|
case '<strike/>': font.strike = 1; break;
|
2017-03-19 06:50:30 +00:00
|
|
|
|
2017-05-09 18:07:57 +00:00
|
|
|
/* 18.4.2 outline CT_BooleanProperty */
|
|
|
|
case '<outline': font.outline = y.val ? parsexmlbool(y.val) : 1; break;
|
|
|
|
case '<outline/>': font.outline = 1; break;
|
2017-03-19 06:50:30 +00:00
|
|
|
|
|
|
|
/* 18.8.36 shadow CT_BooleanProperty */
|
2017-05-09 18:07:57 +00:00
|
|
|
case '<shadow': font.shadow = y.val ? parsexmlbool(y.val) : 1; break;
|
|
|
|
case '<shadow/>': font.shadow = 1; break;
|
|
|
|
|
|
|
|
/* 18.8.12 condense CT_BooleanProperty */
|
|
|
|
case '<condense': font.condense = y.val ? parsexmlbool(y.val) : 1; break;
|
|
|
|
case '<condense/>': font.condense = 1; break;
|
|
|
|
|
|
|
|
/* 18.8.17 extend CT_BooleanProperty */
|
|
|
|
case '<extend': font.extend = y.val ? parsexmlbool(y.val) : 1; break;
|
|
|
|
case '<extend/>': font.extend = 1; break;
|
2017-03-19 06:50:30 +00:00
|
|
|
|
|
|
|
/* 18.4.11 sz CT_FontSize */
|
2017-05-09 18:07:57 +00:00
|
|
|
case '<sz': if(y.val) font.sz = +y.val; break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '<sz/>': case '</sz>': break;
|
|
|
|
|
|
|
|
/* 18.4.14 vertAlign CT_VerticalAlignFontProperty */
|
|
|
|
case '<vertAlign': if(y.val) font.vertAlign = y.val; break;
|
|
|
|
case '<vertAlign/>': case '</vertAlign>': break;
|
|
|
|
|
|
|
|
/* 18.8.18 family CT_FontFamily */
|
2017-05-09 18:07:57 +00:00
|
|
|
case '<family': if(y.val) font.family = parseInt(y.val,10); break;
|
2017-03-19 06:50:30 +00:00
|
|
|
case '<family/>': case '</family>': break;
|
|
|
|
|
|
|
|
/* 18.8.35 scheme CT_FontScheme */
|
|
|
|
case '<scheme': if(y.val) font.scheme = y.val; break;
|
|
|
|
case '<scheme/>': case '</scheme>': break;
|
|
|
|
|
2017-05-09 18:07:57 +00:00
|
|
|
/* 18.4.1 charset CT_IntProperty */
|
2017-03-19 06:50:30 +00:00
|
|
|
case '<charset':
|
|
|
|
if(y.val == '1') break;
|
|
|
|
y.codepage = CS2CP[parseInt(y.val, 10)];
|
|
|
|
break;
|
|
|
|
|
2017-05-09 18:07:57 +00:00
|
|
|
/* 18.?.? color CT_Color */
|
2017-03-19 06:50:30 +00:00
|
|
|
case '<color':
|
|
|
|
if(!font.color) font.color = {};
|
2017-05-09 18:07:57 +00:00
|
|
|
if(y.auto) font.color.auto = parsexmlbool(y.auto);
|
|
|
|
|
2017-07-05 22:27:54 +00:00
|
|
|
if(y.rgb) font.color.rgb = y.rgb.slice(-6);
|
2017-05-09 18:07:57 +00:00
|
|
|
else if(y.indexed) {
|
|
|
|
font.color.index = parseInt(y.indexed, 10);
|
|
|
|
var icv = XLSIcv[font.color.index];
|
|
|
|
if(font.color.index == 81) icv = XLSIcv[1];
|
|
|
|
if(!icv) throw new Error(x);
|
|
|
|
font.color.rgb = icv[0].toString(16) + icv[1].toString(16) + icv[2].toString(16);
|
|
|
|
} else if(y.theme) {
|
|
|
|
font.color.theme = parseInt(y.theme, 10);
|
|
|
|
if(y.tint) font.color.tint = parseFloat(y.tint);
|
|
|
|
if(y.theme && themes.themeElements && themes.themeElements.clrScheme) {
|
|
|
|
font.color.rgb = rgb_tint(themes.themeElements.clrScheme[font.color.theme].rgb, font.color.tint || 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 06:50:30 +00:00
|
|
|
break;
|
|
|
|
case '<color/>': case '</color>': break;
|
|
|
|
|
2019-11-01 03:09:14 +00:00
|
|
|
/* note: sometimes mc:AlternateContent appears bare */
|
|
|
|
case '<AlternateContent': pass = true; break;
|
|
|
|
case '</AlternateContent>': pass = false; break;
|
|
|
|
|
2018-05-05 06:34:37 +00:00
|
|
|
/* 18.2.10 extLst CT_ExtensionList ? */
|
|
|
|
case '<extLst': case '<extLst>': case '</extLst>': break;
|
|
|
|
case '<ext': pass = true; break;
|
|
|
|
case '</ext>': pass = false; break;
|
|
|
|
default: if(opts && opts.WTF) {
|
|
|
|
if(!pass) throw new Error('unrecognized ' + y[0] + ' in fonts');
|
|
|
|
}
|
2017-03-19 06:50:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
/* 18.8.31 numFmts CT_NumFmts */
|
2017-03-18 23:25:50 +00:00
|
|
|
function parse_numFmts(t, styles, opts) {
|
2014-01-28 16:38:02 +00:00
|
|
|
styles.NumberFmt = [];
|
2017-02-10 19:23:01 +00:00
|
|
|
var k/*Array<number>*/ = (keys(SSF._table)/*:any*/);
|
2014-07-28 13:22:32 +00:00
|
|
|
for(var i=0; i < k.length; ++i) styles.NumberFmt[k[i]] = SSF._table[k[i]];
|
2014-06-29 18:29:45 +00:00
|
|
|
var m = t[0].match(tagregex);
|
2017-02-10 19:23:01 +00:00
|
|
|
if(!m) return;
|
2014-07-28 13:22:32 +00:00
|
|
|
for(i=0; i < m.length; ++i) {
|
2014-06-29 18:29:45 +00:00
|
|
|
var y = parsexmltag(m[i]);
|
2018-05-22 00:59:54 +00:00
|
|
|
switch(strip_ns(y[0])) {
|
2014-05-22 12:16:51 +00:00
|
|
|
case '<numFmts': case '</numFmts>': case '<numFmts/>': case '<numFmts>': break;
|
2014-01-28 16:38:02 +00:00
|
|
|
case '<numFmt': {
|
2014-07-28 13:22:32 +00:00
|
|
|
var f=unescapexml(utf8read(y.formatCode)), j=parseInt(y.numFmtId,10);
|
2017-07-05 22:27:54 +00:00
|
|
|
styles.NumberFmt[j] = f;
|
|
|
|
if(j>0) {
|
|
|
|
if(j > 0x188) {
|
|
|
|
for(j = 0x188; j > 0x3c; --j) if(styles.NumberFmt[j] == null) break;
|
|
|
|
styles.NumberFmt[j] = f;
|
|
|
|
}
|
|
|
|
SSF.load(f,j);
|
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
} break;
|
2017-03-10 08:39:51 +00:00
|
|
|
case '</numFmt>': break;
|
2017-02-10 19:23:01 +00:00
|
|
|
default: if(opts.WTF) throw new Error('unrecognized ' + y[0] + ' in numFmts');
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 09:07:51 +00:00
|
|
|
function write_numFmts(NF/*:{[n:number|string]:string}*//*::, opts*/) {
|
2014-06-29 18:29:45 +00:00
|
|
|
var o = ["<numFmts>"];
|
2017-03-25 01:36:40 +00:00
|
|
|
[[5,8],[23,26],[41,44],[/*63*/50,/*66],[164,*/392]].forEach(function(r) {
|
2017-03-19 06:50:30 +00:00
|
|
|
for(var i = r[0]; i <= r[1]; ++i) if(NF[i] != null) o[o.length] = (writextag('numFmt',null,{numFmtId:i,formatCode:escapexml(NF[i])}));
|
2014-05-16 00:33:34 +00:00
|
|
|
});
|
2014-07-28 13:22:32 +00:00
|
|
|
if(o.length === 1) return "";
|
2014-06-29 18:29:45 +00:00
|
|
|
o[o.length] = ("</numFmts>");
|
2014-05-16 00:33:34 +00:00
|
|
|
o[0] = writextag('numFmts', null, { count:o.length-2 }).replace("/>", ">");
|
|
|
|
return o.join("");
|
|
|
|
}
|
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
/* 18.8.10 cellXfs CT_CellXfs */
|
2017-06-10 01:47:42 +00:00
|
|
|
var cellXF_uint = [ "numFmtId", "fillId", "fontId", "borderId", "xfId" ];
|
|
|
|
var cellXF_bool = [ "applyAlignment", "applyBorder", "applyFill", "applyFont", "applyNumberFormat", "applyProtection", "pivotButton", "quotePrefix" ];
|
2017-03-18 23:25:50 +00:00
|
|
|
function parse_cellXfs(t, styles, opts) {
|
2014-01-28 16:38:02 +00:00
|
|
|
styles.CellXf = [];
|
2017-03-19 06:50:30 +00:00
|
|
|
var xf;
|
2018-05-05 06:34:37 +00:00
|
|
|
var pass = false;
|
2019-11-01 03:09:14 +00:00
|
|
|
(t[0].match(tagregex)||[]).forEach(function(x) {
|
2017-06-10 01:47:42 +00:00
|
|
|
var y = parsexmltag(x), i = 0;
|
2018-05-22 00:59:54 +00:00
|
|
|
switch(strip_ns(y[0])) {
|
2014-05-22 12:16:51 +00:00
|
|
|
case '<cellXfs': case '<cellXfs>': case '<cellXfs/>': case '</cellXfs>': break;
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* 18.8.45 xf CT_Xf */
|
2017-07-05 22:27:54 +00:00
|
|
|
case '<xf': case '<xf/>':
|
2017-03-19 06:50:30 +00:00
|
|
|
xf = y;
|
|
|
|
delete xf[0];
|
2017-06-10 01:47:42 +00:00
|
|
|
for(i = 0; i < cellXF_uint.length; ++i) if(xf[cellXF_uint[i]])
|
|
|
|
xf[cellXF_uint[i]] = parseInt(xf[cellXF_uint[i]], 10);
|
|
|
|
for(i = 0; i < cellXF_bool.length; ++i) if(xf[cellXF_bool[i]])
|
2018-01-23 09:07:51 +00:00
|
|
|
xf[cellXF_bool[i]] = parsexmlbool(xf[cellXF_bool[i]]);
|
2017-07-05 22:27:54 +00:00
|
|
|
if(xf.numFmtId > 0x188) {
|
|
|
|
for(i = 0x188; i > 0x3c; --i) if(styles.NumberFmt[xf.numFmtId] == styles.NumberFmt[i]) { xf.numFmtId = i; break; }
|
|
|
|
}
|
2017-03-19 06:50:30 +00:00
|
|
|
styles.CellXf.push(xf); break;
|
2014-01-28 16:38:02 +00:00
|
|
|
case '</xf>': break;
|
|
|
|
|
|
|
|
/* 18.8.1 alignment CT_CellAlignment */
|
2017-03-19 06:50:30 +00:00
|
|
|
case '<alignment': case '<alignment/>':
|
|
|
|
var alignment = {};
|
|
|
|
if(y.vertical) alignment.vertical = y.vertical;
|
|
|
|
if(y.horizontal) alignment.horizontal = y.horizontal;
|
|
|
|
if(y.textRotation != null) alignment.textRotation = y.textRotation;
|
|
|
|
if(y.indent) alignment.indent = y.indent;
|
2019-11-01 03:09:14 +00:00
|
|
|
if(y.wrapText) alignment.wrapText = parsexmlbool(y.wrapText);
|
2017-03-19 06:50:30 +00:00
|
|
|
xf.alignment = alignment;
|
|
|
|
break;
|
|
|
|
case '</alignment>': break;
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* 18.8.33 protection CT_CellProtection */
|
2019-11-01 03:09:14 +00:00
|
|
|
case '<protection':
|
|
|
|
break;
|
|
|
|
case '</protection>': case '<protection/>': break;
|
|
|
|
|
|
|
|
/* note: sometimes mc:AlternateContent appears bare */
|
|
|
|
case '<AlternateContent': pass = true; break;
|
|
|
|
case '</AlternateContent>': pass = false; break;
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2017-03-19 06:50:30 +00:00
|
|
|
/* 18.2.10 extLst CT_ExtensionList ? */
|
2018-05-05 06:34:37 +00:00
|
|
|
case '<extLst': case '<extLst>': case '</extLst>': break;
|
|
|
|
case '<ext': pass = true; break;
|
|
|
|
case '</ext>': pass = false; break;
|
|
|
|
default: if(opts && opts.WTF) {
|
|
|
|
if(!pass) throw new Error('unrecognized ' + y[0] + ' in cellXfs');
|
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function write_cellXfs(cellXfs)/*:string*/ {
|
2017-12-30 05:40:35 +00:00
|
|
|
var o/*:Array<string>*/ = [];
|
2014-06-29 18:29:45 +00:00
|
|
|
o[o.length] = (writextag('cellXfs',null));
|
2019-11-01 03:09:14 +00:00
|
|
|
cellXfs.forEach(function(c) {
|
|
|
|
o[o.length] = (writextag('xf', null, c));
|
|
|
|
});
|
2014-06-29 18:29:45 +00:00
|
|
|
o[o.length] = ("</cellXfs>");
|
2014-05-16 00:33:34 +00:00
|
|
|
if(o.length === 2) return "";
|
|
|
|
o[0] = writextag('cellXfs',null, {count:o.length-2}).replace("/>",">");
|
|
|
|
return o.join("");
|
|
|
|
}
|
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
/* 18.8 Styles CT_Stylesheet*/
|
2014-07-28 13:22:32 +00:00
|
|
|
var parse_sty_xml= (function make_pstyx() {
|
2018-05-22 00:59:54 +00:00
|
|
|
var numFmtRegex = /<(?:\w+:)?numFmts([^>]*)>[\S\s]*?<\/(?:\w+:)?numFmts>/;
|
|
|
|
var cellXfRegex = /<(?:\w+:)?cellXfs([^>]*)>[\S\s]*?<\/(?:\w+:)?cellXfs>/;
|
|
|
|
var fillsRegex = /<(?:\w+:)?fills([^>]*)>[\S\s]*?<\/(?:\w+:)?fills>/;
|
|
|
|
var fontsRegex = /<(?:\w+:)?fonts([^>]*)>[\S\s]*?<\/(?:\w+:)?fonts>/;
|
|
|
|
var bordersRegex = /<(?:\w+:)?borders([^>]*)>[\S\s]*?<\/(?:\w+:)?borders>/;
|
2014-07-28 13:22:32 +00:00
|
|
|
|
2017-03-19 06:50:30 +00:00
|
|
|
return function parse_sty_xml(data, themes, opts) {
|
2017-03-18 23:25:50 +00:00
|
|
|
var styles = {};
|
2017-02-10 19:23:01 +00:00
|
|
|
if(!data) return styles;
|
2017-07-05 22:27:54 +00:00
|
|
|
data = data.replace(/<!--([\s\S]*?)-->/mg,"").replace(/<!DOCTYPE[^\[]*\[[^\]]*\]>/gm,"");
|
2014-01-28 16:38:02 +00:00
|
|
|
/* 18.8.39 styleSheet CT_Stylesheet */
|
|
|
|
var t;
|
|
|
|
|
2017-03-19 06:50:30 +00:00
|
|
|
/* 18.8.31 numFmts CT_NumFmts ? */
|
2017-03-18 23:25:50 +00:00
|
|
|
if((t=data.match(numFmtRegex))) parse_numFmts(t, styles, opts);
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2017-03-19 06:50:30 +00:00
|
|
|
/* 18.8.23 fonts CT_Fonts ? */
|
|
|
|
if((t=data.match(fontsRegex))) parse_fonts(t, styles, themes, opts);
|
|
|
|
|
2017-05-09 18:07:57 +00:00
|
|
|
/* 18.8.21 fills CT_Fills ? */
|
2017-03-19 06:50:30 +00:00
|
|
|
if((t=data.match(fillsRegex))) parse_fills(t, styles, themes, opts);
|
2014-05-29 06:18:23 +00:00
|
|
|
|
2017-05-09 18:07:57 +00:00
|
|
|
/* 18.8.5 borders CT_Borders ? */
|
2017-03-19 06:50:30 +00:00
|
|
|
if((t=data.match(bordersRegex))) parse_borders(t, styles, themes, opts);
|
2014-05-29 06:18:23 +00:00
|
|
|
|
2017-05-09 18:07:57 +00:00
|
|
|
/* 18.8.9 cellStyleXfs CT_CellStyleXfs ? */
|
2020-03-15 07:42:05 +00:00
|
|
|
/* 18.8.8 cellStyles CT_CellStyles ? */
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2017-03-19 06:50:30 +00:00
|
|
|
/* 18.8.10 cellXfs CT_CellXfs ? */
|
2017-03-18 23:25:50 +00:00
|
|
|
if((t=data.match(cellXfRegex))) parse_cellXfs(t, styles, opts);
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2017-03-19 06:50:30 +00:00
|
|
|
/* 18.8.15 dxfs CT_Dxfs ? */
|
|
|
|
/* 18.8.42 tableStyles CT_TableStyles ? */
|
|
|
|
/* 18.8.11 colors CT_Colors ? */
|
|
|
|
/* 18.2.10 extLst CT_ExtensionList ? */
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
return styles;
|
2014-07-28 13:22:32 +00:00
|
|
|
};
|
|
|
|
})();
|
2014-05-16 00:33:34 +00:00
|
|
|
|
|
|
|
var STYLES_XML_ROOT = writextag('styleSheet', null, {
|
|
|
|
'xmlns': XMLNS.main[0],
|
|
|
|
'xmlns:vt': XMLNS.vt
|
|
|
|
});
|
|
|
|
|
|
|
|
RELS.STY = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function write_sty_xml(wb/*:Workbook*/, opts)/*:string*/ {
|
2014-07-28 13:22:32 +00:00
|
|
|
var o = [XML_HEADER, STYLES_XML_ROOT], w;
|
2017-03-12 18:02:43 +00:00
|
|
|
if(wb.SSF && (w = write_numFmts(wb.SSF)) != null) o[o.length] = w;
|
2014-06-29 18:29:45 +00:00
|
|
|
o[o.length] = ('<fonts count="1"><font><sz val="12"/><color theme="1"/><name val="Calibri"/><family val="2"/><scheme val="minor"/></font></fonts>');
|
|
|
|
o[o.length] = ('<fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills>');
|
|
|
|
o[o.length] = ('<borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders>');
|
|
|
|
o[o.length] = ('<cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs>');
|
|
|
|
if((w = write_cellXfs(opts.cellXfs))) o[o.length] = (w);
|
|
|
|
o[o.length] = ('<cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>');
|
|
|
|
o[o.length] = ('<dxfs count="0"/>');
|
|
|
|
o[o.length] = ('<tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleMedium4"/>');
|
|
|
|
|
|
|
|
if(o.length>2){ o[o.length] = ('</styleSheet>'); o[1]=o[1].replace("/>",">"); }
|
2014-05-16 00:33:34 +00:00
|
|
|
return o.join("");
|
|
|
|
}
|