Tuesday, May 10, 2011

Genralize function for reading data from Excel

public void PopulateToExcel(IList list,int TabNum , int iRow)
{
try
{
//System.Threading.Thread.Sleep(30000);

worksheet = package.Workbook.Worksheets[TabNum];

Type elementType = typeof(T);
foreach (T item in list)
{
int iColumn = 1;
foreach (var propInfo in elementType.GetProperties())
{
worksheet.Cells[iRow, iColumn].Value = propInfo.GetValue(item, null) ?? DBNull.Value;
iColumn = iColumn + 1;
}
iRow = iRow + 1;
}
}
catch (Exception ex)
{

}
}

No comments:

Post a Comment