将datagrid导出为ex​​cel [英] Export datagrid to excel

查看:64
本文介绍了将datagrid导出为ex​​cel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将数据网格转换为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


这篇关于将datagrid导出为ex​​cel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆