我的程序需要将gridview里的数据在客户端以excel打开。代码如下:
Response.ClearContent();
Response.AddHeader("Contend-Disposition", "attachment;filename=temp.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.ContentType = "application/excel";
//string style = @"<style>.text{mso-number-format:@}</style>";//导出到excel时,保存表里数字列中前面存在的0
this.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
// Response.Write(style);
Response.Write(sw.ToString());
Response.End();
希望浏览器可以提示客户将这些数据以excel形式存储。但在我本机调试时,这些数据直接以网页形式打开。![图片说明](https://img-ask.csdn.net/upload/201503/23/1427090381_851726.png)
而部署在别人的机器上提示如下:
提示应该是temp.xls存储才对,不知是哪里出现问题了?