如何在导出.xlsx文件时设置单元格宽度

时间:2022-02-27 16:55:19

I am trying to set a fixed column/cell width to my exported excel files with js-xlsx.

我正在尝试用js-xlsx为我导出的excel文件设置一个固定的列/单元格宽度。

EDIT:

编辑:

Here is the source of js-xlsx: https://github.com/SheetJS/js-xlsx

下面是js-xlsx的源代码:https://github.com/SheetJS/js-xlsx

如何在导出.xlsx文件时设置单元格宽度

1 个解决方案

#1


39  

I found a snippet the the write test here https://github.com/SheetJS/js-xlsx/blob/master/tests/write.js#L14-L19

我在这里找到了一个写测试的片段https://github.com/SheetJS/js-xlsx/blob/master/tests/write.js#L14-L19

For quick reference, where ws is your worksheet.

对于快速引用,ws是您的工作表。

var wscols = [
    {wch:6},
    {wch:7},
    {wch:10},
    {wch:20}
];

ws['!cols'] = wscols;

#1


39  

I found a snippet the the write test here https://github.com/SheetJS/js-xlsx/blob/master/tests/write.js#L14-L19

我在这里找到了一个写测试的片段https://github.com/SheetJS/js-xlsx/blob/master/tests/write.js#L14-L19

For quick reference, where ws is your worksheet.

对于快速引用,ws是您的工作表。

var wscols = [
    {wch:6},
    {wch:7},
    {wch:10},
    {wch:20}
];

ws['!cols'] = wscols;