A common problem with exporting to excel is you often may have columns that contain HTML or other content that doesn't work well with Excel.
A GENIUS friend of mine suggested that we just change the grid read when exporting so that it only provides the HTML or other non-friendly-to-Excel content during reads that aren't for an excel export. Thank you, Crankshaw! Here's how it works.
Just create a global parameter in javascript to identify when you're doing an excel export. Pass that parameter to the grid's Read.
Then give your standard excel export button an ID, so that you can tie events to it other than the normal excel export.
// toolbar.Excel().HtmlAttributes(new { id = "WIPDetailToXL" })
Then create two events in javascript.
NOTE: MouseDown happens prior to the Click event, but so does MouseUp. So use MouseDown and MouseOut, both on the ExcelExport button.
So when you Click to export, the mousedown will set the variable to let your read know that this is an "Excel Read". This happens BEFORE the export. And when you move your cursor off the Export button, the variable will change back so that subsequent reads will render your html correctly within your grid.
<script>
var exportExcelFlag = 0;
$("#WIPDetailToXL").mousedown(function (e) {
exportExcelFlag = 1;
});
$("#WIPDetailToXL").mouseout(function (e) {
exportExcelFlag = 0;
});
</script>
Hope this helps someone as much as it did me!