# make an array of cells from formula like in excel with javascript?

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?

• My first question would be: Why are you manually "parsing" the formula? Assuming that the formula came from a cell/range in Excel, you could just ask Excel for the "precedents". (A precedent is a cell that provides data to a formula.) See: Get formula precedents and dependents using the Excel JavaScript API Dec 30, 2021 at 19:06