Gridview数据导出Excel后,打开文件问题
我知道点击是之后是可以打开的,但是这个不是我用,是Boss用,Boss是个白痴啊,他不知道是什么问题
公司安装的是2007 加了 xslx后文件都打不开了 求解 --------------------编程问答-------------------- 代码贴出来看看。。。 --------------------编程问答--------------------
--------------------编程问答-------------------- 这个问题是 版本问题
protected void Button1_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "商品信息表.xls");
}
private void Export(string FileType, string FileName)
{
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;//
HttpContext.Current.Response.AppendHeader("Content-Disposition",
"attachment;filename=" + DateTime.Now.ToShortDateString() + ".xls");
HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
this.GridView1.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
private void bind()
{
DataSet ds;
List<string[]> OutList = new List<string[]>();
object[] Params = new object[5];
Params[0] = "*";
Params[1] = "Hotel_Order"; //订单表
Params[2] = "1=1";
Params[3] = "";
ds = Provider.DataSetList(false, out OutList, Params);
this.GridView1.DataSource = ds.Tables[0];
this.GridView1.DataBind();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
你生成Excel用的是 11.0.0 还是 12.0.0 ? 分别对应的 2003 和 2007
我记得我以前把后缀名改成xlsx 就没有提示 直接可以打开 --------------------编程问答-------------------- 不可以的,生成2007版本的 连打都打不开
--------------------编程问答--------------------
改完扩展名后就打不开了 --------------------编程问答-------------------- 楼主问题解决了吗?我也碰到这样的问题
补充:.NET技术 , C#