首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

导入excel 关联了迅雷,该怎么解决

2012-04-15 
导入excel 关联了迅雷在网上搜了, 然后也看了论坛一些其他的说法, 说是在一个新的页面打开, 可是为什么我

导入excel 关联了迅雷
在网上搜了, 然后也看了论坛一些其他的说法, 说是在一个新的页面打开, 可是为什么我在一个新的页面输出,迅雷下载的还是网页呢? 我的代码问题?

C# code
    public double zhk = 1;    List<Product> pros = new List<Product>();    protected void Page_Load(object sender, EventArgs e)    {            string vastr = Request["vastr"].ToString();            List<Product> prosd = new List<Product>();            if (vastr != "")            {                string[] ids = vastr.Split(',');                for (int i = 0; i < ids.Length; i++)                {                    List<Product> pros = ProductService.GetAllProductById(ids[i].ToString());                    if (pros.Count > 0)                    {                        Product pro = pros[0];                        prosd.Add(pro);                    }                }                ExportGridToExcel(prosd, "upxia.xls");            }            else            {                Response.Write("<script>alert('请选择您要导出的数据!');location='prozhan.aspx'</script>");            }            }    private void ExportGridToExcel(List<Product> pros, string filename)    {        // 检查是否有文件名        if (string.IsNullOrEmpty(filename))        {            throw new ArgumentException("Export filename is required");        }        // 检查是否是excel格式        if (!filename.EndsWith(".xls"))        {            filename += ".xls";        }        StringWriter tw = new StringWriter();        HtmlTextWriter hw = new HtmlTextWriter(tw);        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");        //Response.Clear();        //Response.ContentType = "application/vnd.ms-excel";        Response.AddHeader("content-disposition", "attachment;filename=" + filename);        //Response.Charset = string.Empty;        //Page.EnableViewState = false;        //grid.RenderControl(hw);        writeEc ec = new writeEc();        hw.Write(ec.getEXCEL(pros, zhk));        Response.Write(tw.ToString());        Response.End();    }

希望各位大大能帮我解决哈!

[解决办法]
关注!
[解决办法]
因为是动态下载,下载页面可能是 *.aspx 迅雷只能捕获到aspx,而无法知道这个页面下载什么内容.
可以尝试先将*.aspx中将要下载的内容写入一个临时文件夹,然后 客户端重定向到临时文件
[解决办法]
TRY
Response.ContentType = "application/vnd.ms-excel";
===>
Response.ContentType = "application/octet-stream";

Response.Write(tw.ToString());
===>
把要下在的文件轉換成流
byte[] buffer = new byte[10240];
Response.OutputStream.Write(buffer,0,流的長度)
[解决办法]
关注一下
[解决办法]
接分.....
[解决办法]
接分..... 
 

[解决办法]
你输出在页面上,下载的当然是页面了,你必须把这个EXCEL文件的地址做成一个链接

点链接下载这个文件才行!

[解决办法]
接分。。。
[解决办法]
学习一下

热点排行
Bad Request.