I use this function:

DataGrid.prototype.exportToExcel = function () { var table = this._generateGridTable(true); var uri = 'data:application/vnd.ms-excel;base64,', template = '<html><head><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table border="1" border-collapse="collapse">{table}</table></body></html>', base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }; var ctx = { table: table.html() } var link = document.createElement('a'); link.href = uri + base64(format(template, ctx)); link.download = this.definition.exportFilename + ".xls"; document.body.appendChild(link); // needed for FF link.click(); document.body.removeChild(link); } 

Everything works fine, but if there is a very large number in the table (for example, the phone is incorrectly specified), then excel does not transmit it as it is. Example: the table shows 972544966794, but in excel it is like 9.72545E + 11 how to deal with it?

  • Do not slip html markup excel? - Qwertiy
  • @Qwertiy is impossible - lili

1 answer 1

For a cell with a long number, you need to set the style mso-number-format: '\@' :

 <td style="mso-number-format: '\@'">1234567890123456789</td> 
  • thanks It works! - lili