将Gridview数据导出到MS Word 2007和MS Excel 2007 [英] Exporting Gridview Data to MS word 2007 and MS Excel 2007

查看:95
本文介绍了将Gridview数据导出到MS Word 2007和MS Excel 2007的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨......
如何将gridview数据导出到msword和msexcel ...我已经做到了,但是它不支持XML数据....因为我拥有MSword 2007和MS excel 2007
这是我的编码:-

hi....
how to export the gridview data to msword and msexcel ...i have done it but its not supporting XML data....since i am having MSword 2007 and MS excel 2007
and this is my coding:-

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            binddate();
        }

    }
    private void binddate()
    {
        try
        {
            string connection = ConfigurationManager.AppSettings["ConnectInfo"];
            SqlConnection con = new SqlConnection(connection);
            SqlDataAdapter da = new SqlDataAdapter("select * from quanta", con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            gv_details.DataSource = dt;
            gv_details.DataBind();

        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);

        }
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        /* verifies the control is rendered*/

    }

    protected void btn_word_Click(object sender, ImageClickEventArgs e)
    {
        gv_details.AllowPaging = false;
        gv_details.DataBind();
        Response.ClearContent();
        Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", "Doc1.docx"));
            Response.Charset="";
        Response.ContentType="application/ms-word 2007";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw=new HtmlTextWriter(sw);
        gv_details.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
    }
}



请帮助我....在此先感谢...



please help me....thanks in advance...

推荐答案

尝试以下链接:-

http://forums.asp.net/t/1412788.aspx [
try this link:-

http://forums.asp.net/t/1412788.aspx[^]

Please don''t forget to mark this as your answer if it helps you out.

Thanks


这篇关于将Gridview数据导出到MS Word 2007和MS Excel 2007的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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