使用VB.Net在ASP.Net中下载Excel文件问题 [英] Downloading excel file issue in ASP.Net using VB.Net

查看:92
本文介绍了使用VB.Net在ASP.Net中下载Excel文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在编写代码以从某个位置下载Excel文件.代码如下:

Hi,

I am writing a code to download an excel file from a location. The code is as follows:

Select Case strFileType
            Case "txt" : Response.ContentType = "text/plain"
            Case "xls", "csv" : Response.ContentType = "application/x-msexcel"
            Case Else
                Response.ContentType = "application/octet-stream"
        End Select
Response.AddHeader("content-disposition", "inline; filename=" & ReportFileName) Response.TransmitFile(reportPhysPath & ReportFileName)
       Response.End()



我在 reportPhysPath 中传递文件服务器位置,要打开的文件名在 ReportFileName 中传递.

问题是:
当我下载excel文件时,它将在excel中打开文件,其名称为"Download.aspx",即写入文件下载功能的页面的名称. excel文件的名称应该已经显示.假设文件服务器中的文件名为"mike1.xls",则打开页面时的文件名也应为"mike.xls",而不是"Download.aspx"

当我尝试下载另一个文件(mike2.xls)并在Microsoft Office Excel 2007中已经打开了当前文件(mike1.xls)时,这会导致显示错误消息.该错误消息显示名称为"Download.aspx"的文件为已经打开.


请帮我解决这个问题.在此先感谢:)



I pass the file server location in reportPhysPath and the file-name to be opened is passed in ReportFileName.

The Issue is:
When I download an excel file, it opens the file in excel with a name of "Download.aspx" , i.e. the name of the page where the function for downloading the file is written. The name of the excel file should be have been displayed. Suppose the file name in the file server is "mike1.xls", the file name while opening the page should also be "mike.xls" instead of "Download.aspx"

This causes an error message displayed when I try to download another file(mike2.xls) with the current file(mike1.xls) already open in Microsoft Office Excel 2007. The error message says that a file with name "Download.aspx" is already open.


Please help me solve this. Thanks in Advance :)

推荐答案

Response.Clear()
            Response.Buffer = True
            Response.AddHeader("content-disposition", "attachment;filename=ClientPayFollowUp " & DrpClient.Text.ToString & ".xls")
            Response.Charset = ""
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Response.ContentType = "application/vnd.Excel"


这可能对您有帮助....


this may help you....


Devang Vaja,

我试图在我的Web应用程序中实现此代码. excel文件正在打开,但打开代码时的名称仍为"download.aspx".

能否请您告诉我是在直接在代码下载按钮后面的代码中还是在单独的网页代码后面的代码中实现了此代码.


谢谢!!!
Hi Devang Vaja,

I tried to implement this code in my web application. The excel file is opening but the name while opening the code is still "download.aspx".

Can you please tell me whether you implemented this code on the download button code-behind directly or in the code-behind of a seperate web page.


Thanks !!!


这篇关于使用VB.Net在ASP.Net中下载Excel文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆