Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excel行列解析算法 #99

Open
bojue opened this issue Sep 19, 2020 · 0 comments
Open

Excel行列解析算法 #99

bojue opened this issue Sep 19, 2020 · 0 comments

Comments

@bojue
Copy link
Owner

bojue commented Sep 19, 2020

let getCols = (str) => {
  let arr = str.split('');
  let len = arr.length;
  let res = 0;
  for(let i=0;i<len;i++) {
      let item = arr[i];
      let curr = (item.charCodeAt(0) - 64) * Math.pow(26, (len -1 -i));
      res += curr;
  }
  return res;
}
let getParams = (str)=> {
  if(str === undefined || str === null) return;
  let arr = str.match(/(^[A-Z]+)([0-9]+$)/);
  let [, col, row] = arr;
  let obj = {
      col: getCols(col),
      row: row
  }
  return obj;
}

getParams('AA12'); // {col: 27, row: "12"}
@bojue bojue changed the title instanceof的核心实现原理 Excel行列解析算法 Sep 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant