I am looping my table data and trying to place table rows in excel file but I need to get index of each row in order to make rows in my excel file.
foreach (DataRow row in dt.Rows)
{
xlWorkSheet.Cells[2, 1] = row["Id"].ToString();
xlWorkSheet.Cells[2, 2] = row["ProductId"].ToString();
xlWorkSheet.Cells[2, 3] = row["OrderQuantity"].ToString();
xlWorkSheet.Cells[2, 4] = row["CustomerID"].ToString();
xlWorkSheet.Cells[2, 5] = row["OrderDate"].ToString();
xlWorkSheet.Cells[2, 6] = row["Tax"].ToString();
xlWorkSheet.Cells[2, 7] = row["Total"].ToString();
xlWorkSheet.Cells[2, 8] = row["Net"].ToString();
}
All I need is the way to replace 2
(excel row number) in xlWorkSheet.Cells[2, 8]
with foreach index
number so instead of static row 2
it will be row 3, 4,5,6,...
based on how many rows I have in database.
Any suggestion?