asp.net 如何将网页格式的excel转换为真正的excel?
发布网友
发布时间:2022-04-25 15:57
我来回答
共2个回答
热心网友
时间:2023-10-15 06:01
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
GridView1.EnableViewState = false;
page.EnableEventValidation = false;
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(GridView1);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application nd.ms-excel";
string name = "Keyword_Report-" + System.DateTime.Now.ToShortDateString();
Response.AddHeader("Content-Disposition", "attachment;filename=" + name + ".xls");
Response.Charset = "gb2312";
Response.ContentEncoding = Encoding.UTF8;
Response.Write(sb.ToString());
Response.End();
我测试过 可以用
热心网友
时间:2023-10-15 06:01
我前阵子刚弄过导出Excel,封装好的方法。需要的话,留个邮箱我发你。