首页 新闻 会员 周边 捐助

vs2008中新控件ListView无法像GrivdView样的方法导出数据到excel,word

0
悬赏园豆:100 [已关闭问题] 关闭于 2009-06-13 10:53

 WebExport c = new WebExport();
        c.TargetControlID = "lvUser";
        c.FileType = ExportFileType.Word;
        c.ExportFileName = "导出时的文件名字";
        c.ExtensionType = ".xls";
        c.Text = "Excel";
        c.Page = this;
        c.CommandName = "Click";

 

        Page page = new Page();
        HtmlForm form = new HtmlForm();
        c.EnableViewState = false;
        page.EnableEventValidation = false;
        page.Controls.Add(form);
        form.Controls.Add(c);

        HttpResponse response = HttpContext.Current.Response;
        response.Clear();
        response.Buffer = true;
        response.AddHeader("Content-Disposition", "attachment; filename=" + c.ExportFileName + c.ExtensionType + "");
        response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        response.ContentEncoding = System.Text.Encoding.UTF8;
        response.Charset = "UTF8";
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);  
        page.RenderControl(oHtmlTextWriter);
        response.Output.Write(oStringWriter.ToString());
        response.End();

 

导出以后很乱,没有中文

cswgylive的主页 cswgylive | 初学一级 | 园豆:5
提问于:2009-06-11 10:57
< >
分享
所有回答(0)
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册