0
\$\begingroup\$

I'm working on stylesheet in Excel, and I've made this function of makeCells is there a better way of doing it. I've tried regex to get two cells formula.split(/\((.*)\)/g)[1].split(':') is there a way to get those cells without using split only regex.

const formula = "sum(B15:B20)";
const [start,end] = formula.split(/\((.*)\)/g)[1].split(':')
const extractNumber = str => str.replace(/[^\d]/g,'');
const makeCells = (start, end)=>{
    let colu  = start[0] 
    let first = +extractNumber(start);
    let last  = +extractNumber(end);
    return Array(last-first).fill(0).map((_,i)=>colu+(i+first)).concat(end);
}
console.log(makeCells(start,end))


And how can I make function more general, Call it only with formula like this makeCells('sum(B15:B20)') and return an array of cells?

\$\endgroup\$
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.