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

后端 未结 6 1329
南笙
南笙 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:24

    Similar to cell width, you can set the cell height in the following way

    var wsrows =  [
                     {hpt: 12}, // row 1 sets to the height of 12 in points
                     {hpx: 16}, // row 2 sets to the height of 16 in pixels
                   ];
    
    ws['!rows'] = wsrows; // ws - worksheet
    

    Hint: If your worksheet data is auto generated and you don't know how many rows and columns are get populated then you could use the following way to find the number of rows and columns in the worksheet for doing cell width/height formatting.

    var range = XLSX.utils.decode_range(ws['!ref']);
    var noRows = range.e.r; // No.of rows
    var noCols = range.e.c; // No. of cols
    

提交回复
热议问题