how write to cell that spans multiple columns using excelJS?

RockBoro picture RockBoro · Aug 14, 2018 · Viewed 7.8k times · Source

can I create an excel cell which spans multiple columns using excelJS?

I tried getCell with a cell range. But the value was set in only the first column.

function colSpamDemo( )
{
  let wb = new ExcelJS.Workbook();
  let ws = wb.addWorksheet('Export');

  ws.getCell('A1:C1').value = 'This price list supercedes all prior price lists.';
  ws.getCell('A1:C1').alignment = { horizontal:'center'} ;
}

Answer

miken32 picture miken32 · Aug 29, 2018

You can create a merged cell, which sounds like what you are looking for.

function colSpamDemo( )
{
  let wb = new ExcelJS.Workbook();
  let ws = wb.addWorksheet('Export');

  ws.mergeCells('A1:C1');
  ws.getCell('A1').value = 'This price list supercedes all prior price lists.';
  ws.getCell('A1').alignment = { horizontal:'center'} ;
}