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

2.3k views Asked by At

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.

2

There are 2 answers

0
Alex On BEST ANSWER

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;
    },
  });
0
Adrian Klaver On

Excel spreadsheet and Tabulator are not the same thing so if will be difficult to set up a one to one relationship between them. You could set up column widths in your table constructor using these settings. There is also the fit data options.