2014-01-28 16:38:02 +00:00
|
|
|
/* 18.2.28 (CT_WorkbookProtection) Defaults */
|
2014-06-29 18:29:45 +00:00
|
|
|
var WBPropsDef = [
|
2017-06-01 21:22:11 +00:00
|
|
|
['allowRefreshQuery', false, "bool"],
|
|
|
|
['autoCompressPictures', true, "bool"],
|
|
|
|
['backupFile', false, "bool"],
|
|
|
|
['checkCompatibility', false, "bool"],
|
2017-11-20 01:51:14 +00:00
|
|
|
['CodeName', ''],
|
2017-06-01 21:22:11 +00:00
|
|
|
['date1904', false, "bool"],
|
|
|
|
['defaultThemeVersion', 0, "int"],
|
|
|
|
['filterPrivacy', false, "bool"],
|
|
|
|
['hidePivotFieldList', false, "bool"],
|
|
|
|
['promptedSolutions', false, "bool"],
|
|
|
|
['publishItems', false, "bool"],
|
|
|
|
['refreshAllConnections', false, "bool"],
|
|
|
|
['saveExternalLinkValues', true, "bool"],
|
|
|
|
['showBorderUnselectedTables', true, "bool"],
|
|
|
|
['showInkAnnotation', true, "bool"],
|
|
|
|
['showObjects', 'all'],
|
|
|
|
['showPivotChartFilter', false, "bool"],
|
|
|
|
['updateLinks', 'userSet']
|
2014-06-29 18:29:45 +00:00
|
|
|
];
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* 18.2.30 (CT_BookView) Defaults */
|
2014-06-29 18:29:45 +00:00
|
|
|
var WBViewDef = [
|
2017-06-01 21:22:11 +00:00
|
|
|
['activeTab', 0, "int"],
|
|
|
|
['autoFilterDateGrouping', true, "bool"],
|
|
|
|
['firstSheet', 0, "int"],
|
|
|
|
['minimized', false, "bool"],
|
|
|
|
['showHorizontalScroll', true, "bool"],
|
|
|
|
['showSheetTabs', true, "bool"],
|
|
|
|
['showVerticalScroll', true, "bool"],
|
|
|
|
['tabRatio', 600, "int"],
|
|
|
|
['visibility', 'visible']
|
2014-01-28 16:38:02 +00:00
|
|
|
//window{Height,Width}, {x,y}Window
|
2014-06-29 18:29:45 +00:00
|
|
|
];
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* 18.2.19 (CT_Sheet) Defaults */
|
2014-06-29 18:29:45 +00:00
|
|
|
var SheetDef = [
|
2017-03-31 18:46:42 +00:00
|
|
|
//['state', 'visible']
|
2014-06-29 18:29:45 +00:00
|
|
|
];
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* 18.2.2 (CT_CalcPr) Defaults */
|
2014-06-29 18:29:45 +00:00
|
|
|
var CalcPrDef = [
|
|
|
|
['calcCompleted', 'true'],
|
|
|
|
['calcMode', 'auto'],
|
|
|
|
['calcOnSave', 'true'],
|
|
|
|
['concurrentCalc', 'true'],
|
|
|
|
['fullCalcOnLoad', 'false'],
|
|
|
|
['fullPrecision', 'true'],
|
|
|
|
['iterate', 'false'],
|
|
|
|
['iterateCount', '100'],
|
|
|
|
['iterateDelta', '0.001'],
|
|
|
|
['refMode', 'A1']
|
|
|
|
];
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* 18.2.3 (CT_CustomWorkbookView) Defaults */
|
2014-06-29 18:29:45 +00:00
|
|
|
var CustomWBViewDef = [
|
|
|
|
['autoUpdate', 'false'],
|
|
|
|
['changesSavedWin', 'false'],
|
|
|
|
['includeHiddenRowCol', 'true'],
|
|
|
|
['includePrintSettings', 'true'],
|
|
|
|
['maximized', 'false'],
|
|
|
|
['minimized', 'false'],
|
|
|
|
['onlySync', 'false'],
|
|
|
|
['personalView', 'false'],
|
|
|
|
['showComments', 'commIndicator'],
|
|
|
|
['showFormulaBar', 'true'],
|
|
|
|
['showHorizontalScroll', 'true'],
|
|
|
|
['showObjects', 'all'],
|
|
|
|
['showSheetTabs', 'true'],
|
|
|
|
['showStatusbar', 'true'],
|
|
|
|
['showVerticalScroll', 'true'],
|
|
|
|
['tabRatio', '600'],
|
|
|
|
['xWindow', '0'],
|
|
|
|
['yWindow', '0']
|
|
|
|
];
|
|
|
|
|
|
|
|
function push_defaults_array(target, defaults) {
|
|
|
|
for(var j = 0; j != target.length; ++j) { var w = target[j];
|
|
|
|
for(var i=0; i != defaults.length; ++i) { var z = defaults[i];
|
|
|
|
if(w[z[0]] == null) w[z[0]] = z[1];
|
2017-06-01 21:22:11 +00:00
|
|
|
else switch(z[2]) {
|
|
|
|
case "bool": if(typeof w[z[0]] == "string") w[z[0]] = parsexmlbool(w[z[0]], z[0]); break;
|
|
|
|
case "int": if(typeof w[z[0]] == "string") w[z[0]] = parseInt(w[z[0]], 10); break;
|
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function push_defaults(target, defaults) {
|
|
|
|
for(var i = 0; i != defaults.length; ++i) { var z = defaults[i];
|
|
|
|
if(target[z[0]] == null) target[z[0]] = z[1];
|
2017-06-01 21:22:11 +00:00
|
|
|
else switch(z[2]) {
|
|
|
|
case "bool": if(typeof target[z[0]] == "string") target[z[0]] = parsexmlbool(target[z[0]], z[0]); break;
|
|
|
|
case "int": if(typeof target[z[0]] == "string") target[z[0]] = parseInt(target[z[0]], 10); break;
|
|
|
|
}
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function parse_wb_defaults(wb) {
|
|
|
|
push_defaults(wb.WBProps, WBPropsDef);
|
|
|
|
push_defaults(wb.CalcPr, CalcPrDef);
|
|
|
|
|
|
|
|
push_defaults_array(wb.WBView, WBViewDef);
|
|
|
|
push_defaults_array(wb.Sheets, SheetDef);
|
|
|
|
|
|
|
|
_ssfopts.date1904 = parsexmlbool(wb.WBProps.date1904, 'date1904');
|
|
|
|
}
|
2017-03-10 08:39:51 +00:00
|
|
|
|
2017-06-01 21:22:11 +00:00
|
|
|
function safe1904(wb/*:Workbook*/)/*:string*/ {
|
|
|
|
/* TODO: store date1904 somewhere else */
|
|
|
|
if(!wb.Workbook) return "false";
|
|
|
|
if(!wb.Workbook.WBProps) return "false";
|
|
|
|
return parsexmlbool(wb.Workbook.WBProps.date1904) ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
2017-05-11 07:29:59 +00:00
|
|
|
var badchars = "][*?\/\\".split("");
|
2017-05-13 18:21:22 +00:00
|
|
|
function check_ws_name(n/*:string*/, safe/*:?boolean*/)/*:boolean*/ {
|
2017-05-11 07:29:59 +00:00
|
|
|
if(n.length > 31) { if(safe) return false; throw new Error("Sheet names cannot exceed 31 chars"); }
|
|
|
|
var _good = true;
|
|
|
|
badchars.forEach(function(c) {
|
|
|
|
if(n.indexOf(c) == -1) return;
|
|
|
|
if(!safe) throw new Error("Sheet name cannot contain : \\ / ? * [ ]");
|
|
|
|
_good = false;
|
|
|
|
});
|
|
|
|
return _good;
|
|
|
|
}
|
2017-04-03 00:16:03 +00:00
|
|
|
function check_wb_names(N) {
|
|
|
|
N.forEach(function(n,i) {
|
2017-05-11 07:29:59 +00:00
|
|
|
check_ws_name(n);
|
2017-04-03 00:16:03 +00:00
|
|
|
for(var j = 0; j < i; ++j) if(n == N[j]) throw new Error("Duplicate Sheet Name: " + n);
|
|
|
|
});
|
|
|
|
}
|
2017-03-10 08:39:51 +00:00
|
|
|
function check_wb(wb) {
|
|
|
|
if(!wb || !wb.SheetNames || !wb.Sheets) throw new Error("Invalid Workbook");
|
2017-04-03 00:16:03 +00:00
|
|
|
check_wb_names(wb.SheetNames);
|
|
|
|
/* TODO: validate workbook */
|
2017-03-10 08:39:51 +00:00
|
|
|
}
|