Tatu Bogdan
Tatu Bogdan

Reputation: 596

excel4node lib to autosize excel cell in order to fit longer text

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.

Upvotes: 3

Views: 8707

Answers (2)

M ghanom
M ghanom

Reputation: 11

you can add alignment settings for cell setting :

alignment: { 
    shrinkToFit: true, 
    wrapText: true
}

Upvotes: 0

Chris
Chris

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

Related Questions