column metadata for Excel export

2 posts, 1 answers
  1. Scott Buchanan
    Scott Buchanan avatar
    42 posts
    Member since:
    Dec 2008

    Posted 06 Nov 2015 Link to this post

    Greetings!  I have a set of grids to export to Excel.  I completed the first, with the help of your fine demo apps.

    I have quite a bit of code for the OnExcelExport(e) event to set Excel column widths, cell colors, etc.  For example:

    //Set column width and wrap text
    if (colIndex == 0) {
        row.cells[colIndex].wrap = true;
        sheet.columns[colIndex].autoWidth = false;
        sheet.columns[colIndex].width = 63;
    if (colIndex == 5 || colIndex == 6 || colIndex == 7) {
        row.cells[colIndex].wrap = true;
        sheet.columns[colIndex].autoWidth = false;
        sheet.columns[colIndex].width = 72;

    My question is :Is there a way to store metadata in the column definition of the grid that I can read in OnExcelExport(e) so that I can create shared, generic functions to set the Excel attributes or must I code each grid like this (referencing column order, etc.)?  I tried stuffing attributes in the clientTemplate but this always seemed to affect my HTML grid...


  2. Answer
    Dimiter Madjarov
    Dimiter Madjarov avatar
    2288 posts

    Posted 09 Nov 2015 Link to this post

    Hello Scott,

    The metadata cannot be added to the columns through the fluent API (except as some data- HTML attributes), but you could add metadata to the columns definition on document.ready i.e. when the widget is initialized.

    $(function () {
        var grid = $("#grid").data("kendoGrid");
        grid.columns[0].myMetadata = { ... };

    You could then access this custom data in the excelExport event and use it to customize the exported document. I hope this information helps.

    Dimiter Madjarov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top