It works but seems slower than it should. ideas?
Code:
public static void ExportToExcel(DataTable dt)
{
Excel.Application xlApp = new Excel.ApplicationClass();
Excel.Workbook xlBook;
Excel.Worksheet xlSheet;
xlBook = xlApp.Workbooks.Add(Missing.Value);
xlSheet = (Excel.Worksheet)xlBook.Worksheets.get_Item(1);
//Write headers
for(int i=0; i<dt.Columns.Count; i++)
{
xlSheet.Cells[1,i+1] = dt.Columns[i].ColumnName.ToString();
}
//Write Data
for(int i=0; i<dt.Rows.Count; i++)
{
for(int k=0; k<dt.Columns.Count; k++)
{
xlSheet.Cells[2+i,k+1] = dt.Rows[i][k];
}
}
xlApp.Visible = true;
}