excel4node lib以自动调整excel单元格的大小以适合较长的文本

时间:2018-09-05 13:00:28

标签: node.js excel excel4node

使用excel4node lib从某些Web表格中生成excel文档,是否有可能在文本太长而无法在一个单元格中容纳文本并使其宽度变大时自动调整单元格的大小?

documentation中,它们具有以下2个功能:

ws.column(3).setWidth(50);
ws.row(1).setHeight(20);

但这不适合其中的文本,只会使单元格更大。将显示示例:

enter image description here

和我想要的输出:

enter image description here

该注释单元格的代码:

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"]);
    });

关于评论栏。

2 个答案:

答案 0 :(得分:0)

您可以为单元格设置添加对齐设置:

alignment: { 
    shrinkToFit: boolean, 
    wrapText: true
}

答案 1 :(得分:0)

此功能尚未实现,as exposed in this GitHub issue。在此问题中,the author is pointing to an approximation approach used by PHPOffice考虑​​到字体和内容的长度来动态设置列的宽度。