Alex
Alex

Reputation: 35

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.

Upvotes: 0

Views: 2746

Answers (2)

Alex
Alex

Reputation: 35

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;
    },
  });

Upvotes: 1

Adrian Klaver
Adrian Klaver

Reputation: 19665

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.

Upvotes: 1

Related Questions