2014-01-28 16:38:02 +00:00
|
|
|
/* [MS-XLSB] 2.4.301 BrtBundleSh */
|
2017-02-10 19:23:01 +00:00
|
|
|
function parse_BrtBundleSh(data, length/*:number*/) {
|
2014-01-28 16:38:02 +00:00
|
|
|
var z = {};
|
2017-03-31 18:46:42 +00:00
|
|
|
z.Hidden = data.read_shift(4); //hsState ST_SheetState
|
2014-01-28 16:38:02 +00:00
|
|
|
z.iTabID = data.read_shift(4);
|
|
|
|
z.strRelID = parse_RelID(data,length-8);
|
|
|
|
z.name = parse_XLWideString(data);
|
|
|
|
return z;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
function write_BrtBundleSh(data, o) {
|
2014-05-29 22:30:03 +00:00
|
|
|
if(!o) o = new_buf(127);
|
2017-03-31 18:46:42 +00:00
|
|
|
o.write_shift(4, data.Hidden);
|
2014-05-29 22:30:03 +00:00
|
|
|
o.write_shift(4, data.iTabID);
|
|
|
|
write_RelID(data.strRelID, o);
|
2014-05-31 15:44:56 +00:00
|
|
|
write_XLWideString(data.name.substr(0,31), o);
|
2017-02-03 20:50:45 +00:00
|
|
|
return o.length > o.l ? o.slice(0, o.l) : o;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-05-29 22:30:03 +00:00
|
|
|
|
|
|
|
/* [MS-XLSB] 2.4.807 BrtWbProp */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtWbProp(data, length) {
|
2014-05-29 22:30:03 +00:00
|
|
|
data.read_shift(4);
|
|
|
|
var dwThemeVersion = data.read_shift(4);
|
|
|
|
var strName = (length > 8) ? parse_XLWideString(data) : "";
|
|
|
|
return [dwThemeVersion, strName];
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
function write_BrtWbProp(data, o) {
|
2017-03-31 00:47:35 +00:00
|
|
|
if(!o) o = new_buf(68);
|
2014-05-29 22:30:03 +00:00
|
|
|
o.write_shift(4, 0);
|
|
|
|
o.write_shift(4, 0);
|
2017-03-31 00:47:35 +00:00
|
|
|
write_XLSBCodeName("ThisWorkbook", o);
|
|
|
|
return o.slice(0, o.l);
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-05-29 22:30:03 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtFRTArchID$(data, length) {
|
2014-05-29 22:30:03 +00:00
|
|
|
var o = {};
|
|
|
|
data.read_shift(4);
|
|
|
|
o.ArchID = data.read_shift(4);
|
|
|
|
data.l += length - 8;
|
|
|
|
return o;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2017-02-19 20:36:32 +00:00
|
|
|
/* [MS-XLSB] 2.4.680 BrtName */
|
|
|
|
function parse_BrtName(data, length, opts) {
|
|
|
|
var end = data.l + length;
|
|
|
|
var flags = data.read_shift(4);
|
|
|
|
var chKey = data.read_shift(1);
|
|
|
|
var itab = data.read_shift(4);
|
|
|
|
var name = parse_XLNameWideString(data);
|
|
|
|
var formula = parse_XLSBNameParsedFormula(data, 0, opts);
|
|
|
|
var comment = parse_XLNullableWideString(data);
|
2017-03-31 00:47:35 +00:00
|
|
|
//if(0 /* fProc */) {
|
2017-02-19 20:36:32 +00:00
|
|
|
// unusedstring1: XLNullableWideString
|
|
|
|
// description: XLNullableWideString
|
|
|
|
// helpTopic: XLNullableWideString
|
|
|
|
// unusedstring2: XLNullableWideString
|
2017-03-31 00:47:35 +00:00
|
|
|
//}
|
2017-02-19 20:36:32 +00:00
|
|
|
data.l = end;
|
|
|
|
return {Name:name, Ptg:formula, Comment:comment};
|
|
|
|
}
|
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
/* [MS-XLSB] 2.1.7.60 Workbook */
|
2017-03-12 18:02:43 +00:00
|
|
|
function parse_wb_bin(data, opts)/*:WorkbookFile*/ {
|
2014-01-28 16:38:02 +00:00
|
|
|
var wb = { AppVersion:{}, WBProps:{}, WBView:[], Sheets:[], CalcPr:{}, xmlns: "" };
|
2014-01-29 06:00:09 +00:00
|
|
|
var pass = false, z;
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2017-02-19 20:36:32 +00:00
|
|
|
if(!opts) opts = {};
|
|
|
|
opts.biff = 12;
|
|
|
|
|
|
|
|
var Names = {}, NameList = [];
|
|
|
|
|
2017-04-08 06:55:35 +00:00
|
|
|
recordhopper(data, function hopper_wb(val, R, RT) {
|
2014-01-28 16:38:02 +00:00
|
|
|
switch(R.n) {
|
|
|
|
case 'BrtBundleSh': wb.Sheets.push(val); break;
|
|
|
|
|
2017-02-19 20:36:32 +00:00
|
|
|
case 'BrtName':
|
|
|
|
Names[val.Name] = val; NameList.push(val.Name);
|
|
|
|
break;
|
2017-04-08 06:55:35 +00:00
|
|
|
case 'BrtNameExt': break;
|
2017-02-19 20:36:32 +00:00
|
|
|
|
2014-02-17 08:44:22 +00:00
|
|
|
case 'BrtAbsPath15': break;
|
|
|
|
case 'BrtBookProtection': break;
|
2017-04-08 06:55:35 +00:00
|
|
|
case 'BrtBookProtectionIso': break;
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'BrtBookView': break;
|
|
|
|
case 'BrtCalcProp': break;
|
2017-04-08 06:55:35 +00:00
|
|
|
case 'BrtCrashRecErr': break;
|
|
|
|
case 'BrtDecoupledPivotCacheID': break;
|
|
|
|
case 'BrtExternSheet': break;
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'BrtFileRecover': break;
|
2014-03-29 02:05:50 +00:00
|
|
|
case 'BrtFileSharing': break;
|
2017-04-08 06:55:35 +00:00
|
|
|
case 'BrtFileSharingIso': break;
|
|
|
|
case 'BrtFileVersion': break;
|
|
|
|
case 'BrtFnGroup': break;
|
|
|
|
case 'BrtModelRelationship': break;
|
|
|
|
case 'BrtModelTable': break;
|
|
|
|
case 'BrtModelTimeGroupingCalcCol': break;
|
|
|
|
case 'BrtOleSize': break;
|
|
|
|
case 'BrtPivotTableRef': break;
|
|
|
|
case 'BrtPlaceholderName': break;
|
|
|
|
case 'BrtRevisionPtr': break;
|
2014-07-28 13:22:32 +00:00
|
|
|
case 'BrtSmartTagType': break;
|
2017-04-08 06:55:35 +00:00
|
|
|
case 'BrtSupAddin': break;
|
|
|
|
case 'BrtSupBookSrc': break;
|
|
|
|
case 'BrtSupSame': break;
|
|
|
|
case 'BrtSupSelf': break;
|
|
|
|
case 'BrtTableSlicerCacheID': break;
|
|
|
|
case 'BrtTableSlicerCacheIDs': break;
|
|
|
|
case 'BrtTimelineCachePivotCacheID': break;
|
|
|
|
case 'BrtUid': break;
|
|
|
|
case 'BrtUserBookView': break;
|
|
|
|
case 'BrtWbFactoid': break;
|
|
|
|
case 'BrtWbProp': break;
|
|
|
|
case 'BrtWbProp14': break;
|
|
|
|
case 'BrtWebOpt': break;
|
|
|
|
case 'BrtWorkBookPr15': break;
|
2014-07-28 13:22:32 +00:00
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'BrtFRTBegin': pass = true; break;
|
|
|
|
case 'BrtFRTEnd': pass = false; break;
|
2017-04-08 06:55:35 +00:00
|
|
|
case 'BrtACBegin': break;
|
|
|
|
case 'BrtACEnd': break;
|
|
|
|
|
|
|
|
case 'BrtFRTArchID$': break;
|
|
|
|
default:
|
|
|
|
if((R.n||"").indexOf("Begin") > 0){}
|
|
|
|
else if((R.n||"").indexOf("End") > 0){}
|
|
|
|
else if(!pass || opts.WTF) throw new Error("Unexpected record " + RT + " " + R.n);
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
2017-02-19 20:36:32 +00:00
|
|
|
}, opts);
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
parse_wb_defaults(wb);
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2017-02-19 20:36:32 +00:00
|
|
|
Names['!names'] = NameList;
|
2017-03-12 18:02:43 +00:00
|
|
|
// $FlowIgnore
|
2017-02-19 20:36:32 +00:00
|
|
|
wb.Names = Names;
|
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
return wb;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2014-05-29 22:30:03 +00:00
|
|
|
/* [MS-XLSB] 2.1.7.60 Workbook */
|
|
|
|
function write_BUNDLESHS(ba, wb, opts) {
|
|
|
|
write_record(ba, "BrtBeginBundleShs");
|
2014-06-29 18:29:45 +00:00
|
|
|
for(var idx = 0; idx != wb.SheetNames.length; ++idx) {
|
2017-03-31 18:46:42 +00:00
|
|
|
var viz = wb.Workbook && wb.Workbook.Sheets && wb.Workbook.Sheets[idx] && wb.Workbook.Sheets[idx].Hidden || 0;
|
|
|
|
var d = { Hidden: viz, iTabID: idx+1, strRelID: 'rId' + (idx+1), name: wb.SheetNames[idx] };
|
2014-05-29 22:30:03 +00:00
|
|
|
write_record(ba, "BrtBundleSh", write_BrtBundleSh(d));
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-05-29 22:30:03 +00:00
|
|
|
write_record(ba, "BrtEndBundleShs");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [MS-XLSB] 2.4.643 BrtFileVersion */
|
|
|
|
function write_BrtFileVersion(data, o) {
|
|
|
|
if(!o) o = new_buf(127);
|
|
|
|
for(var i = 0; i != 4; ++i) o.write_shift(4, 0);
|
|
|
|
write_XLWideString("SheetJS", o);
|
|
|
|
write_XLWideString(XLSX.version, o);
|
|
|
|
write_XLWideString(XLSX.version, o);
|
|
|
|
write_XLWideString("7262", o);
|
|
|
|
o.length = o.l;
|
2017-02-03 20:50:45 +00:00
|
|
|
return o.length > o.l ? o.slice(0, o.l) : o;
|
2014-05-29 22:30:03 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 18:46:42 +00:00
|
|
|
/* [MS-XLSB] 2.4.298 BrtBookView */
|
|
|
|
function write_BrtBookView(idx, o) {
|
|
|
|
if(!o) o = new_buf(29);
|
|
|
|
o.write_shift(-4, 0);
|
|
|
|
o.write_shift(-4, 460);
|
|
|
|
o.write_shift(4, 28800);
|
|
|
|
o.write_shift(4, 17600);
|
|
|
|
o.write_shift(4, 500);
|
|
|
|
o.write_shift(4, idx);
|
|
|
|
o.write_shift(4, idx);
|
|
|
|
var flags = 0x78;
|
|
|
|
o.write_shift(1, flags);
|
|
|
|
return o.length > o.l ? o.slice(0, o.l) : o;
|
|
|
|
}
|
|
|
|
|
2014-05-29 22:30:03 +00:00
|
|
|
/* [MS-XLSB] 2.1.7.60 Workbook */
|
|
|
|
function write_BOOKVIEWS(ba, wb, opts) {
|
2017-03-31 18:46:42 +00:00
|
|
|
/* required if hidden tab appears before visible tab */
|
|
|
|
if(!wb.Workbook || !wb.Workbook.Sheets) return;
|
|
|
|
var sheets = wb.Workbook.Sheets;
|
|
|
|
var i = 0, vistab = -1, hidden = -1;
|
|
|
|
for(; i < sheets.length; ++i) {
|
|
|
|
if(!sheets[i] || !sheets[i].Hidden && vistab == -1) vistab = i;
|
|
|
|
else if(sheets[i].Hidden == 1 && hidden == -1) hidden = i;
|
|
|
|
}
|
|
|
|
if(hidden > vistab) return;
|
2014-05-29 22:30:03 +00:00
|
|
|
write_record(ba, "BrtBeginBookViews");
|
2017-03-31 18:46:42 +00:00
|
|
|
write_record(ba, "BrtBookView", write_BrtBookView(vistab));
|
2014-05-29 22:30:03 +00:00
|
|
|
/* 1*(BrtBookView *FRT) */
|
|
|
|
write_record(ba, "BrtEndBookViews");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [MS-XLSB] 2.4.302 BrtCalcProp */
|
|
|
|
function write_BrtCalcProp(data, o) {
|
|
|
|
if(!o) o = new_buf(26);
|
|
|
|
o.write_shift(4,0); /* force recalc */
|
|
|
|
o.write_shift(4,1);
|
|
|
|
o.write_shift(4,0);
|
|
|
|
write_Xnum(0, o);
|
|
|
|
o.write_shift(-4, 1023);
|
|
|
|
o.write_shift(1, 0x33);
|
|
|
|
o.write_shift(1, 0x00);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2017-02-03 20:50:45 +00:00
|
|
|
/* [MS-XLSB] 2.4.640 BrtFileRecover */
|
2014-05-29 22:30:03 +00:00
|
|
|
function write_BrtFileRecover(data, o) {
|
|
|
|
if(!o) o = new_buf(1);
|
|
|
|
o.write_shift(1,0);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [MS-XLSB] 2.1.7.60 Workbook */
|
2014-06-29 18:29:45 +00:00
|
|
|
function write_wb_bin(wb, opts) {
|
2014-05-29 22:30:03 +00:00
|
|
|
var ba = buf_array();
|
|
|
|
write_record(ba, "BrtBeginBook");
|
|
|
|
write_record(ba, "BrtFileVersion", write_BrtFileVersion());
|
|
|
|
/* [[BrtFileSharingIso] BrtFileSharing] */
|
2017-03-31 00:47:35 +00:00
|
|
|
write_record(ba, "BrtWbProp", write_BrtWbProp());
|
2014-05-29 22:30:03 +00:00
|
|
|
/* [ACABSPATH] */
|
|
|
|
/* [[BrtBookProtectionIso] BrtBookProtection] */
|
2017-03-31 18:46:42 +00:00
|
|
|
write_BOOKVIEWS(ba, wb, opts);
|
2014-05-29 22:30:03 +00:00
|
|
|
write_BUNDLESHS(ba, wb, opts);
|
|
|
|
/* [FNGROUP] */
|
|
|
|
/* [EXTERNALS] */
|
|
|
|
/* *BrtName */
|
2017-03-31 00:47:35 +00:00
|
|
|
/* write_record(ba, "BrtCalcProp", write_BrtCalcProp()); */
|
2014-05-29 22:30:03 +00:00
|
|
|
/* [BrtOleSize] */
|
|
|
|
/* *(BrtUserBookView *FRT) */
|
|
|
|
/* [PIVOTCACHEIDS] */
|
|
|
|
/* [BrtWbFactoid] */
|
|
|
|
/* [SMARTTAGTYPES] */
|
|
|
|
/* [BrtWebOpt] */
|
2017-03-31 00:47:35 +00:00
|
|
|
/* write_record(ba, "BrtFileRecover", write_BrtFileRecover()); */
|
2014-05-29 22:30:03 +00:00
|
|
|
/* [WEBPUBITEMS] */
|
|
|
|
/* [CRERRS] */
|
|
|
|
/* FRTWORKBOOK */
|
|
|
|
write_record(ba, "BrtEndBook");
|
2014-05-16 00:33:34 +00:00
|
|
|
|
2014-05-29 22:30:03 +00:00
|
|
|
return ba.end();
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|