将VS中的倒到EXCEL中去
怎么将VS DATAGRID中的数据道入EXCEL中啊 大哥们 帮帮忙啊
Excel.Application excel = new Excel.ApplicationClass();
excel.Application.Workbooks.Add(true);
excel.Visible = true;
int colindex = 0;
foreach(DataColumn dc in dt.Columns)
{
colindex ++;
excel.Cells[1,colindex] = dc.ColumnName;
}
int rowindex = 1;
foreach(DataRow dr in dt.Rows)
{
rowindex ++;
colindex = 0;
foreach(DataColumn col in dt.Columns)
{
colindex ++;
excel.Cells[rowindex,colindex] = dr[col.ColumnName].ToString();
}
}
Conn.Close();
}