troubleshooting Question

How do I change the output file from xls to CSV?

Avatar of Steynsk
SteynskFlag for Netherlands asked on
5 Comments4 Solutions314 ViewsLast Modified:
Hi Experts,

We've got this well working script (see below) that produces an XLS file. But our results  exeed the limitations of the XLS format. That's wy I'm trying to write my output to CSV.

Can this be done by changing our current code or do I need complete other methode to make this work? And what sould be changed to get this working?

All help welcome

-----current code-----------------
<!--#INCLUDE FILE="connect.asp"-->
Server.ScriptTimeout = 600


'Declare some variables
dim RS, pid
Set RS = Server.CreateObject("ADODB.Recordset")
pid = Request.QueryString("pid")
sql = "SELECT * FROM mytable WHERE id= " & pid & " order by datum"
RS.Open sql, CS  
'This is the the code which tells the page to open Excel and give it the data to display
Response.ContentType = "application/"
'You can give the spreadsheet a name at the point its produced
Response.AddHeader "Content-Disposition", "attachment; filename="& pid&".xls"  

loopCounter = 0

Note that I have formatted the output header here to a dark blue background and white text
this will be reflected in the spreadsheet when its produced and you could extend this to your own tastes of course.
<table border="1" width="100%">
    <th  bgcolor="#FFFFFF"><font size="2">patientnummer</font></th>
    <th  bgcolor="#FFFFFF"><font size="2">datum/tijd</font></th>
    <th  bgcolor="#FFFFFF"><font size="2">bed</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">HF</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">RESP</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">SpO2</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">SpO2r</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">SpO2l</font></th>
    <th  bgcolor="#FFFFFF"><font size="2">tcpCO2</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">tcpO2</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">etCO2</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">NIBDs</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">NIBDm</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">NIBDd</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">ABPs</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">ABPm</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">ABPd</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">rSO2_1</font></th>
    <th  bgcolor="#FFFFFF"><font size="2">rSO2_2</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">rSO2_3</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">rSO2_4</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">Pols</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">dSPO2</font></th>
      <th  bgcolor="#FFFFFF"><font size="2">awRF</font></th>      
<%Do While Not RS.eof%>
            <td><font size="2"><%= RS("PID") %></font></td>
            <td><font size="2"><%= RS("datum") %></font></td>
            <td><font size="2"><%= RS("bed") %></font></td>
            <td><font size="2"><%= RS("HF") %></font></td>
            <td><font size="2"><%= RS("RESP") %></font></td>
            <td><font size="2"><%= RS("SpO2") %></font></td>
            <td><font size="2"><%= RS("SpO2r") %></font></td>
            <td><font size="2"><%= RS("SpO2l") %></font></td>
            <td><font size="2"><%= RS("tcpCO2") %></font></td>
            <td><font size="2"><%= RS("tcpO2") %></font></td>
            <td><font size="2"><%= RS("etCO2") %></font></td>
            <td><font size="2"><%= RS("NIBDs") %></font></td>
            <td><font size="2"><%= RS("NIBDm") %></font></td>
            <td><font size="2"><%= RS("NIBDd") %></font></td>
            <td><font size="2"><%= RS("ABPs") %></font></td>
            <td><font size="2"><%= RS("ABPm") %></font></td>
            <td><font size="2"><%= RS("ABPd") %></font></td>
            <td><font size="2"><%= RS("rSO2_1") %></font></td>
            <td><font size="2"><%= RS("rSO2_2") %></font></td>
            <td><font size="2"><%= RS("rSO2_3") %></font></td>
            <td><font size="2"><%= RS("rSO2_4") %></font></td>
            <td><font size="2"><%= RS("Pols") %></font></td>
            <td><font size="2"><%= RS("dSPO2") %></font></td>
            <td><font size="2"><%= RS("awRF") %></font></td>

loopCounter = loopCounter + 1

if loopCounter = 1000 then
      loopCounter = 0      

end if

Set CS = Nothing
Set RS = Nothing

---------------------end of code--------------------
Join our community to see this answer!
Unlock 4 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros