How to set cell width when export .xlsx files with js-xlsx

后端 未结 6 1384
南笙
南笙 2021-02-01 14:50

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

EDIT:

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

6条回答
  •  渐次进展
    2021-02-01 15:29

    Nothing new, but explicitly using the width property makes it a bit easier to maintain:

    ws['!cols'] = [{ width: 20 }, { width: 20 }, { width: 150 } ]; //set col. widths
    

    Here is the full list of properties you can give to these ColInfo objects though, they give reasons why each width exists, but they state you should use width > wpx > wch, depending on the type of sheet you have and what is available for your use case. More can be read here: https://docs.sheetjs.com/

提交回复
热议问题