Skip to content

Commit 760a505

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 f0398c9 commit 760a505

File tree

6 files changed

+29
-9
lines changed

6 files changed

+29
-9
lines changed

Project/Sources/Classes/workbookOptions.4dm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,17 @@ Function set allowExtendPasteRange($value : Boolean)
218218
This:C1470[""].options.allowExtendPasteRange:=$value
219219
VP SET WORKBOOK OPTIONS(This:C1470.area; {allowExtendPasteRange: $value})
220220

221+
// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
222+
Function get allowInvalidFormula() : Boolean
223+
224+
return This:C1470[""].options.allowInvalidFormula
225+
226+
// ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==>
227+
Function set allowInvalidFormula($value : Boolean)
228+
229+
This:C1470[""].options.allowInvalidFormula:=$value
230+
VP SET WORKBOOK OPTIONS(This:C1470.area; {allowInvalidFormula: $value})
231+
221232
// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
222233
Function get allowSheetReorder() : Boolean
223234

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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,15 @@
398398

399399
instancesArray.forEach(i => {
400400
const instance = i.sheet.getRange(i.row, i.column, i.rowCount, i.columnCount);
401-
402-
instance.formula(params.formula);
403-
404-
if (format != null) {
405-
instance.formatter(format);
401+
try {
402+
instance.formula(params.formula);
403+
}
404+
catch(e) {
405+
Utils.logEvent({ type: 'error-catched', data: e, formula: params.formula});
406+
if (Utils.spread.options.allowInvalidFormula == true) {
407+
instance.formula(null);
408+
instance.value("=" + params.formula);
409+
}
406410
}
407411
});
408412
});

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
@@ -756,6 +756,7 @@ document.addEventListener('DOMContentLoaded', function () {
756756
// Allow users to enter mathematical formula.
757757
Utils.spread.options.allowUserEditFormula = true;
758758
Utils.spread.options.enableFormulaTextbox = true;
759+
Utils.spread.options.allowInvalidFormula = true;
759760

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

Resources/scripts/utils.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,17 @@ Utils.diagnostics = {
9494
events: []
9595
};
9696

97-
Utils.logEvent = function ({ type, data }) {
97+
Utils.logEvent = function (eventData) {
9898
if (Utils.diagnostics.events.length >= 500) {
9999
Utils.diagnostics.events = [];
100100
}
101101
const event = {
102102
time: new Date(),
103-
type,
104-
data
103+
...eventData
105104
};
106105

107106
Utils.diagnostics.events.push(event);
108-
if (Utils.debug || type.includes("error")) console.log(event);
107+
if (Utils.debug || (eventData.type && eventData.type.includes("error"))) console.log(event);
109108
};
110109

111110
Utils.adjustFormat = function (format) {

0 commit comments

Comments
 (0)