/* 18.2 Workbook */
function parse_wb_xml(data) {
var wb = { AppVersion:{}, WBProps:{}, WBView:[], Sheets:[], CalcPr:{}, xmlns: "" };
var pass = false, xmlns = "xmlns";
data.match(/<[^>]*>/g).forEach(function(x) {
var y = parsexmltag(x);
switch(y[0].replace(/<\w+:/,"<")) {
case '': break;
/* 18.2.13 fileVersion CT_FileVersion ? */
case '': break;
/* 18.2.12 fileSharing CT_FileSharing ? */
case '': break;
/* 18.2.28 workbookPr CT_WorkbookPr ? */
case '': delete y[0]; wb.WBProps = y; break;
/* 18.2.29 workbookProtection CT_WorkbookProtection ? */
case '': break;
/* 18.2.1 bookViews CT_BookViews ? */
case '': case '': break;
/* 18.2.30 workbookView CT_BookView + */
case '': case '': break; // aggregate sheet
/* 18.2.19 sheet CT_Sheet + */
case '': break;
/* 18.2.14 functionGroup CT_FunctionGroup + */
case '': break;
/* 18.2.8 externalReference CT_ExternalReference + */
case '': break;
case '': pass=true; break;
case '': pass=false; break;
/* 18.2.5 definedName CT_DefinedName + */
case '': case '': break;
/* 18.2.2 calcPr CT_CalcPr ? */
case '': delete y[0]; wb.CalcPr = y; break;
/* 18.2.16 oleSize CT_OleSize ? (ref required) */
case '': case '': case '': break;
/* 18.2.18 pivotCaches CT_PivotCaches ? */
case '': case '': case '': break;
/* 18.2.23 smartTagTypes CT_SmartTagTypes ? */
case '': case '': break;
/* 18.2.22 smartTagType CT_SmartTagType ? */
case '': break;
/* 18.2.11 fileRecoveryPr CT_FileRecoveryPr ? */
case '': break;
/* 18.2.26 webPublishObjects CT_WebPublishObjects ? */
case '': case '': break;
/* 18.2.25 webPublishObject CT_WebPublishObject ? */
case '': case '': case '': break;
/* 18.2.7 ext CT_Extension + */
case '': pass=false; break;
/* Others */
case '': pass=false; break;
}
});
if(XMLNS.main.indexOf(wb.xmlns) === -1) throw new Error("Unknown Namespace: " + wb.xmlns);
var z;
/* defaults */
for(z in WBPropsDef) if(typeof wb.WBProps[z] === 'undefined') wb.WBProps[z] = WBPropsDef[z];
for(z in CalcPrDef) if(typeof wb.CalcPr[z] === 'undefined') wb.CalcPr[z] = CalcPrDef[z];
wb.WBView.forEach(function(w){for(var z in WBViewDef) if(typeof w[z] === 'undefined') w[z]=WBViewDef[z]; });
wb.Sheets.forEach(function(w){for(var z in SheetDef) if(typeof w[z] === 'undefined') w[z]=SheetDef[z]; });
_ssfopts.date1904 = parsexmlbool(wb.WBProps.date1904, 'date1904');
return wb;
}
var WB_XML_ROOT = writextag('workbook', null, {
'xmlns': XMLNS.main[0],
//'xmlns:mx': XMLNS.mx,
//'xmlns:s': XMLNS.main[0],
'xmlns:r': XMLNS.r
});
var write_wb_xml = function(wb, opts) {
var o = [];
o.push(XML_HEADER);
o.push(WB_XML_ROOT);
/* TODO: put this somewhere else */
var date1904 = "false";
try { date1904 = parsexmlbool(wb.Workbook.WBProps.date1904) ? "true" : "false"; } catch(e) { date1904 = "false"; }
o.push(writextag('workbookPr', null, {date1904:date1904}));
o.push("");
var i = 1;
wb.SheetNames.forEach(function(s) {
o.push(writextag('sheet',null,{name:s, sheetId:String(i), "r:id":"rId"+i}));
++i;
});
o.push("");
if(o.length>2){ o.push(''); o[1]=o[1].replace("/>",">"); }
return o.join("");
};