Yes you can do that.
From StackOverFlow. hope it helps.
http://stackoverflow.com/a/13973274[
^]
public static void ExportToExcel(this DataTable Tbl, string ExcelFilePath = null)
{
try
{
if (Tbl == null || Tbl.Columns.Count == 0)
throw new Exception("ExportToExcel: Null or empty input table!\n");
Excel.Application excelApp = new Excel.Application();
excelApp.Workbooks.Add();
Excel._Worksheet workSheet = excelApp.ActiveSheet;
for (int i = 0; i < Tbl.Columns.Count; i++)
{
workSheet.Cells[1, (i+1)] = Tbl.Columns[i].ColumnName;
}
for (int i = 0; i < Tbl.Rows.Count; i++)
{
for (int j = 0; j < Tbl.Columns.Count; j++)
{
workSheet.Cells[(i + 2), (j + 1)] = Tbl.Rows[i][j];
}
}
if (ExcelFilePath != null && ExcelFilePath != "")
{
try
{
workSheet.SaveAs(ExcelFilePath);
excelApp.Quit();
MessageBox.Show("Excel file saved!");
}
catch (Exception ex)
{
throw new Exception("ExportToExcel: Excel file could not be saved! Check filepath.\n"
+ ex.Message);
}
}
else
{
excelApp.Visible = true;
}
}
catch(Exception ex)
{
throw new Exception("ExportToExcel: \n" + ex.Message);
}
}
}