当前位置:编程学习 > C#/ASP.NET >>

gridview 导出excel 变成了aspx页面是怎么回事

gridview 导出excel 变成了aspx页面是怎么回事   在本地导出就是.xls 的文件, 但是放在服务器下载时就变成了.aspx 页面, 求救了 --------------------编程问答-------------------- 可能是代码的问题啊。你吧代码发点出来。让大家给你看下。 --------------------编程问答--------------------     #region
    /// <summary>
    /// 根据数据控件,文件类型,文件名称导出文件
    /// </summary>
    /// <param name="source">数据控件</param>
    /// <param name="type">文件类型</param>
    /// <param name="fileName">文件名称</param>
    public static void Export(Control source, string type, string fileName, Page page)
    {
        HttpResponse response = HttpContext.Current.Response;
        response.Clear();
        response.ClearContent();
        response.Buffer = true;
        string fType = type == "excel" ? ".xls" : ".doc";
        response.HeaderEncoding = Encoding.UTF8;
        response.AppendHeader("Content-Disposition", "attachment;fileName=" + HttpUtility.UrlEncode(fileName + fType, Encoding.UTF8));
        response.ContentType = "application/ms-excel";
        response.Charset = "GB2312";
        response.ContentEncoding = Encoding.UTF8;
        StringWriter sWriter = new StringWriter();
        HtmlTextWriter hWriter = new HtmlTextWriter(sWriter);
        source.EnableViewState = false;
        source.RenderControl(hWriter);
        response.Write(sWriter);
        response.ContentType = "text/html";
        page.RegisterStartupScript("onload", "<script language=javascript>window.location=window.location;window.alert();</script>");
        response.End();
    }
    //重写VerifyRenderingInServerForm方法,什么事也不干(也就是阻止系统调用默认的VerifyRenderingInServerForm方法)
    public override void VerifyRenderingInServerForm(Control control)
    {
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //文本:vnd.ms-excel.numberformat:@
        //日期:vnd.ms-excel.numberformat:yyyy/mm/dd
        //数字:vnd.ms-excel.numberformat::#,##0.00
        //货币:vnd.ms-excel.numberformat¥#,##0.00
        //百分比:vnd.ms-excel.numberformat:#0.00%
        for (int i = 0; i < e.Row.Cells.Count; i++)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //表示对每一行以字符串的形式输出
                e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
            }
        }
    }
    #endregion --------------------编程问答-------------------- 打开EXCEL模板,遍历赋值到单元格
--------------------编程问答-------------------- 什么意思  --------------------编程问答-------------------- 我的更怪,同样的Buton事件调用方法,TOEXCEL(Gridview1),有的页面可以直接下载的就是EXCEL,有的就是.ASPX,但是如果保存时在迅雷中选使用IE下载后就能下到EXCEL,我都想不通了。 --------------------编程问答-------------------- 楼主问题解决了吗?分享一下 --------------------编程问答-------------------- http://blog.csdn.net/hongchawendu/article/details/7387535 --------------------编程问答-------------------- 用NPOI吧亲 --------------------编程问答-------------------- 我也碰到了  楼主解决了吗 --------------------编程问答--------------------
引用 7 楼 hjywyj 的回复:
http://blog.csdn.net/hongchawendu/article/details/7387535
++ --------------------编程问答-------------------- --------------------编程问答--------------------
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,