Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Writing an xls file to the browser

Posted on 2005-03-04
3
Medium Priority
?
425 Views
Last Modified: 2012-05-05
I'm having trouble reading a file on the server, then writing the file to the browser.  I keep getting a file error in excel.  Here's what I'm currently doing:

<%
Response.buffer = TRUE
strFileName = Server.MapPath("../../securedocuments/myFile.xls")
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile(strFileName, 1, false)
Response.ContentType = "application/x-msexcel"
Response.AddHeader "Content-disposition", "attachment; filename=myFile.xls"

' loop and write
Dim strLine
Do While Not file.AtEndOfStream
      strLine = file.readline & vbcrlf
      Response.BinaryWrite strLine
Loop

' close everything
file.close
Set file = nothing
Set fs = nothing

Response.End
%>

If anyone has any ideas, please help! ;)

Thanks,

davidgkyk
0
Comment
Question by:davidgky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
nurbek earned 500 total points
ID: 13463362
maybe you need to read from excel file like that?

Dim excRS, excConn
Dim ConnStr

ConnStr = "Driver={Microsoft Excel Driver (*.xls)};DBQ=" & Server.MapPath("test.xls")

Set excConn = Server.CreateObject("ADODB.Connection")
excConn.Open ConnStr

Set excRS = excConn.Execute("SELECT * FROM [Sheet1$]")

If Not excRS.EOF Then
   excRS.MoveFirst
   Response.Write "<table border=""1"">"
   Response.Write("<tr bgcolor=#CCCCCC><td>ID</td><td>Ad</td><td>Soyad</td></tr>")
   Do Until excRS.EOF
      Response.Write "<tr>"
      Response.Write "<td>&nbsp;" & excRS("ID") & "</td>"
      Response.Write "<td>&nbsp;" & excRS("Name") & "</td>"
      Response.Write "<td>&nbsp;" & excRS("Surname") & "</td>"
      Response.Write "</tr>"
      excRS.MoveNext
   Loop
   Response.Write "</table>"
End If

Set excRS = Nothing
excConn.Close
Set excConn = Nothing
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question