Home » excel » javascript – how write to cell that spans multiple columns using excelJS?

javascript – how write to cell that spans multiple columns using excelJS?

Posted by: admin May 14, 2020 Leave a comment

Questions:

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'} ;
}
How to&Answers:

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'} ;
}