SheetJS sum adjacent columns by range

Viewed 409

I'm trying to add the values of two adjacent columns using SheetJS. The resulting sheet needs to contain the formula.

From an Excel perspective

  • A1 = B1 + C1
  • A2 = B2 + C2
  • A3 = B3 + C3
  • ... and so on

I get the desired result using the approach below:

const range = { s: { c: 0, r: 0 }, e: { c: 10, r: 50 } };

for (let i = 0; i < 50; i++) {
    wSheet[`A${i}`] = { f: `B${i} + C${i}`};
}

wSheet['!ref'] = xlsx.utils.encode_range(range);

However, is there a more elegant way of doing so by defining a formula column range and thereby avoiding a loop? Maybe I'm not looking at the documentation correctly https://github.com/SheetJS/sheetjs#cell-object.

Thanks in advance

0 Answers
Related