licp
2024-06-28 771699a2a85aecde95a4393ef6016b28f73a551e
src/util/excelFountion.js
@@ -1,7 +1,7 @@
function SUM(...val){
  let num = 0;
  let num = null;
  if(val&&val.length>0){
    val.forEach(item=>{
      num+=item;
@@ -10,33 +10,44 @@
  return num;
}
function MAX(...val){
  let max = 0;
  let max = null;
  if(val&&val.length>0){
    val = val.filter(item=>item!=null&&item!=='')
    max = Math.max(...val)
    if(val.length>0){
      max = Math.max(...val)
    }else{
      max = null;
    }
  }
  return max;
}
function MIN(...val){
  let min = 0;
  let min = null;
  if(val&&val.length>0){
    val = val.filter(item=>item!=null&&item!=='')
    min = Math.min(...val)
    console.log(val)
    if(val.length>0){
      min = Math.min(...val)
    }
  }
  return min;
}
function AVERAGE(...val){
  let num = 0;
  let num = null;
  let arr = [];
  if(val&&val.length>0){
    arr = val.filter(item=>item!=null&&item!=='')
    arr.forEach(item=>{
      num+=item;
    })
    return num/arr.length;
    if(arr.length>0){
      return num/arr.length;
    }else{
      return null;
    }
  }else{
    return 0;
    return null;
  }
}
@@ -51,19 +62,23 @@
 * @param {Object} cellId
 */
function getColumnNameFromId(cellId){
   if (! Array.isArray(cellId)) {
      cellId = cellId.split('-');
   }
   var i = cellId[0];
   var letter = '';
   if (i > 701) {
      letter += String.fromCharCode(64 + parseInt(i / 676));
      letter += String.fromCharCode(64 + parseInt((i % 676) / 26));
   } else if (i > 25) {
      letter += String.fromCharCode(64 + parseInt(i / 26));
   }
   letter += String.fromCharCode(65 + (i % 26));
   return letter + (parseInt(cellId[1]) + 1);
  try{
    if (! Array.isArray(cellId)) {
      cellId = cellId.split('-');
    }
    var i = cellId[0];
    var letter = '';
    if (i > 701) {
      letter += String.fromCharCode(64 + parseInt(i / 676));
      letter += String.fromCharCode(64 + parseInt((i % 676) / 26));
    } else if (i > 25) {
      letter += String.fromCharCode(64 + parseInt(i / 26));
    }
    letter += String.fromCharCode(65 + (i % 26));
    return letter + (parseInt(cellId[1]) + 1);
  }catch(e){
    console.log('error',cellId)
  }
}
/**
 * 根据列名获取坐标
@@ -71,37 +86,41 @@
 * @param {Object} arr
 */
function getIdFromColumnName(id, arr) {
   // Get the letters
   var t = /^[a-zA-Z]+/.exec(id);
   if (t) {
      // Base 26 calculation
      var code = 0;
      for (var i = 0; i < t[0].length; i++) {
         code += parseInt(t[0].charCodeAt(i) - 64) * Math.pow(26, (t[0].length - 1 - i));
      }
      code--;
      // Make sure jexcel starts on zero
      if (code < 0) {
         code = 0;
      }
      // Number
      var number = parseInt(/[0-9]+$/.exec(id));
      if (number > 0) {
         number--;
      }
      if (arr == true) {
         id = [ code, number ];
      } else {
         // id = code + '-' + number;
      id = {
        c:code,
        r:number
  try{
    // Get the letters
    var t = /^[a-zA-Z]+/.exec(id);
    if (t) {
      // Base 26 calculation
      var code = 0;
      for (var i = 0; i < t[0].length; i++) {
        code += parseInt(t[0].charCodeAt(i) - 64) * Math.pow(26, (t[0].length - 1 - i));
      }
      }
   }
   return id;
      code--;
      // Make sure jexcel starts on zero
      if (code < 0) {
        code = 0;
      }
      // Number
      var number = parseInt(/[0-9]+$/.exec(id));
      if (number > 0) {
        number--;
      }
      if (arr == true) {
        id = [ code, number ];
      } else {
        // id = code + '-' + number;
        id = {
          c:code,
          r:number
        }
      }
    }
    return id;
  }catch(e){
    console.log('error',id)
  }
}
// 获取参数列表