Export to Excel - Footer as Number, Not String

2 posts, 1 answers
  1. kencox
    kencox avatar
    106 posts
    Member since:
    Oct 2002

    Posted 28 Apr 2018 Link to this post

    Hey folks,

    When I export my grid to Excel, the client footer value is formatted as a string (see the Excel image below).

    Is it possible to tell Excel that this is a numeric value?

    Thanks,

    Ken

    columns.Bound(e => e.Total).Title("Amount").Width(120).Format("{0:C}").ClientFooterTemplate("#= kendo.format('{0:c}', sum)#");
  2. Answer
    Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    1041 posts

    Posted 01 May 2018 Link to this post

    Hello, Ken,

    To get the Kendo UI Grid Excel Export footer to generate a cell like the rest of the numeric cells, you should add a handler to the excelExport event and parse the value of the cell to a float. You may use the kendo.parseFloat() method:

    excelExport: function(e){
      var rows = e.workbook.sheets[0].rows;
     
      for (var ri = 0; ri < rows.length; ri++) {
        var row = rows[ri];
     
        if (row.type == "footer") {
          for (var ci = 0; ci < row.cells.length; ci++) {
            var cell = row.cells[ci];
            if (cell.value) {
              cell.value = kendo.parseFloat(cell.value);
            }
          }
        }
      }
    },
     
    Here is a runnable example for your convenience:

    https://dojo.telerik.com/@bubblemaster/IsIRuHEL

    Let me know if you need further assistance.

    Kind Regards,
    Alex Hajigeorgieva
    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