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();
导出以后很乱,没有中文