2

So I need to generate an excel spreadsheet based on data from DB. Once I add in all the data from the DB I need to add in a new row at the bottom that says when the spreadsheet was generated like so:

enter image description here

I don't know how to get the cells to merge here, I can't use worksheet.mergeCells() since I don't know how many rows of data there will be in the DB. How would I merge the cells when using worksheet.addRow()?

Nayeer Mahiuddin
  • 187
  • 3
  • 16

1 Answers1

5

I have come across a similar problem and have used something close to this:

const newRow = worksheet.addRow(["This report is..."]);
const currentRowIdx = worksheet.rowCount; // Find out how many rows are there currently
const endColumnIdx = worksheet.columnCount; // Find out how many columns are in the worksheet
    
// merge by start row, start column, end row, end column
worksheet.mergeCells(currentRowIdx, 1, currentRowIdx, endColumnIdx );
Aidam1
  • 73
  • 7