@syncfusion/ej2-calculate 35.1.39 → 35.1.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11433,7 +11433,7 @@ class LogicalFormulas extends FormulaModuleBase {
11433
11433
  const condUpper = condition.toUpperCase();
11434
11434
  const parsedVal = this.parent.parseFloat(condition);
11435
11435
  if (condUpper === this.parent.trueValue || (parsedVal < 0 || parsedVal > 0)) {
11436
- if (nestedFormula && argArr[1].includes(':')) {
11436
+ if (nestedFormula && argArr[1].includes(':') && this.parent.isCellReference(argArr[1])) {
11437
11437
  cellValues = this.parent.getCellCollection(argArr[1]);
11438
11438
  for (let i = 0; i < cellValues.length; i++) {
11439
11439
  cellVal = this.parent.getValueFromArg(cellValues[i]);
@@ -11449,7 +11449,7 @@ class LogicalFormulas extends FormulaModuleBase {
11449
11449
  if (isNullOrUndefined(argArr[2])) {
11450
11450
  return this.parent.falseValue;
11451
11451
  }
11452
- if (nestedFormula && argArr[2].includes(':')) {
11452
+ if (nestedFormula && argArr[2].includes(':') && this.parent.isCellReference(argArr[2])) {
11453
11453
  cellValues = this.parent.getCellCollection(argArr[2]);
11454
11454
  for (let i = 0; i < cellValues.length; i++) {
11455
11455
  cellVal = this.parent.getValueFromArg(cellValues[i]);
@@ -14642,6 +14642,11 @@ class TextExtraFormulas extends FormulaModuleBase {
14642
14642
  return this.substringSide(args, false);
14643
14643
  }
14644
14644
  substringSide(args, fromLeft) {
14645
+ let nestedFormula;
14646
+ if (args && args.length > 0 && args[args.length - 1] === 'nestedFormulaTrue') {
14647
+ nestedFormula = true;
14648
+ args.pop();
14649
+ }
14645
14650
  const errCollection = this.parent.getErrorStrings();
14646
14651
  if (isNullOrUndefined(args) || (args.length === 1 && args[0] === '')) {
14647
14652
  return this.parent.formulaErrorStrings[FormulasErrorsStrings.InvalidArguments];
@@ -14664,10 +14669,8 @@ class TextExtraFormulas extends FormulaModuleBase {
14664
14669
  return errCollection[CommonErrors.Value];
14665
14670
  }
14666
14671
  }
14667
- if (fromLeft) {
14668
- return text.substring(0, count);
14669
- }
14670
- return count >= text.length ? text : text.substring(text.length - count);
14672
+ const result = fromLeft ? text.substring(0, count) : (count >= text.length ? text : text.substring(text.length - count));
14673
+ return nestedFormula ? this.parent.tic + result + this.parent.tic : result;
14671
14674
  }
14672
14675
  /**
14673
14676
  * Returns a specific number of characters from a text string starting at the position you specify.
@@ -14747,6 +14750,11 @@ class TextExtraFormulas extends FormulaModuleBase {
14747
14750
  * @returns {string | number} - Computed text result or an Excel error token such as `#VALUE!`.
14748
14751
  */
14749
14752
  ComputeTRIM(...args) {
14753
+ let nestedFormula;
14754
+ if (args && args.length > 0 && args[args.length - 1] === 'nestedFormulaTrue') {
14755
+ nestedFormula = true;
14756
+ args.pop();
14757
+ }
14750
14758
  const errCollection = this.parent.getErrorStrings();
14751
14759
  if (isNullOrUndefined(args) || args.length !== 1) {
14752
14760
  return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
@@ -14755,7 +14763,8 @@ class TextExtraFormulas extends FormulaModuleBase {
14755
14763
  if (errCollection.indexOf(text) > -1) {
14756
14764
  return text;
14757
14765
  }
14758
- return text.trim().replace(/\s+/g, ' ');
14766
+ const result = text.trim().replace(/\s+/g, ' ');
14767
+ return nestedFormula ? this.parent.tic + result + this.parent.tic : result;
14759
14768
  }
14760
14769
  /**
14761
14770
  * Replaces characters within text.
@@ -19701,12 +19710,23 @@ class Parser {
19701
19710
  const criteriaStr = this.parent.substring(substr, leftBraceIdx, substr.indexOf('}') - leftBraceIdx + 1);
19702
19711
  substr = substr.split(criteriaStr).join(criteriaStr.split(argsSep).join(this.parent.tic + this.parent.tic));
19703
19712
  }
19704
- else if ((libFormula === 'VLOOKUP' || libFormula === 'HLOOKUP') && substr.includes('{')) {
19705
- const leftBraceIdx = substr.indexOf('{');
19706
- const criteriaStr = this.parent.substring(substr, leftBraceIdx, substr.indexOf('}') - leftBraceIdx + 1);
19707
- const protectedStr = criteriaStr.split(';').join(this.parent.tic + 'RSEP' + this.parent.tic)
19708
- .split(argsSep).join(this.parent.tic + 'CSEP' + this.parent.tic);
19709
- substr = substr.split(criteriaStr).join(protectedStr);
19713
+ if ((libFormula === 'VLOOKUP' || libFormula === 'HLOOKUP') && substr.includes('{')) {
19714
+ let searchStartIdx = 0;
19715
+ let leftBraceIdx = substr.indexOf('{', searchStartIdx);
19716
+ while (leftBraceIdx > -1) {
19717
+ const rightBraceIdx = substr.indexOf('}', leftBraceIdx);
19718
+ if (rightBraceIdx > leftBraceIdx) {
19719
+ const criteriaStr = this.parent.substring(substr, leftBraceIdx, rightBraceIdx - leftBraceIdx + 1);
19720
+ const protectedStr = criteriaStr.split(';').join(this.parent.tic + 'RSEP' + this.parent.tic)
19721
+ .split(argsSep).join(this.parent.tic + 'CSEP' + this.parent.tic);
19722
+ substr = substr.split(criteriaStr).join(protectedStr);
19723
+ searchStartIdx = leftBraceIdx + protectedStr.length;
19724
+ leftBraceIdx = substr.indexOf('{', searchStartIdx);
19725
+ }
19726
+ else {
19727
+ break;
19728
+ }
19729
+ }
19710
19730
  }
19711
19731
  }
19712
19732
  try {
@@ -21251,7 +21271,7 @@ let Calculate = class Calculate extends Base {
21251
21271
  }
21252
21272
  if (nestedFormula && libFormula) {
21253
21273
  const formulas = ['IF', 'INDEX', 'SORT', 'T', 'EXACT',
21254
- 'PROPER', 'DOLLAR', 'DATE', 'TEXT', 'ISNUMBER'];
21274
+ 'PROPER', 'DOLLAR', 'DATE', 'TEXT', 'ISNUMBER', 'TRIM', 'LEFT'];
21255
21275
  if (formulas.some((formula) => formula === libFormula)) {
21256
21276
  args.push('nestedFormulaTrue');
21257
21277
  }
@@ -23297,8 +23317,8 @@ let Calculate = class Calculate extends Base {
23297
23317
  return { op, criteria };
23298
23318
  }
23299
23319
  processNestedFormula(pText, sFormula, fResult) {
23300
- if (!fResult.toString().includes('"')) {
23301
- const formulaEndIdx = pText.lastIndexOf(sFormula) + sFormula.length;
23320
+ if (fResult && !fResult.toString().includes('"')) {
23321
+ const formulaEndIdx = pText.indexOf(sFormula) + sFormula.length;
23302
23322
  if (pText[formulaEndIdx] === '"' && this.getErrorStrings().indexOf(fResult.toString()) < 0 &&
23303
23323
  !this.isNumber(fResult) && fResult !== this.trueValue && fResult !== this.falseValue) {
23304
23324
  return pText.split(sFormula).join('"' + fResult + '"');