Response.Clear(); Response.Charset = "gb2312"; Response.AddHeader("content-disposition", "attachment;filename=shengchanpaicheng.xls"); Response.ContentEncoding = System.Text.Encoding.UTF7; Response.ContentType = "application/ms-excel"; System.IO.StringWriter strw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmw = new HtmlTextWriter(strw); GridView1.AllowPaging = false; GridView1.DataSource = bindgrid(); GridView1.DataBind(); GridView1.RenderControl(htmw); Response.Write(strw.ToString()); Response.End(); GridView1.AllowPaging = true; bindgrid();
用Office2003能正常显示shengchanpaicheng.xls里面的数据.可是现在同事用的是office2007却打不开,有什么办法能让office2007也能正常使用?谢谢.
错误提示:
你尝试打开的文件的格式shengchanpaicheng.xls与文件扩展名指定的格式不一致,打开之前请验证文件没有损坏且来源可信,是否立即打开该文件.
解决方案 »
- 今天刚接触.net的伪静态化,那为高手可以解释下这些重写规则!~~
- 用一个类保存获取IP地址的方法?
- sql server如何转换为ACCESS?
- ASP.NET问题
- 请问asp.net 中怎么写cookie 谢谢
- 求助:自定义控件的事件执行不正常,极其特殊而怪异,望朋友们帮忙!!!!!
- petshop,duwanish 感覺太簡單, Asp.net forums,DottextWeb 又感覺太難,為什麼啊,我該怎麼學
- 此问题已有人提出,但好像没有解决 就是Cookies 取出的值是乱码
- 查询数据时,查询条件绑定在DropDownList里,查询结果显示在Gridview里
- 请问怎么再网页上动态显示多组控件
- b/s架构里边怎么使用.dell,顶的也有分
- asp.net中, 把一段文本(c++源文件),在服务器端处理后(改变某些行的字体,颜色),显示到客户端.
参考:http://topic.csdn.net/u/20080515/02/640fcb7f-835b-4ed0-b853-edd10d927b0a.html
#region 导出到Excel
///<summary>
/// 导出到Excel
///</summary>
protected void lbtnExport_Click(object sender, EventArgs e)
{
Response.Clear();
Page.Response.Buffer = true;
Response.Charset = "gb2312";
string strFileName = "FileName.xls";
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8));
Response.ContentEncoding = System.Text.Encoding.UTF8; System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
gvIndex.AllowPaging = false;
gvIndex.ShowFooter = true;
NewBind();
gvIndex.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
gvIndex.AllowPaging = true;
NewBind();
}
//此方法必须存在
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for
}
#endregion
{
}
加上这个方法就可以了!