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

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

    public exportAsExcelFile(json: any[], excelFileName: string): void {
    
       const header = Object.keys(json[0]); // columns name
    
       var wscols = [];
       for (var i = 0; i < header.length; i++) {  // columns length added
         wscols.push({ wch: header[i].length + 5 })
       }
       const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);
       worksheet["!cols"] = wscols;
    }
    

提交回复
热议问题