Search code examples
javascripthtmlxlsxtabulator

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


I am using Tabulator as frontend table framework. When I download the table data in Excel file format, my columns have default size. Is it possible to set the width of columns in xls file? I need the columns to be the same size as in the table in the browser.


Solution

  • I found a solution how to set column widths using 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;
        },
      });