3

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:

enter image description here

and my desired output:

enter image description here

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.

Tatu Bogdan
  • 586
  • 2
  • 10
  • 27

2 Answers2

0

you can add alignment settings for cell setting :

alignment: { 
    shrinkToFit: true, 
    wrapText: true
}
Community
  • 1
  • 1
0

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.

Chris
  • 1,140
  • 15
  • 30