Reputation: 596
Using excel4node lib in order to generate excel docs out of some web tables, is there a possibility to autosize cell when the text is too long to fit it in one cell and to make the width of the cell bigger?
In documentation they have this 2 functions:
ws.column(3).setWidth(50);
ws.row(1).setHeight(20);
But that won't fit the text inside, will just make the cell bigger. Will show example:
and my desired output:
Code for that comment cell:
reducedReport.forEach((element, index) => {
ws.cell(index + 2, 1).string(element["projectName"]);
ws.cell(index + 2, 2).string(element["workerName"]);
ws.cell(index + 2, 3).string(element["comment"]);
ws.column(3).setWidth(30);
ws.row(15).setHeight(40);
ws.cell(index + 2, 4).string(moment(element["date"] * 1000).format("DD-MM-YYYY"));
console.log(element["comment"]);
});
It's about comment column.
Upvotes: 3
Views: 8707
Reputation: 11
you can add alignment settings for cell setting :
alignment: {
shrinkToFit: true,
wrapText: true
}
Upvotes: 0
Reputation: 1230
This feature is not implemented yet, as exposed in this GitHub issue. In that issue, the author is pointing to an approximation approach used by PHPOffice, to dynamically set the column's width considering the font and the content's length.
Upvotes: 0