asp.net 如何将网页格式的excel转换为真正的excel?
就是我用Response.Write将GridView导出Excle但是如果我讲导出的Excel文件修改会多出个.flies的文件.这个Excel不是真正格式的Excel...
就是我用Response.Write将GridView导出Excle 但是如果我讲导出的Excel文件修改 会多出个 .flies的文件.这个Excel不是真正格式的Excel,是HTML格式的,我是想直接将这个HTML格式的eXCEL直接转换成真正格式的Excel,这样的话里面的一些合并单元格的也会在。我就是想请教怎么将他们转换
展开
展开全部
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();
我测试过 可以用
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();
我测试过 可以用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |