/* 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:{}, xmlns: "" };
var pass = false, xmlns = "xmlns";
(data.match(tagregex)||[]).forEach(function xml_wb(x) {
var y = 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 '': delete y[0]; wb.WBProps = y; 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 '': 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 '': 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=false; break;
default: if(!pass && opts.WTF) throw new Error('unrecognized ' + y[0] + ' in workbook');
}
});
if(XMLNS.main.indexOf(wb.xmlns) === -1) throw new Error("Unknown Namespace: " + wb.xmlns);
parse_wb_defaults(wb);
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
});
function safe1904(wb/*:Workbook*/)/*:string*/ {
/* TODO: store date1904 somewhere else */
if(!wb.Workbook) return "false";
if(!wb.Workbook.WBProps) return "false";
// $FlowIgnore
return parsexmlbool(wb.Workbook.WBProps.date1904) ? "true" : "false";
}
function write_wb_xml(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:string*/ {
var o = [XML_HEADER];
o[o.length] = WB_XML_ROOT;
o[o.length] = (writextag('workbookPr', null, {date1904:safe1904(wb)}));
o[o.length] = "";
for(var i = 0; i != wb.SheetNames.length; ++i)
o[o.length] = (writextag('sheet',null,{name:wb.SheetNames[i].substr(0,31), sheetId:""+(i+1), "r:id":"rId"+(i+1)}));
o[o.length] = "";
if(o.length>2){ o[o.length] = ''; o[1]=o[1].replace("/>",">"); }
return o.join("");
}