daGetData.Fill(dsGetData)
            Dim GetDataTABLE As DataTable = dsGetData.Tables(0)
            GVDATA.DataSource = dsGetData.Tables(0)
            GVDATA.DataBind()            GVDATA.AllowPaging = False
            GVDATA.DataBind()
            Response.Clear()
            Response.AddHeader("Content-Disposition", "attachment;filename=123.xls")
           
            'Response.ContentType = "application/vnd.xls"  
            Response.ContentType = "application/vnd.ms-excel"            Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter
            Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
            GVDATA.RenderControl(htmlWrite) 
            Response.Write(stringWrite.ToString)
            Response.End()服务器配置.ent3.5+win2003sever+iis6.0如果用Response.ContentType = "application/vnd.xls"  这一段导出时没有显示文件名各后辍。
如果用Response.ContentType = "application/vnd.ms-excel"这一段导出时直接接在浏览器当前页打开。
希望得到的结果是:按下导出时,弹出提示框,打开,保存,文件是带sxl后辍的。还有就是服务器需要安装office吗?

解决方案 »

  1.   

    下载不用office, 正常的应该是Response.ContentType = "application/vnd.ms-excel" 
    至于直接打开,是因为你曾经直接打开过,浏览器记住了操作方式
      

  2.   


        public static void Export(string FileType, string FileName,Page page,GridView gv)
        {        page.Response.Clear();
            page.Response.Buffer = true;
            //设定输出的字符集
            page.Response.Charset = "GB2312";
            //解决导出到Excel2007乱码问题
            page.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>");        //假定导出的文件名为盘点结果表.xls
            page.Response.AppendHeader("Content-Disposition", "attachment;filename=" +
                                 HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
            //解决导出到Excel2007乱码问题
            page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");        //设置导出文件的格式
            page.Response.ContentType = FileType;
            //关闭ViewState
            page.EnableViewState = false;
            
            StringWriter stringWriter = new StringWriter();
            HtmlTextWriter textWriter = new HtmlTextWriter(stringWriter);
            gv.RenderControl(textWriter);
            //把HTML写回浏览器
            page.Response.Write(stringWriter.ToString());
            page.Response.Flush();
            page.Response.End();        //貌似不需要恢复分页,如果出现错误反注释下面两句代码
            //GridView1.AllowPaging = true;//恢复分页
            ////为GridView重新绑定数据源
            //Bind();    }
    你试一试
      

  3.   

    //Export("application/ms-excel", "FileName.xls",this,GridView1);//调用
      

  4.   

    Response.ContentType = "application/vnd.ms-excel";
    Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString() + "CV.xls"); 这样就可以的啊。服务器比用装 excel
      

  5.   

    导出数据到excel模板
     string path = Server.MapPath("~/") + FilePath;
     Response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
                        if (File.Exists(path))
                        {
                            Response.ContentType = "application/octet-stream";
                            Response.WriteFile("" + path + "");
                        }
                        Response.End();