/* 18.2 Workbook */
var wbnsregex = /<\w+:workbook/;
function parse_wb_xml(data, opts)/*:WorkbookFile*/ {
if(!data) throw new Error("Could not find file");
var wb = { AppVersion:{}, WBProps:{}, WBView:[], Sheets:[], CalcPr:{}, Names:[], xmlns: "" };
var pass = false, xmlns = "xmlns";
var dname = {}, dnstart = 0;
data.replace(tagregex, function xml_wb(x, idx) {
var y/*:any*/ = parsexmltag(x);
switch(strip_ns(y[0])) {
case '': break;
/* 18.2.13 fileVersion CT_FileVersion ? */
case '': case '': break;
/* 18.2.12 fileSharing CT_FileSharing ? */
case '': break;
/* 18.2.28 workbookPr CT_WorkbookPr ? */
case '':
WBPropsDef.forEach(function(w) {
if(y[w[0]] == null) return;
switch(w[2]) {
case "bool": wb.WBProps[w[0]] = parsexmlbool(y[w[0]]); break;
case "int": wb.WBProps[w[0]] = parseInt(y[w[0]], 10); break;
default: wb.WBProps[w[0]] = y[w[0]];
}
});
if(y.codeName) wb.WBProps.CodeName = y.codeName;
break;
case '': 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 '': delete y[0]; wb.WBView.push(y); break;
case '': break;
/* 18.2.20 sheets CT_Sheets 1 */
case '': case '': break; // aggregate sheet
/* 18.2.19 sheet CT_Sheet + */
case '': break;
/* 18.2.15 functionGroups CT_FunctionGroups ? */
case '': break;
/* 18.2.14 functionGroup CT_FunctionGroup + */
case '': case '': break;
/* 18.2.8 externalReference CT_ExternalReference + */
case '': break;
case '': case '': pass=false; break;
/* 18.2.5 definedName CT_DefinedName + */
case '': {
dname.Ref = data.slice(dnstart, idx);
wb.Names.push(dname);
} break;
case '': break;
/* 18.2.2 calcPr CT_CalcPr ? */
case '': delete y[0]; wb.CalcPr = y; break;
case '': 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=true; break;
case '': pass=false; break;
/* TODO */
case ' 0);
/* fileVersion */
/* fileSharing */
var workbookPr/*:any*/ = ({codeName:"ThisWorkbook"}/*:any*/);
if(wb.Workbook && wb.Workbook.WBProps) {
WBPropsDef.forEach(function(x) {
/*:: if(!wb.Workbook || !wb.Workbook.WBProps) throw "unreachable"; */
if((wb.Workbook.WBProps[x[0]]/*:any*/) == null) return;
if((wb.Workbook.WBProps[x[0]]/*:any*/) == x[1]) return;
workbookPr[x[0]] = (wb.Workbook.WBProps[x[0]]/*:any*/);
});
/*:: if(!wb.Workbook || !wb.Workbook.WBProps) throw "unreachable"; */
if(wb.Workbook.WBProps.CodeName) { workbookPr.codeName = wb.Workbook.WBProps.CodeName; delete workbookPr.CodeName; }
}
o[o.length] = (writextag('workbookPr', null, workbookPr));
/* workbookProtection */
/* bookViews */
o[o.length] = "";
var sheets = wb.Workbook && wb.Workbook.Sheets || [];
for(var i = 0; i != wb.SheetNames.length; ++i) {
var sht = ({name:escapexml(wb.SheetNames[i].slice(0,31))}/*:any*/);
sht.sheetId = ""+(i+1);
sht["r:id"] = "rId"+(i+1);
if(sheets[i]) switch(sheets[i].Hidden) {
case 1: sht.state = "hidden"; break;
case 2: sht.state = "veryHidden"; break;
}
o[o.length] = (writextag('sheet',null,sht));
}
o[o.length] = "";
/* functionGroups */
/* externalReferences */
if(write_names) {
o[o.length] = "";
if(wb.Workbook && wb.Workbook.Names) wb.Workbook.Names.forEach(function(n) {
var d/*:any*/ = {name:n.Name};
if(n.Comment) d.comment = n.Comment;
if(n.Sheet != null) d.localSheetId = ""+n.Sheet;
if(!n.Ref) return;
o[o.length] = writextag('definedName', String(n.Ref), d);
});
o[o.length] = "";
}
/* calcPr */
/* oleSize */
/* customWorkbookViews */
/* pivotCaches */
/* smartTagPr */
/* smartTagTypes */
/* webPublishing */
/* fileRecoveryPr */
/* webPublishObjects */
/* extLst */
if(o.length>2){ o[o.length] = ''; o[1]=o[1].replace("/>",">"); }
return o.join("");
}