How to Auto Resize Row in excelJs? [Duplicate]
How to Set Excelsheet Row Height to Auto So That the Content Can Autofit in the Cell Using Exceljs 1 3 Answers You Can Do This by Doing a Loop as Shown Below...
You can do this by doing a loop as shown below:
const workbook = new Excel.Workbook();
const sheet1 = workbook.addWorksheet('sheet1');
for (let i = 0; i < sheet1.columns.length; i += 1) {
let dataMax = 0;
const column = sheet1.columns[i];
for (let j = 1; j < column.values.length; j += 1) {
const columnLength = column.values[j].length;
if (columnLength > dataMax) {
dataMax = columnLength;
}
}
column.height = dataMax < 10 ? 10 : dataMax;
}
Although initially I do not know that it can be done. If it can be started with a certain cell height:
yourDataArray.forEach((e, index) => {
worksheet.getRow(index).height = 28; // Height for file = 28 inches
worksheet.addRow({
...e // data Object [Destructuring][1]
})
}
´´´
[1]:
You can do something like this:
Foreach on your data and get the desired row through the index
const row = worksheet.getRow(index);
row.height = row.height * 20 / row.width;
*NOTE:
I fixed the number '20', but you can also make it a variable
In my excel, my data data starts at line four onwards, so I do:
const row = worksheet.getRow(index + 4);