define(["require", "exports", "@syncfusion/ej2-base", "../base/index"], function (require, exports, ej2_base_1, index_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getRangeIndexes(range) {
var cellindexes;
var indexes = [];
if (range) {
range = range.lastIndexOf('!') > -1 ? range.substring(range.lastIndexOf('!') + 1) : range;
range = range.indexOf(':') === -1 ? range + ':' + range : range;
var containsAlphabetsAndDigits = new RegExp(/^(?=.*[a-zA-Z])(?=.*\d)/g);
if (!containsAlphabetsAndDigits.test(range)) {
var refArr = range.split(':');
range = ej2_base_1.isNullOrUndefined(range.match(/[0-9]/)) ? (refArr[0] + '1:' + refArr[1] + '1') : ('A' + refArr[0] + ':A' + refArr[1]);
}
range.split(':').forEach(function (address) {
cellindexes = getCellIndexes(address);
indexes.push(cellindexes[0]);
indexes.push(cellindexes[1]);
});
}
return indexes;
}
exports.getRangeIndexes = getRangeIndexes;
function getCellIndexes(address) {
return [parseInt(address.match(/\d+/)[0], 10) - 1, getColIndex(address.match(/[A-Z]+/i)[0].toUpperCase())];
}
exports.getCellIndexes = getCellIndexes;
function getColIndex(text) {
var colIdx = 0;
text = text.split('').reverse().join('');
for (var i = text.length - 1; i >= 0; i--) {
colIdx += (text[i].charCodeAt(0) - 64) * (Math.pow(26, i));
}
return colIdx - 1;
}
exports.getColIndex = getColIndex;
function getCellAddress(sRow, sCol) {
return getColumnHeaderText(sCol + 1) + (sRow + 1);
}
exports.getCellAddress = getCellAddress;
function getRangeAddress(range) {
return getCellAddress(range[0], range[1]) + ':' + (!ej2_base_1.isNullOrUndefined(range[2]) ?
getCellAddress(range[2], range[3]) : getCellAddress(range[0], range[1]));
}
exports.getRangeAddress = getRangeAddress;
function getColumnHeaderText(colIndex) {
var alphabet = 'Z';
if (colIndex / 26 > 1) {
return getColumnHeaderText((colIndex % 26 === 0) ? (colIndex / 26 - 1) : Math.floor(colIndex / 26))
+ String.fromCharCode((colIndex % 26) === 0 ? alphabet.charCodeAt(0) : 64 + (colIndex % 26));
}
else {
return String.fromCharCode(64 + (colIndex));
}
}
exports.getColumnHeaderText = getColumnHeaderText;
function getIndexesFromAddress(address) {
return getRangeIndexes(getRangeFromAddress(address));
}
exports.getIndexesFromAddress = getIndexesFromAddress;
function getRangeFromAddress(address) {
var sheetRefIndex = address.lastIndexOf('!');
return sheetRefIndex > -1 ? address.substring(sheetRefIndex + 1) : address;
}
exports.getRangeFromAddress = getRangeFromAddress;
function getAddressFromSelectedRange(sheet) {
return sheet.name + '!' + sheet.selectedRange;
}
exports.getAddressFromSelectedRange = getAddressFromSelectedRange;
function getAddressInfo(context, address) {
return { sheetIndex: getSheetIndexFromAddress(context, address), indices: getIndexesFromAddress(address) };
}
exports.getAddressInfo = getAddressInfo;
function getSheetIndexFromAddress(context, address) {
var sIdx;
if (address.indexOf('!') > -1) {
sIdx = index_1.getSheetIndex(context, index_1.getSheetNameFromAddress(address));
}
else {
sIdx = context.activeSheetIndex;
}
return sIdx;
}
exports.getSheetIndexFromAddress = getSheetIndexFromAddress;
function getSwapRange(range) {
var clonedRange = range.slice();
if (range[0] > range[2]) {
swap(clonedRange, 0, 2);
}
if (range[1] > range[3]) {
swap(clonedRange, 1, 3);
}
return clonedRange;
}
exports.getSwapRange = getSwapRange;
function swap(range, x, y) {
var tmp = range[x];
range[x] = range[y];
range[y] = tmp;
}
function isSingleCell(range) {
return range[0] === range[2] && range[1] === range[3];
}
exports.isSingleCell = isSingleCell;
});
|