'Exceljs How to addRow and merge cells
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:
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()?
Solution 1:[1]
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 );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

