I am using Datatable.js and ClosedXML to export grid data to excel.
This is the template snapshot, column name changed for privacy –
And when I download the excel sheet, I get error in the last column, as shown –
If I change the Reported By parameter to any other parameters ,like ABC6 or ABC7 .etc, the error stays the same. But the values are coming for all the records in the other columns. Code for exporting data as xml on server side –
string webRootPath = _env.WebRootPath;
var template = new XLTemplate($"{webRootPath}\ReportTemplates\{model.ReportId.ToString()}Template.xlsx");
template.AddVariable("ReportDisplayName", model.ReportDisplayName);
template.AddVariable("ReportParameters", model);
switch (model.ReportId)
{
case ReportNames.FallReport:
var fallReportData = returnModel.ReportData as List<FallReportViewModel>;
template.AddVariable("ReportData", fallReportData);
break;
...
The viewmodel has all the column datataypes defined, including Reported By column,which is defined as a string. Code for jquery side –
buttons: [
{
text: 'Export to PDF',
action: function (e, dt, node, config) {
....
}
},
{
text: 'Export to Excel',
action: function (e, dt, node, config) {
if (ValidateReportParameterAndContent()) {
$("#ReportType").val("xls");
$("#ReportDisplayName").val($("#reportName").val());
$("#frmReport").submit();
setTimeout(function () { $(".page-loader").css('display', 'none'); }, 3000);
}
}
}
],
1