My data is held in an IEnumerable object and I want that to be populated into a table in excel.
Basically I am able to export data to the Excel sheet but I dont know export a table in a more elegant way.
This is what I have:
//Populate column names
String[] columnNames = {"val1", "val2", "val3", "val4", "val5"};
for (int p = 1, l = 1; l <= 5;l++)
{
xlWorkSheet.Cells[p, l] = columnNames[l-1];
}
//Entries is an IEnumerable object
int i = 1;
foreach (var e in Entries)
{
int j = 1;
xlWorkSheet.Cells[i, j] = e.val1; j++;
xlWorkSheet.Cells[i, j] = e.val2; j++;
xlWorkSheet.Cells[i, j] = e.val3; j++;
xlWorkSheet.Cells[i, j] = e.val4; j++;
xlWorkSheet.Cells[i, j] = e.val5; j++;
i++;
}
I was thinking about converting the data from IEnumerable to datatable like this Convert IEnumerable to DataTable but i thought it will introduce an extra layer of unnecessary complexity.
What are your thoughts?
Thanks