The trick is not to pass numbers as "unprocessed objects" in EPPlus, but to correctly list them.
Here's how I did it in the export method from DataTable to Excel, which I did using EPPlus:
if (dc.DataType == typeof(int)) ws.SetValue(row, col, !r.IsNull(dc) ? (int)r[dc] : (int?)null); else if (dc.DataType == typeof(decimal)) ws.SetValue(row, col, !r.IsNull(dc) ? (decimal)r[dc] : (decimal?)null); else if (dc.DataType == typeof(double)) ws.SetValue(row, col, !r.IsNull(dc) ? (double)r[dc] : (double?)null); else if (dc.DataType == typeof(float)) ws.SetValue(row, col, !r.IsNull(dc) ? (float)r[dc] : (float?)null); else if (dc.DataType == typeof(string)) ws.SetValue(row, col, !r.IsNull(dc) ? (string)r[dc] : null); else if (dc.DataType == typeof(DateTime)) { if (!r.IsNull(dc)) { ws.SetValue(row, col, (DateTime)r[dc]);
IMPORTANT : It is worth noting that DateTime values ββwill require more work for proper processing, since we would like to format it in a certain way AND, possibly, support NULL values ββin the column: the above method fulfills both of these requirements.
I posted a complete code example (DataTable to Excel file with EPPlus) in this blog post .
source share