Skip to content

Commit 440c94c

Browse files
committed
ACI0105889 support option allowInvalidFormula and set it by default to true
When even with option the formula could not be set (same in excel) then set it as text and have a better log in js console
1 parent 09a5d66 commit 440c94c

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

Resources/schemas/SJS.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@
187187
"type": "boolean",
188188
"default": true
189189
},
190+
"allowInvalidFormula": {
191+
"type": "boolean",
192+
"default": true
193+
},
190194
"referenceStyle": {
191195
"$ref": "#/definitions/ReferenceStyle",
192196
"default": 0

Resources/scripts/commands/values.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,17 @@
375375
Utils.getRanges(range, instancesArray);
376376

377377
instancesArray.forEach(i => {
378-
let instance = i.sheet.getRange(i.row, i.column, i.rowCount, i.columnCount);
379-
380-
instance.formula(params.formula);
378+
const instance = i.sheet.getRange(i.row, i.column, i.rowCount, i.columnCount);
379+
try {
380+
instance.formula(params.formula);
381+
}
382+
catch(e) {
383+
Utils.logEvent({ type: 'error-catched', data: e, formula: params.formula});
384+
if (Utils.spread.options.allowInvalidFormula == true) {
385+
instance.formula(null);
386+
instance.value("=" + params.formula);
387+
}
388+
}
381389

382390
if (format != null) {
383391
instance.formatter(format);

Resources/scripts/commands/workbook.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'allowCopyPasteExcelStyle',
2424
'allowDynamicArray',
2525
'allowExtendPasteRange',
26+
'allowInvalidFormula',
2627
'allowSheetReorder',
2728
'allowUndo',
2829
'allowUserDeselect',

Resources/scripts/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ document.addEventListener('DOMContentLoaded', function () {
717717
// Allow users to enter mathematical formula.
718718
Utils.spread.options.allowUserEditFormula = true;
719719
Utils.spread.options.enableFormulaTextbox = true;
720+
Utils.spread.options.allowInvalidFormula = true;
720721

721722
if ((vp_localizedFolder !== 'ja.lproj') && (vp_localizedFolder !== 'en.lproj')) {
722723
let sheetName = vp_spreadJsResources.Sheets.SHEET_NAME;

Resources/scripts/utils.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,18 @@ Utils.diagnostics = {
9393
events: []
9494
};
9595

96-
Utils.logEvent = function ({ type, data }) {
96+
Utils.logEvent = function (eventData) {
9797
if (Utils.diagnostics.events.length >= 500) {
9898
Utils.diagnostics.events = [];
9999
}
100-
101-
Utils.diagnostics.events.push({
100+
const event = {
102101
time: new Date(),
103-
type,
104-
data
105-
});
106-
}
102+
...eventData
103+
};
104+
105+
Utils.diagnostics.events.push(event);
106+
if (Utils.debug || (eventData.type && eventData.type.includes("error"))) console.log(event);
107+
};
107108

108109
Utils.adjustFormat = function (format) {
109110
let propertyName = '';

0 commit comments

Comments
 (0)