如何在 Tabulator 的 XLS 导出中设置列宽

How to set the column width in Tabulator's XLS export

我正在使用 Tabulator 作为前端 table 框架。 当我在 Excel file format 中下载 table 数据时,我的列具有默认大小。是否可以在 xls 文件中设置列宽?我需要列的大小与浏览器中 table 中的大小相同。

Excel 电子表格和制表符不是一回事,因此很难在它们之间建立一对一的关系。您可以使用这些 settings. There is also the fit data options.

在 table 构造函数中设置列宽

我找到了如何使用 sheetjs 设置列宽的解决方案

  table1.download("xlsx", "data.xlsx", {
    documentProcessing: function(workbook) {

      var ws_name = workbook.SheetNames[0];
      var ws = workbook.Sheets[ws_name];
      
      // setting column with in characters (use wpx for pixels)
      var wscols = [
          {wch:60},
          {wch:7},
          {wch:10},
          {wch:200}
      ];

      ws['!cols'] = wscols;

      return workbook;
    },
  });