How to set width of columns in the excel?

3 posts, 0 answers
  1. Federico
    Federico avatar
    21 posts
    Member since:
    Oct 2017

    Posted 02 Nov 2017 Link to this post

    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. Federico
    Federico avatar
    21 posts
    Member since:
    Oct 2017

    Posted 02 Nov 2017 Link to this post

    and, What should I do if I wanted to change the height of all the cells in a column?
  3. Preslav
    Admin
    Preslav avatar
    516 posts

    Posted 03 Nov 2017 Link to this post

    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.
Back to Top