Dzwebs.Net

撰写电脑技术杂文十余年

将Panel控件的数据导出到WROD并下载的代码

Admin | 2015-5-12 10:49:26 | 被阅次数 | 3866

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  将Panel控件的数据,先导入到Word之后,再下载Word的功能代码如下,提供两种代码。

  第一种代码

  StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        this.Panel1.RenderControl(hw);

        System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
        response.Clear();
        response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        response.ContentType = "application/vnd.ms-word";

        response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlPathEncode(Server.UrlDecode("文档名称") + ".doc"));
        //response.Charset = "utf-8";
        response.Write(tw.ToString());
        response.End();

  第二种代码

  Response.ClearContent();
        Response.AddHeader("content-disposition", "attachment; filename=文档名称.doc");
        //Response.ContentType = "application/word";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        Response.ContentType = "application/word";
        Response.ContentType = "application/vnd.ms-word";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        Panel1.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();

  上面的代码只是能实现导入word下载的功能,但是,假如控件中有图片或有网页换行等标记,不能在word中自动转换。也就是说,只能将控件中的网页源代码内容导入到WORD中,不能实现相关标记的自动识别替换。


该杂文来自: 网站开发杂文

上一篇:下篇:asp.net动态生成WORD并填充内容的代码

下一篇:通过page_Init获取点击了哪个按钮

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计