@syncfusion/ej2-calculate 35.1.37 → 35.1.40

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.
@@ -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,6 +19710,24 @@ 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
  }
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
+ }
19730
+ }
19704
19731
  }
19705
19732
  try {
19706
19733
  let args;
@@ -21244,7 +21271,7 @@ let Calculate = class Calculate extends Base {
21244
21271
  }
21245
21272
  if (nestedFormula && libFormula) {
21246
21273
  const formulas = ['IF', 'INDEX', 'SORT', 'T', 'EXACT',
21247
- 'PROPER', 'DOLLAR', 'DATE', 'TEXT', 'ISNUMBER'];
21274
+ 'PROPER', 'DOLLAR', 'DATE', 'TEXT', 'ISNUMBER', 'TRIM', 'LEFT'];
21248
21275
  if (formulas.some((formula) => formula === libFormula)) {
21249
21276
  args.push('nestedFormulaTrue');
21250
21277
  }
@@ -21633,7 +21660,52 @@ let Calculate = class Calculate extends Base {
21633
21660
  return errorStrings[CommonErrors.Value];
21634
21661
  }
21635
21662
  }
21636
- const rangeArr = argArr[1].split(':');
21663
+ const rangeArg = argArr[1];
21664
+ const rowSepMarker = this.tic + 'RSEP' + this.tic;
21665
+ const isInlineArray = rangeArg.includes(rowSepMarker) ||
21666
+ (rangeArg.startsWith('(') && rangeArg.endsWith(')') && rangeArg.includes(rowSepMarker));
21667
+ if (isInlineArray) {
21668
+ const innerStr = rangeArg.startsWith('(') && rangeArg.endsWith(')')
21669
+ ? rangeArg.substring(1, rangeArg.length - 1) : rangeArg;
21670
+ const rowBoundary = this.tic + 'RSEP' + this.tic;
21671
+ const colBoundary = this.tic + 'CSEP' + this.tic;
21672
+ const rows = innerStr.split(rowBoundary).map((rowStr) => {
21673
+ return rowStr.split(colBoundary).map((cell) => {
21674
+ if (cell.startsWith(this.tic) && cell.endsWith(this.tic)) {
21675
+ return cell.substring(1, cell.length - 1);
21676
+ }
21677
+ if (this.isCellReference(cell.trim())) {
21678
+ return this.getValueFromArg(cell.trim());
21679
+ }
21680
+ return cell.trim();
21681
+ });
21682
+ });
21683
+ const numRows = rows.length;
21684
+ const numCols = rows[0] ? rows[0].length : 0;
21685
+ const matchColIdx = colNumIdx - 1;
21686
+ if (isVlookup && numCols <= matchColIdx) {
21687
+ return errorStrings[CommonErrors.Ref];
21688
+ }
21689
+ if (!isVlookup && numRows <= matchColIdx) {
21690
+ return errorStrings[CommonErrors.Ref];
21691
+ }
21692
+ const lookupValUpper = lookupValue.toUpperCase();
21693
+ const iterCount = isVlookup ? numRows : numCols;
21694
+ for (let r = 0; r < iterCount; r++) {
21695
+ const cellVal = (isVlookup ? rows[r][0] : rows[0][r]) || '';
21696
+ const isMatch = this.isNumber(lookupValue) && this.isNumber(cellVal)
21697
+ ? this.parseFloat(lookupValue) === this.parseFloat(cellVal) : cellVal.toUpperCase() === lookupValUpper;
21698
+ if (isMatch) {
21699
+ const matchVal = isVlookup
21700
+ ? (rows[r][matchColIdx] !== undefined ? rows[r][matchColIdx] : '')
21701
+ : (rows[matchColIdx] !== undefined && rows[matchColIdx][r] !== undefined
21702
+ ? rows[matchColIdx][r] : '');
21703
+ return matchVal !== '' ? matchVal : '';
21704
+ }
21705
+ }
21706
+ return errorStrings[CommonErrors.NA];
21707
+ }
21708
+ const rangeArr = rangeArg.split(':');
21637
21709
  let startIdx;
21638
21710
  let endIdx;
21639
21711
  let idx;