D
dillardrm
I am using OWC to generate an excel file. The excel file is saved on
the web server and is subsequently streamed to the browser via the
ADODB.Stream object. For some reason, the file is being saved
correctly on the server, but is not displaying in the browser. I get
an empty spreadsheet. Does anyone have any ideas?
Thanks,
Robby
The code is as follows:
'Write out spreadsheat
objExcel.GenerateWorksheet()
fPath = FILEPATHNAME & Session("UserId")
fName = fPath & "\" & Session("UserId") & year(now()) & month(now())
& day(now()) & hour(now()) & Minute(now()) & second(now()) & ".xls"
'If possible, save out worksheet and open it
If objExcel.SaveWorksheet(fName) then
'clear the buffer
Response.Buffer = True
Response.Clear
'Create stream
Set s = Server.CreateObject("ADODB.Stream")
s.Open
'Set data stream type to binary
s.Type = 1
'make sure file exists
set fs=Server.CreateObject("Scripting.FileSystemObject")
if not fs.FileExists(fName) then
Response.Write("<h1>Error: </h1>" & fName & " does not
exist<p>")
Response.End
end if
'get length of file
Set f = fs.GetFile(fName)
intFilelength = f.size
s.LoadFromFile(fName)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
Response.End
end if
'send the headers to the browser
Response.AddHeader "Roadmap","attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/vnd.ms-excel"
'output the file to the brower
Response.BinaryWrite s.Read
Response.Flush
'Clean up
s.Close
Set s = nothing
Else
%>
<b>Error in saving worksheet!</b>
<%
End If
the web server and is subsequently streamed to the browser via the
ADODB.Stream object. For some reason, the file is being saved
correctly on the server, but is not displaying in the browser. I get
an empty spreadsheet. Does anyone have any ideas?
Thanks,
Robby
The code is as follows:
'Write out spreadsheat
objExcel.GenerateWorksheet()
fPath = FILEPATHNAME & Session("UserId")
fName = fPath & "\" & Session("UserId") & year(now()) & month(now())
& day(now()) & hour(now()) & Minute(now()) & second(now()) & ".xls"
'If possible, save out worksheet and open it
If objExcel.SaveWorksheet(fName) then
'clear the buffer
Response.Buffer = True
Response.Clear
'Create stream
Set s = Server.CreateObject("ADODB.Stream")
s.Open
'Set data stream type to binary
s.Type = 1
'make sure file exists
set fs=Server.CreateObject("Scripting.FileSystemObject")
if not fs.FileExists(fName) then
Response.Write("<h1>Error: </h1>" & fName & " does not
exist<p>")
Response.End
end if
'get length of file
Set f = fs.GetFile(fName)
intFilelength = f.size
s.LoadFromFile(fName)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
Response.End
end if
'send the headers to the browser
Response.AddHeader "Roadmap","attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/vnd.ms-excel"
'output the file to the brower
Response.BinaryWrite s.Read
Response.Flush
'Clean up
s.Close
Set s = nothing
Else
%>
<b>Error in saving worksheet!</b>
<%
End If