This is a migrated thread and some comments may be shown as answers.

How to set width of columns in the excel?

2 Answers 936 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Federico
Top achievements
Rank 1
Federico asked on 02 Nov 2017, 03:39 PM

How to set width of columns in the excel with mvvm grid?

I have this function in the viewmodel:

$("#gridall").data("kendoGrid").bind("excelExport", function (e) {
            var sheet = e.workbook.sheets[0].columns;
        });
I'd like to set autoWidth property for all columns;

2 Answers, 1 is accepted

Sort by
0
Federico
Top achievements
Rank 1
answered on 02 Nov 2017, 04:34 PM
and, What should I do if I wanted to change the height of all the cells in a column?
0
Preslav
Telerik team
answered on 03 Nov 2017, 02:05 PM
Hi Federico,

The desired functionality could be achieved by deleting the default width property and changing the autoWidth to true. For example, the modified code could look like:

excelExport: function(e) {
  var sheet = e.workbook.sheets[0];
  for (var i = 0; i < sheet.columns.length; i++) {
    delete sheet.columns[i].width;
    sheet.columns[i].autoWidth = true;
  }
}

For a runnable example, check this Dojo: http://dojo.telerik.com/OLIDO

Furthermore, I believe that it is a better approach to manually control the widths of the excel columns by explicitly setting the values by following the approach outlined in this forum:
Finally, changing the height of cells in a column is not possible. You could change the height of a row by using the sheets.rows.height configuration:
I hope this helps.


Regards,
Preslav
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Federico
Top achievements
Rank 1
Answers by
Federico
Top achievements
Rank 1
Preslav
Telerik team
Share this question
or