将datagrid导出为excel
问题描述:
我需要将数据网格转换为excel。为此,我编写了以下代码,
i jst need to convert a datagrid to excel.For that i wrote the following code,
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=DailyReport.xls");
Response.Charset = "";
Response.ContentType = "~/SDailyReport.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
DataGrid g1 = new DataGrid();
List<griddisplay> obj1 = new List<griddisplay>();
obj1 = bl.Getgrid();
g1.DataSource = obj1;
g1.DataBind();
g1.RenderControl (htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
i在系统中完成此代码并获得结果。我在另一个中尝试相同系统没有安装ms office而且没有显示任何结果.SO
是否必须在系统中安装ms office才能导出到excel?
i done this code in a system and got the result.i tried the same in another system where ms office is not installed and its not showing any result.SO
whether its essential to have ms office installed in the system to export to excel?
答
您好,
请看这个链接。这似乎很有用:
http://forums.asp.net/t/1081527。 aspx [ ^ ]
我希望它有所帮助,
干杯
Hi,
Look at this link. It seems to be useful:
http://forums.asp.net/t/1081527.aspx[^]
I hope it helps,
Cheers