|
 |
asptoday_discuss thread: Exporting ASP Reports to Excel Format
Message #1 by raymond.gonsalves@v... on Thu, 25 Apr 2002 23:41:15
|
|
Hello Everyone,
In David Schultz's article "Exporting ASP Reports to Excel Format" dated
Nov. 2nd 1999
He uses the line Response.ContentType = "application/msexcel" to send the
data from an ASP page to Excel.
My problem is as follows: When the save dialogbox prompts the user to save
the file it suggests the filename "theASPpostingpage.asp" as the file to
save and in the Save as File Type box it list "Active Server Page".
I would like it to suggest the filename to be "myfile.xls" so the users do
not accidently save the file as an *.asp file on their hard drive.
Any help would be greatly appreciated.
Ray Gonsalves
Rye, NY
Message #2 by Lawrence Yap <assoc_con@y...> on Fri, 26 Apr 2002 05:58:44 -0700 (PDT)
|
|
Hello Ray,
Try this. I am assuming that you have an .asp
page that calls a download page to perform the task
you're doing. This code resides in the download page
only. The variables here are arbitrary depending on
what you're getting from the QueryString:
<%
Response.Buffer = True
Dim strFilePath, strFileSize, strFileName
Const adTypeBinary = 1
strFilePath = Request.QueryString("File")
strFileSize = Request.QueryString("Size")
strFileName = Request.QueryString("Name")
Response.Clear
'8*******************************8
' Requires MDAC 2.5 to be stable
' I recommend MDAC 2.6
'8*******************************8
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = lcase(Right(strFileName, 4))
' Feel Free to Add Your Own Content-Types Here
Select Case strFileType
Case ".asf"
ContentType = "video/x-ms-asf"
Case ".avi"
ContentType = "video/avi"
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
Case ".gif"
ContentType = "image/gif"
Case ".jpg", "jpeg"
ContentType = "image/jpeg"
Case ".wav"
ContentType = "audio/wav"
Case ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "video/mpeg"
Case ".rtf"
ContentType = "application/rtf"
Case ".htm", "html"
ContentType = "text/html"
Case ".asp"
ContentType = "text/asp"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select
Response.AddHeader "Content-Disposition",
"attachment; filename=000" & strFileName
Response.AddHeader "Content-Length", strFileSize
' the filename here pertains your myFile.xxx, you can
leave this blank as well. 000 is just a prefix.
' In Their Browser
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
Response.End
%>
--- raymond.gonsalves@v... wrote:
> Hello Everyone,
>
> In David Schultz's article "Exporting ASP Reports to
> Excel Format" dated
> Nov. 2nd 1999
>
> He uses the line Response.ContentType
> "application/msexcel" to send the
> data from an ASP page to Excel.
>
> My problem is as follows: When the save dialogbox
> prompts the user to save
> the file it suggests the filename
> "theASPpostingpage.asp" as the file to
> save and in the Save as File Type box it list
> "Active Server Page".
>
> I would like it to suggest the filename to be
> "myfile.xls" so the users do
> not accidently save the file as an *.asp file on
> their hard drive.
>
> Any help would be greatly appreciated.
>
> Ray Gonsalves
> Rye, NY
__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/
|
|
 |