Advertisement
AceScottie

get_a1

May 9th, 2019
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function columnToLetter(column){
  2.   var temp, letter = '';
  3.   while (column > 0){
  4.     temp = (column - 1) % 26;
  5.     letter = String.fromCharCode(temp + 65) + letter;
  6.     column = (column - temp - 1) / 26;
  7.   }
  8.   return letter;
  9. }
  10. function to_a1(row, col, rowcount, colcount){
  11.   if(typeof(row)== "number" && typeof(col)== "number" && row >0 && col>0 ){
  12.     var ocol = col;
  13.     if(col !== null){col = columnToLetter(col);}
  14.     var a1 = col+row;
  15.     if(colcount !== null){
  16.       colcount = columnToLetter(ocol+colcount-1);
  17.       if(rowcount !== null){a1+=":"+colcount+(row+rowcount-1);}else{a1+=":"+colcount+row;}
  18.     }
  19.     Logger.log(a1);
  20.     return a1;
  21.   }else{
  22.     throw 'to_a1 requires row and col to be positive numbers';
  23.   }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement