怎样实现把datareader的记录集倒入excel ,使用户在客户端浏览时能打开excel.
下面是我的代码,可是按下按钮并不能启动excel,请指点
private void Button4_Click(object sender, System.EventArgs e)
{
SqlConnection conn=new SqlConnection(Application["conn"].ToString());
SqlDataAdapter excel_da=new SqlDataAdapter("select * from files",conn);
DataSet excel_ds=new DataSet("files");
excel_da.Fill(excel_ds);
DataTable excel_dt=excel_ds.Tables[0];
int rowIndex=1;
int colIndex=0;
Excel.Application excel= new Excel.Application();
try
{
excel.Application.Workbooks.Add(true);
// excel.Visible=true;
}
catch
{
Response.Write("您可能没有安装OFFICE!");
return ;
}
foreach(DataRow row in excel_dt.Rows)
{
Response.Write("do");
rowIndex++;
colIndex=0;
foreach(DataColumn col in excel_dt.Columns)
{
Response.Write("go");
colIndex++;
excel.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString();
}
}
// excel.Save(@"c:\1.xls");
excel.Visible=true;
}