all files / workbook/common/ util.js

92.48% Statements 504/545
89.26% Branches 432/484
100% Functions 36/36
92.46% Lines 503/544
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813   480606×   9524× 9524× 9524× 62× 62× 33×     9462× 9462× 3822×     5669×   31147× 16391×   14756×   17×   16×   5987×   26× 26× 26× 26× 64× 64× 64×     26×   6068× 6068× 414×   5654× 5647× 2409×     3238× 56× 56×   3238× 35× 35×     3238× 3195×     43×   43×       50×                           3612× 897×   3612× 12×   3600× 555×   3045× 479×   2566× 2566×       9573× 9573× 9573× 9573× 9573× 9573× 27012× 12382×     9573× 9573× 9573× 8355× 7890× 4232× 4232×     4232× 4232× 3904×         5669×   4232× 4232× 4232× 4232× 30× 30×     30×   4232× 4009× 4009× 4009×   4232× 335×   3897×   147479× 147479× 147479× 145218× 146320× 146320× 1102×     145218×         145218×           2261× 439× 439× 22×     417×       147479×   31064× 31064×       32× 32× 32× 32× 32×   32× 32×   32× 32×   32× 32× 32× 32× 32× 384× 384×   32× 32× 32× 32× 32× 32× 32× 32× 102× 102×     100×   102× 45× 45× 45× 45×   45×     43×   43× 43× 12×   43×   45× 45×   45× 45× 14×     31×       32× 32× 32× 32× 32× 45× 45× 45× 45× 45× 45× 172×   45× 45×   32×           45× 45× 48×     45×     45×   45× 45× 49×     45×     45×   31901× 31901× 26171×   31901× 12442× 8308× 8308× 8308× 8308× 8308× 8308× 1191× 1191×   8308× 399×   8308×             8308× 8308× 8308× 1404×   8308× 1481× 1481× 1481×   8308× 7739×   8308× 6465× 6465× 1993× 1993× 1993×   1993× 937×   1993×         4134×     31901×   116× 116× 116× 116× 116× 116× 116× 91× 96× 89×       116× 28× 70× 22×       116× 22430×     22429×     116× 191×     190×     116× 753×     751×     116× 270×     266×     116×   124× 124× 124× 124× 74× 20×   74× 26×   18× 12×       48× 11× 11×   37× 14×     74×     50× 16×   50× 22×   17× 11×       28× 10× 10×   18× 12×     50×     80× 80× 80× 80× 53× 53× 23×   30× 14×   16×   14×   12×       53×     27× 27× 15×   12×             27×     36× 36× 36× 58× 58× 58×   58× 11× 11× 11×         446× 446× 446× 446× 446× 446× 446× 446× 446× 446× 370×     76× 76× 76× 76× 76× 27× 23×   15× 10×           49×               40× 22×         16×             18×         28×   446× 446× 418×     28×   133× 133× 86×   133× 177× 110×           67×   67× 67× 26×       133×   344× 344×   344×                                 344×   15×             15×               3597885×   777× 777×   777× 777× 777× 26791× 21125× 21125× 21125× 21125× 21003× 21003×   20998×                       103× 103× 100×   103× 103×                       103×   291786×      
define(["require", "exports", "./../index", "./index", "./index", "./../index", "@syncfusion/ej2-base", "./internalization", "./../index", "@syncfusion/ej2-data"], function (require, exports, index_1, index_2, index_3, index_4, ej2_base_1, internalization_1, index_5, ej2_data_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function checkIsFormula(text, isEditing) {
        return text && text[0] === '=' && (text.length > 1 || isEditing);
    }
    exports.checkIsFormula = checkIsFormula;
    function isCellReference(value) {
        var range = value;
        range = range.split('$').join('');
        if (range.indexOf(':') > -1) {
            var rangeSplit = range.split(':');
            if (isValidCellReference(rangeSplit[0]) && isValidCellReference(rangeSplit[1])) {
                return true;
            }
        }
        else Eif (range.indexOf(':') < 0) {
            if (isValidCellReference(range)) {
                return true;
            }
        }
        return false;
    }
    exports.isCellReference = isCellReference;
    function isChar(value) {
        if ((value.charCodeAt(0) >= 65 && value.charCodeAt(0) <= 90) || (value.charCodeAt(0) >= 97 && value.charCodeAt(0) <= 122)) {
            return true;
        }
        return false;
    }
    exports.isChar = isChar;
    function isRowSelected(sheet, range) {
        return range[1] === 0 && range[3] === sheet.colCount - 1;
    }
    exports.isRowSelected = isRowSelected;
    function isColumnSelected(sheet, range) {
        return range[0] === 0 && range[2] === sheet.rowCount - 1;
    }
    exports.isColumnSelected = isColumnSelected;
    function inRange(range, rowIdx, colIdx) {
        return range && (rowIdx >= range[0] && rowIdx <= range[2] && colIdx >= range[1] && colIdx <= range[3]);
    }
    exports.inRange = inRange;
    function isInMultipleRange(address, rowIdx, colIdx) {
        var range;
        var isInRange;
        var splitedAddress = address.split(' ');
        for (var i = 0, len = splitedAddress.length; i < len; i++) {
            range = index_2.getRangeIndexes(splitedAddress[i]);
            isInRange = inRange(range, rowIdx, colIdx);
            if (isInRange) {
                break;
            }
        }
        return isInRange;
    }
    exports.isInMultipleRange = isInMultipleRange;
    function isInRange(range, testRange, isModify) {
        var inRange = range[0] <= testRange[0] && range[2] >= testRange[2] && range[1] <= testRange[1] && range[3] >= testRange[3];
        if (inRange) {
            return true;
        }
        if (isModify) {
            if (testRange[0] < range[0] && testRange[2] < range[0] || testRange[0] > range[2] && testRange[2] > range[2]) {
                return false;
            }
            else {
                if (testRange[0] < range[0] && testRange[2] > range[0]) {
                    testRange[0] = range[0];
                    inRange = true;
                }
                if (testRange[2] > range[2]) {
                    testRange[2] = range[2];
                    inRange = true;
                }
            }
            if (testRange[1] < range[1] && testRange[3] < range[1] || testRange[1] > range[3] && testRange[3] > range[3]) {
                return false;
            }
            else {
                if (testRange[1] < range[1] && testRange[3] > range[1]) {
                    testRange[1] = range[1];
                    inRange = true;
                }
                if (testRange[3] > range[3]) {
                    testRange[3] = range[3];
                    inRange = true;
                }
            }
        }
        return inRange;
    }
    exports.isInRange = isInRange;
    function getSplittedAddressForColumn(address, testRange, colIdx) {
        var colName = index_3.getColumnHeaderText(colIdx + 1);
        if (address) {
            address.split(' ').forEach(function (addrs) {
                var range = index_2.getRangeIndexes(addrs);
                if (isInRange(range, testRange)) {
                    address = address.split(addrs).join(colName + (range[0] + 1) +
                        ':' + colName + testRange[0] + ' ' + colName + (testRange[2] + 2) +
                        ':' + colName + (range[2] + 1));
                }
                else if (isInRange(range, testRange, true)) {
                    var modifiedAddress = void 0;
                    if (testRange[0] > range[0]) {
                        modifiedAddress = colName + (range[0] + 1) + ':' + colName + testRange[0];
                    }
                    else {
                        modifiedAddress = colName + (testRange[2] + 2) + ':' + colName + (range[2] + 1);
                    }
                    address = address.split(addrs).join(modifiedAddress);
                }
            });
        }
        else {
            address = colName + '1:' + colName + testRange[0] + ' ' + colName + (testRange[2] + 2) + ':' + colName + '1048576';
        }
        return address;
    }
    exports.getSplittedAddressForColumn = getSplittedAddressForColumn;
    function isLocked(cell, column) {
        if (!cell) {
            cell = {};
        }
        if (cell.isLocked) {
            return true;
        }
        else if (cell.isLocked === false) {
            return false;
        }
        else if (column && column.isLocked) {
            return true;
        }
        else Eif (!cell.isLocked && (column && column.isLocked !== false)) {
            return true;
        }
        return false;
    }
    exports.isLocked = isLocked;
    function isValidCellReference(value) {
        var text = value;
        var startNum = 0;
        var endNum = 0;
        var cellText = '';
        var textLength = text.length;
        for (var i = 0; i < textLength; i++) {
            if (isChar(text[i])) {
                endNum++;
            }
        }
        cellText = text.substring(startNum, endNum);
        var cellTextLength = cellText.length;
        if (cellTextLength !== textLength) {
            if (cellTextLength < 4) {
                if (textLength !== 1 && (isNaN(parseInt(text, 10)))) {
                    var cellColIndex = columnIndex(cellText);
                    Iif (cellColIndex > 16384) {
                        return false;
                    }
                    var cellNumber = parseFloat(text.substring(endNum, textLength));
                    if (cellNumber > 0 && cellNumber < 1048577) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    exports.isValidCellReference = isValidCellReference;
    function columnIndex(cell) {
        var j = 0;
        var k = 0;
        cell = cell.toUpperCase();
        if (j < cell.length && cell[j] === '!') {
            j++;
            while (j < cell.length && cell[j] !== '!') {
                j++;
            }
            j++;
        }
        while (j < cell.length && isChar(cell[j])) {
            var charCode = cell[j].charCodeAt(0);
            k = k * 26 + charCode - 64;
            j++;
        }
        if (k === 0) {
            return -1;
        }
        return k;
    }
    exports.columnIndex = columnIndex;
    function skipHiddenIdx(sheet, index, increase, layout, count) {
        if (layout === void 0) { layout = 'rows'; }
        var rowColObj;
        if (increase) {
            for (var i = index; i < Infinity; i++) {
                rowColObj = sheet["" + layout];
                if (rowColObj[index] && rowColObj[index].hidden) {
                    index++;
                }
                else {
                    Iif (count) {
                        count--;
                        index++;
                    }
                    else {
                        break;
                    }
                }
            }
        }
        else {
            for (var i = index; i > -1; i--) {
                rowColObj = sheet["" + layout];
                if (rowColObj[index] && rowColObj[index].hidden) {
                    index--;
                }
                else {
                    break;
                }
            }
        }
        return index;
    }
    exports.skipHiddenIdx = skipHiddenIdx;
    function isHeightCheckNeeded(style, onActionUpdate) {
        var keys = Object.keys(style);
        return (onActionUpdate ? keys.indexOf('fontSize') > -1 : keys.indexOf('fontSize') > -1
            && Number(style.fontSize.split('pt')[0]) > 12) || keys.indexOf('fontFamily') > -1 || keys.indexOf('borderTop') > -1
            || keys.indexOf('borderBottom') > -1;
    }
    exports.isHeightCheckNeeded = isHeightCheckNeeded;
    function getUpdatedFormula(currIndexes, prevIndexes, sheet, context, prevCell, isSort) {
        var cIdxValue;
        var cell;
        Eif (prevIndexes) {
            cell = prevCell || index_1.getCell(prevIndexes[0], prevIndexes[1], sheet, false, true);
            cIdxValue = cell.formula || '';
        }
        Eif (cIdxValue) {
            if (isSort) {
                context.notify(index_3.clearFormulaDependentCells, { cellRef: index_2.getCellAddress(prevIndexes[0], prevIndexes[1]) });
            }
            Eif (cIdxValue.indexOf('=') === 0) {
                cIdxValue = cIdxValue.slice(1);
            }
            cIdxValue = cIdxValue.split('(').join(context.listSeparator).split(')').join(context.listSeparator);
            var formulaOperators = ['+', '-', '*', '/', '>=', '<=', '<>', '>', '<', '=', '%', '&'];
            var splitArray = void 0;
            var value = cIdxValue;
            for (var i = 0; i < formulaOperators.length; i++) {
                splitArray = value.split(formulaOperators[i]);
                value = splitArray.join(context.listSeparator);
            }
            splitArray = value.split(context.listSeparator);
            var newAddress = [];
            var newRef = void 0;
            var refObj = void 0;
            var isSheetRef = void 0;
            var cellRefSheet = void 0;
            var cellRef = void 0;
            for (var j = 0; j < splitArray.length; j++) {
                isSheetRef = splitArray[j].includes('!');
                if (isSheetRef) {
                    var lastIndex = splitArray[j].lastIndexOf('!');
                    cellRefSheet = splitArray[j].substring(0, lastIndex);
                    cellRef = splitArray[j].substring(lastIndex + 1).toUpperCase();
                }
                else {
                    cellRef = splitArray[j].toUpperCase();
                }
                if (isCellReference(cellRef.trim()) && !cellRef.includes('$')) {
                    var leadingSpaces = getLeadingSpaces(cellRef);
                    var trailingSpaces = getTrailingSpaces(cellRef);
                    var range = index_2.getRangeIndexes(cellRef);
                    var newRange = [currIndexes[0] - (prevIndexes[0] - range[0]), currIndexes[1] - (prevIndexes[1] - range[1]),
                        currIndexes[0] - (prevIndexes[0] - range[2]), currIndexes[1] - (prevIndexes[1] - range[3])];
                    if (newRange[1] < 0 || newRange[2] < 0 || newRange[3] < 0 || (!isSort && newRange[0] < 0)) {
                        newRef = '#REF!';
                    }
                    else {
                        if (isSort && newRange[0] < 0) {
                            newRange[0] = newRange[2];
                        }
                        newRef = index_2.getCellAddress(newRange[0], newRange[1]);
                        if (cellRef.includes(':')) {
                            newRef += (':' + index_2.getCellAddress(newRange[2], newRange[3]));
                        }
                        newRef = isCellReference(newRef) ? newRef : '#REF!';
                    }
                    refObj = {};
                    if (isSheetRef) {
                        newRef = cellRefSheet + "!" + newRef;
                    }
                    refObj[splitArray[j]] = "" + leadingSpaces + newRef + trailingSpaces;
                    if (splitArray[j].includes(':')) {
                        newAddress.splice(0, 0, refObj);
                    }
                    else {
                        newAddress.push(refObj);
                    }
                }
            }
            var objKey = void 0;
            var objValue = void 0;
            cIdxValue = cell.formula;
            var newCIdxValue = cIdxValue;
            for (var j = 0; j < newAddress.length; j++) {
                objKey = Object.keys(newAddress[j])[0];
                objValue = newAddress[j]["" + objKey];
                var objKeyLen = objKey.length;
                var positionIdx = newCIdxValue.indexOf(objKey);
                var emptyString = '';
                for (var idx = 0; idx < objValue.length; idx++) {
                    emptyString += ' ';
                }
                cIdxValue = cIdxValue.slice(0, positionIdx) + objValue + cIdxValue.slice(positionIdx + objKeyLen);
                newCIdxValue = newCIdxValue.slice(0, positionIdx) + emptyString + newCIdxValue.slice(positionIdx + objKeyLen);
            }
            return cIdxValue;
        }
        else {
            return null;
        }
    }
    exports.getUpdatedFormula = getUpdatedFormula;
    function getLeadingSpaces(string) {
        var leadingSpaces = '';
        for (var i = 0; i < string.length; i++) {
            if (string[i] === ' ') {
                leadingSpaces += ' ';
            }
            else {
                break;
            }
        }
        return leadingSpaces;
    }
    exports.getLeadingSpaces = getLeadingSpaces;
    function getTrailingSpaces(string) {
        var trailingSpaces = '';
        for (var i = string.length - 1; i >= 0; i--) {
            if (string[i] === ' ') {
                trailingSpaces = ' ' + trailingSpaces;
            }
            else {
                break;
            }
        }
        return trailingSpaces;
    }
    exports.getTrailingSpaces = getTrailingSpaces;
    function updateCell(context, sheet, prop) {
        var args = { cell: prop.cell, rowIndex: prop.rowIdx, colIndex: prop.colIdx, cancel: false, sheet: sheet.name };
        if (!prop.preventEvt) {
            context.trigger(index_2.beforeCellUpdate, args);
        }
        if (!prop.eventOnly && !args.cancel) {
            if (prop.valChange) {
                var prevCell = index_1.getCell(args.rowIndex, args.colIndex, sheet);
                var prevCellVal = !prop.preventEvt && context.getDisplayText(prevCell);
                var isFormulaCell = !!(prevCell && prevCell.formula);
                index_1.setCell(args.rowIndex, args.colIndex, sheet, args.cell, !prop.pvtExtend);
                var cell = index_1.getCell(args.rowIndex, args.colIndex, sheet, false, true);
                if (prop.mergedCells) {
                    delete cell.value;
                    delete cell.formula;
                }
                if (cell.formattedText) {
                    delete cell.formattedText;
                }
                var evtArgs = {
                    action: 'updateCellValue',
                    address: [args.rowIndex, args.colIndex], sheetIndex: index_1.getSheetIndex(context, sheet.name), value: isFormulaCell && !cell.formula ? (cell.value || (cell.value === 0 ? '0' : '')) :
                        (cell.formula || cell.value || (cell.value === 0 ? '0' : '')),
                    skipFormatCheck: prop.skipFormatCheck, isRandomFormula: prop.isRandomFormula,
                    isDelete: prop.isDelete, deletedRange: prop.deletedRange
                };
                context.notify(index_2.workbookEditOperation, evtArgs);
                prop.isFormulaDependent = evtArgs.isFormulaDependent;
                if (prop.requestType && args.cell === null) {
                    index_1.setCell(args.rowIndex, args.colIndex, sheet, args.cell, !prop.pvtExtend);
                }
                if (prop.cellDelete) {
                    delete cell.value;
                    delete cell.formula;
                    delete cell.hyperlink;
                }
                if (prop.uiRefresh) {
                    context.serviceLocator.getService('cell').refresh(args.rowIndex, args.colIndex, prop.lastCell, prop.td, prop.checkCF, prop.checkWrap, prop.skipFormatCheck, prop.isRandomFormula);
                }
                if (!prop.preventEvt) {
                    var cellDisplayText = context.getDisplayText(cell);
                    if (cellDisplayText !== prevCellVal) {
                        var cellValue = index_1.getCell(args.rowIndex, args.colIndex, sheet, false, true).value;
                        cellValue = cellValue || (cellValue === 0 ? '0' : '');
                        var evtArgs_1 = { value: cellValue, oldValue: prevCellVal, formula: cell.formula || '',
                            address: sheet.name + "!" + index_2.getCellAddress(args.rowIndex, args.colIndex), displayText: cellDisplayText };
                        if (prop.requestType) {
                            evtArgs_1.requestType = prop.requestType;
                        }
                        context.trigger('cellSave', evtArgs_1);
                    }
                }
            }
            else {
                index_1.setCell(args.rowIndex, args.colIndex, sheet, args.cell, !prop.pvtExtend);
            }
        }
        return args.cancel;
    }
    exports.updateCell = updateCell;
    function getDataRange(rowIdx, colIdx, sheet) {
        var sRowIdx = rowIdx;
        var eRowIdx = rowIdx;
        var sColIdx = colIdx;
        var eColIdx = colIdx;
        var usedRowIdx = sheet.usedRange.rowIndex;
        var usedColIdx = sheet.usedRange.colIndex;
        var isEmptyRow = function (idx) {
            for (var i = 0; i <= usedColIdx; i++) {
                if (!ej2_base_1.isUndefined(index_1.getCell(idx, i, sheet, null, true).value)) {
                    return false;
                }
            }
            return true;
        };
        var isEmptyColumn = function (idx) {
            for (var i = sRowIdx; i <= eRowIdx; i++) {
                if (!ej2_base_1.isUndefined(index_1.getCell(i, idx, sheet, null, true).value)) {
                    return false;
                }
            }
            return true;
        };
        for (var i = sRowIdx; i <= usedRowIdx; i++) {
            if (ej2_base_1.isUndefined(index_1.getCell(i, colIdx, sheet, null, true).value) && isEmptyRow(i)) {
                break;
            }
            else {
                eRowIdx = i;
            }
        }
        for (var i = sRowIdx; i >= 0; i--) {
            if (ej2_base_1.isUndefined(index_1.getCell(i, colIdx, sheet, null, true).value) && isEmptyRow(i)) {
                break;
            }
            else {
                sRowIdx = i;
            }
        }
        for (var i = sColIdx; i <= usedColIdx; i++) {
            if (ej2_base_1.isUndefined(index_1.getCell(rowIdx, i, sheet, null, true).value) && isEmptyColumn(i)) {
                break;
            }
            else {
                eColIdx = i;
            }
        }
        for (var i = sColIdx; i >= 0; i--) {
            if (ej2_base_1.isUndefined(index_1.getCell(rowIdx, i, sheet, null, true).value) && isEmptyColumn(i)) {
                break;
            }
            else {
                sColIdx = i;
            }
        }
        return [sRowIdx, sColIdx, eRowIdx, eColIdx];
    }
    exports.getDataRange = getDataRange;
    function insertFormatRange(args, formatRange, isAction) {
        var sltRangeIndex = index_2.getRangeIndexes(args.model.selectedRange);
        var insertStartIndex = 0;
        var insertEndIndex = 0;
        if (args.modelType === 'Column') {
            if (isAction) {
                sltRangeIndex = [0, args.start, 0, args.end];
            }
            if (args.insertType === 'before') {
                if ((formatRange[1] <= sltRangeIndex[1] && formatRange[3] >= sltRangeIndex[1])) {
                    insertStartIndex = 0;
                    insertEndIndex = (sltRangeIndex[3] - sltRangeIndex[1]) + 1;
                }
                else if (sltRangeIndex[1] < formatRange[1]) {
                    insertStartIndex = insertEndIndex = (sltRangeIndex[3] - sltRangeIndex[1]) + 1;
                }
            }
            else {
                if ((formatRange[1] <= sltRangeIndex[3] && formatRange[3] >= sltRangeIndex[3])) {
                    insertStartIndex = 0;
                    insertEndIndex = (sltRangeIndex[3] - sltRangeIndex[1]) + 1;
                }
                else if (sltRangeIndex[3] < formatRange[3]) {
                    insertStartIndex = insertEndIndex = (sltRangeIndex[3] - sltRangeIndex[1]) + 1;
                }
            }
            return [formatRange[0], formatRange[1] + insertStartIndex, formatRange[2], formatRange[3] + insertEndIndex];
        }
        else {
            if (isAction) {
                sltRangeIndex = [args.start, 0, args.end, 0];
            }
            if (args.insertType === 'above') {
                if ((formatRange[0] <= sltRangeIndex[0] && formatRange[2] >= sltRangeIndex[0])) {
                    insertStartIndex = 0;
                    insertEndIndex = (sltRangeIndex[2] - sltRangeIndex[0]) + 1;
                }
                else if (sltRangeIndex[0] < formatRange[0]) {
                    insertStartIndex = insertEndIndex = (sltRangeIndex[2] - sltRangeIndex[0]) + 1;
                }
            }
            else {
                if ((formatRange[0] <= sltRangeIndex[2] && formatRange[2] >= sltRangeIndex[2])) {
                    insertStartIndex = 0;
                    insertEndIndex = (sltRangeIndex[2] - sltRangeIndex[0]) + 1;
                }
                else if (sltRangeIndex[2] < formatRange[2]) {
                    insertStartIndex = insertEndIndex = (sltRangeIndex[2] - sltRangeIndex[0]) + 1;
                }
            }
            return [formatRange[0] + insertStartIndex, formatRange[1], formatRange[2] + insertEndIndex, formatRange[3]];
        }
    }
    exports.insertFormatRange = insertFormatRange;
    function deleteFormatRange(args, formatRange) {
        var cellRange;
        var deleteStartIndex = 0;
        var deleteEndIndex = 0;
        if (args.modelType === 'Column') {
            cellRange = [0, args.start, args.model.usedRange.rowIndex, args.end];
            if (cellRange[3] < formatRange[1]) {
                deleteStartIndex = deleteEndIndex = cellRange[3] - cellRange[1] + 1;
            }
            else if (cellRange[1] >= formatRange[1] && cellRange[3] <= formatRange[3]) {
                deleteEndIndex = cellRange[3] - cellRange[1] + 1;
            }
            else if (cellRange[1] >= formatRange[1] && cellRange[1] <= formatRange[3]) {
                deleteEndIndex = formatRange[3] - cellRange[1] + 1;
            }
            else if (cellRange[1] < formatRange[1] && cellRange[3] >= formatRange[1]) {
                deleteStartIndex = formatRange[1] - cellRange[1];
                deleteEndIndex = cellRange[3] - cellRange[1] + 1;
            }
            else Iif (cellRange[1] < formatRange[1] && cellRange[3] < formatRange[3]) {
                deleteStartIndex = (cellRange[3] - formatRange[1]) + (cellRange[3] - cellRange[1]) + 1;
                deleteEndIndex = cellRange[3] - cellRange[1] + 1;
            }
            return [formatRange[0], formatRange[1] - deleteStartIndex, formatRange[2], formatRange[3] - deleteEndIndex];
        }
        else {
            cellRange = [args.start, 0, args.end, args.model.usedRange.colIndex];
            if (cellRange[2] < formatRange[0]) {
                deleteStartIndex = deleteEndIndex = cellRange[2] - cellRange[0] + 1;
            }
            else if (cellRange[0] >= formatRange[0] && cellRange[2] <= formatRange[2]) {
                deleteEndIndex = cellRange[2] - cellRange[0] + 1;
            }
            else if (cellRange[0] >= formatRange[0] && cellRange[0] <= formatRange[2]) {
                deleteEndIndex = formatRange[2] - cellRange[0] + 1;
            }
            else if (cellRange[0] < formatRange[0] && cellRange[2] >= formatRange[0]) {
                deleteStartIndex = formatRange[0] - cellRange[0];
                deleteEndIndex = cellRange[2] - cellRange[0] + 1;
            }
            else Iif (cellRange[0] < formatRange[0] && cellRange[2] < formatRange[2]) {
                deleteStartIndex = (cellRange[2] - formatRange[0]) + (cellRange[2] - cellRange[0]) + 1;
                deleteEndIndex = cellRange[2] - cellRange[0] + 1;
            }
            return [formatRange[0] - deleteStartIndex, formatRange[1], formatRange[2] - deleteEndIndex, formatRange[3]];
        }
    }
    exports.deleteFormatRange = deleteFormatRange;
    function updateCFModel(curCF, cfRule, rowIdx, colIdx) {
        var cfRange;
        var indexes;
        for (var i = curCF.length - 1; i >= 0; i--) {
            cfRange = curCF[i].range.trim().split(',');
            for (var j = 0; j < cfRange.length; j++) {
                indexes = index_2.getRangeIndexes(cfRange[j].includes(':') ? cfRange[j] :
                    cfRange[j] + ":" + cfRange[j]);
                if (rowIdx >= indexes[0] && colIdx >= indexes[1] && rowIdx <= indexes[2] && colIdx <= indexes[3]) {
                    cfRule.push(curCF[i]);
                    curCF.splice(i, 1);
                    break;
                }
            }
        }
    }
    exports.updateCFModel = updateCFModel;
    function checkRange(indexes, range) {
        var ranges = range.trim().split(',');
        var left;
        var right;
        var top;
        var bottom;
        var cfIdx;
        var checkRange = function (idx) {
            for (var i = 0; i < ranges.length; i++) {
                cfIdx = index_2.getRangeIndexes(ranges[i].includes(':') ? ranges[i] : ranges[i] + ":" + ranges[i]);
                if (idx[0] <= cfIdx[0] && idx[1] <= cfIdx[1] && idx[2] >= cfIdx[2] && idx[3] >= cfIdx[3]) {
                    return true;
                }
                else {
                    top = idx[0] >= cfIdx[0] && idx[0] <= cfIdx[2];
                    bottom = idx[2] >= cfIdx[0] && idx[2] <= cfIdx[2];
                    left = idx[1] >= cfIdx[1] && idx[1] <= cfIdx[3];
                    right = idx[3] >= cfIdx[1] && idx[3] <= cfIdx[3];
                    if (top && bottom) {
                        if (left || right || (idx[1] < cfIdx[1] && idx[3] > cfIdx[3])) {
                            if (idx[0] - cfIdx[0] > 0) {
                                return true;
                            }
                            if (cfIdx[2] - idx[2] > 0) {
                                return true;
                            }
                        }
                        if (left && idx[1] !== cfIdx[1]) {
                            return true;
                        }
                        if (right && idx[3] !== cfIdx[3]) {
                            return true;
                        }
                    }
                    else if (left && right) {
                        Eif (top || bottom || (idx[0] < cfIdx[0] && idx[2] > cfIdx[2])) {
                            if (idx[1] - cfIdx[1] > 0) {
                                return true;
                            }
                            if (cfIdx[3] - idx[3] > 0) {
                                return true;
                            }
                        }
                        if (top) {
                            Eif (idx[0] !== cfIdx[0]) {
                                return true;
                            }
                        }
                        else Eif (bottom && idx[2] !== cfIdx[2]) {
                            return true;
                        }
                    }
                    else if (top || bottom) {
                        if (left) {
                            if (idx[1] !== cfIdx[1]) {
                                return true;
                            }
                            if (idx[0] - cfIdx[0] > 0) {
                                return true;
                            }
                            else Eif (cfIdx[2] - idx[2] > 0) {
                                return true;
                            }
                        }
                        else if (right) {
                            if (idx[3] !== cfIdx[3]) {
                                return true;
                            }
                            if (idx[0] - cfIdx[0] > 0) {
                                return true;
                            }
                            else Eif (cfIdx[2] - idx[2] > 0) {
                                return true;
                            }
                        }
                        else if (idx[1] < cfIdx[1] && idx[3] > cfIdx[3]) {
                            return true;
                        }
                    }
                    else Iif ((left || right) && idx[0] < cfIdx[0] && idx[2] > cfIdx[2]) {
                        return true;
                    }
                }
            }
            return false;
        };
        for (var j = 0; j < indexes.length; j++) {
            if (checkRange(indexes[j])) {
                return true;
            }
        }
        return false;
    }
    exports.checkRange = checkRange;
    function parseLocaleNumber(valArr, context, numObj) {
        var formatArgs;
        if (!numObj) {
            numObj = ej2_base_1.getNumericObject(context.locale);
        }
        for (var idx = 0; idx < valArr.length; idx++) {
            if (index_5.isNumber(valArr[idx])) {
                if (numObj.group === '.') {
                    valArr[idx] = valArr[idx].toString();
                    if (valArr[idx].indexOf('.') &&
                        internalization_1.parseThousandSeparator(valArr[idx], context.locale, numObj.group, numObj.decimal)) {
                        valArr[idx] = valArr[idx].split(numObj.group).join('');
                    }
                }
            }
            else {
                formatArgs = { formattedText: valArr[idx], value: valArr[idx], format: 'General',
                    cell: { value: valArr[idx], format: 'General' }, isEdit: true };
                context.notify(index_5.getFormattedCellObject, formatArgs);
                if (index_5.isNumber(formatArgs.value)) {
                    valArr[idx] = formatArgs.value.toString();
                }
            }
        }
        return valArr;
    }
    exports.parseLocaleNumber = parseLocaleNumber;
    function getViewportIndexes(parent, viewport) {
        var sheet = parent.getActiveSheet();
        var indexes = [[viewport.topIndex + parent.frozenRowCount(sheet), viewport.leftIndex + parent.frozenColCount(sheet),
                viewport.bottomIndex, viewport.rightIndex]];
        Iif (sheet.frozenRows || sheet.frozenColumns) {
            var froezenRow = parent.frozenRowCount(sheet);
            var froezenCol = parent.frozenColCount(sheet);
            var topLeftCell = index_1.getCellIndexes(sheet.topLeftCell);
            if (froezenRow && froezenCol) {
                indexes.push([topLeftCell[0], topLeftCell[1], froezenRow - 1, froezenCol - 1]);
                var paneTopLeftCell = index_1.getCellIndexes(sheet.paneTopLeftCell);
                indexes.push([paneTopLeftCell[0], topLeftCell[1], viewport.bottomIndex, froezenCol - 1]);
            }
            if (froezenRow) {
                indexes.push([topLeftCell[0], viewport.leftIndex + froezenCol, froezenRow - 1, viewport.rightIndex]);
            }
            if (froezenCol) {
                indexes.push([viewport.topIndex + froezenRow, topLeftCell[1], viewport.bottomIndex,
                    froezenCol - 1]);
            }
        }
        return indexes;
    }
    exports.getViewportIndexes = getViewportIndexes;
    function setVisibleMergeIndex(args) {
        Iif (index_4.isHiddenRow(args.sheet, args.rowIdx)) {
            var idx = skipHiddenIdx(args.sheet, args.rowIdx, true);
            if (idx < args.rowIdx + args.cell.rowSpan) {
                args.rowIdx = idx;
                args.isMergedHiddenCell = true;
            }
        }
        Iif (index_4.isHiddenCol(args.sheet, args.colIdx)) {
            var idx = skipHiddenIdx(args.sheet, args.colIdx, true, 'columns');
            if (idx < args.colIdx + args.cell.colSpan) {
                args.colIdx = idx;
                args.isMergedHiddenCell = true;
            }
        }
    }
    exports.setVisibleMergeIndex = setVisibleMergeIndex;
    function isImported(context) {
        return context.workbookOpenModule && context.workbookOpenModule.preventFormatCheck;
    }
    exports.isImported = isImported;
    function getAutoDetectFormatParser(context) {
        var intl = new ej2_base_1.Internationalization();
        var eventArgs = { intl: intl, updateValue: true, value: '',
            curSymbol: ej2_base_1.getNumberDependable(context.locale, ej2_base_1.defaultCurrencyCode) };
        var options = { args: eventArgs, intl: intl };
        var localeNumObj = ej2_base_1.getNumericObject(context.locale);
        return function (cell) {
            if (!cell.format && cell.value && !index_5.isNumber(cell.value)) {
                eventArgs.cell = cell;
                eventArgs.value = cell.value;
                context.notify(index_4.checkDateFormat, eventArgs);
                if (!cell.format) {
                    var cellVal = cell.value.toString();
                    if (cellVal.includes(options.args.curSymbol) || cellVal.includes(localeNumObj.group) || cellVal.includes('%')) {
                        options.fResult = cellVal;
                        context.notify(index_4.checkNumberFormat, options);
                    }
                    else Iif (localeNumObj.decimal !== '.' && !index_5.isNumber(cellVal)) {
                        if (cellVal.includes(localeNumObj.decimal)) {
                            cellVal = cellVal.replace(localeNumObj.decimal, '.');
                            if (index_5.isNumber(cellVal)) {
                                cell.value = cellVal;
                            }
                        }
                    }
                }
            }
        };
    }
    exports.getAutoDetectFormatParser = getAutoDetectFormatParser;
    function applyPredicates(dataManager, predicates, equalOrPredicates) {
        var query = new ej2_data_1.Query();
        if (predicates.length) {
            query.where(ej2_data_1.Predicate.and(predicates));
        }
        var result = dataManager.executeLocal(query);
        Iif (equalOrPredicates) {
            for (var idx = 0, predicateCollLen = equalOrPredicates.length; idx < predicateCollLen; idx++) {
                if (!result.length) {
                    break;
                }
                query = new ej2_data_1.Query();
                if (equalOrPredicates[idx].length) {
                    query.where(ej2_data_1.Predicate.or(equalOrPredicates[idx]));
                }
                result = new ej2_data_1.DataManager(result).executeLocal(query);
            }
        }
        return result;
    }
    exports.applyPredicates = applyPredicates;
    function isReadOnly(cell, column, row) {
        return (cell && cell.isReadOnly) || (row && row.isReadOnly) || (column && column.isReadOnly);
    }
    exports.isReadOnly = isReadOnly;
});