I think you just want to iterate through the list items index based in for loop
static public void WriteToFile<T>(List<T> YourList)
{
for (int i = 0; i < YourList.count(); i++)
{
excelWorksheet.Cells[i + 1, "A"] = yourList[i].ID;
excelWorksheet.Cells[i + 1, "B"] = yourList[i].Name;
}
}
Or should be using foreach statement like
foreach(var item in yourList)
{
// you should increment i
excelWorksheet.Cells[i + 1, "A"] = item.ID;
}
Hope this helps