Avatar of Steynsk
Steynsk
Flag for Netherlands asked on

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

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

Response.Buffer=true

'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/vnd.ms-excel"
'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%">
<tr>
    <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>      
</tr>
<%Do While Not RS.eof%>
<tr>
            <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>
</tr>
<%

loopCounter = loopCounter + 1

if loopCounter = 1000 then
      Response.Flush
      loopCounter = 0      

end if

RS.Movenext
Loop
%>
</table>
<%
RS.Close
CS.Close
 
Set CS = Nothing
Set RS = Nothing
%>

---------------------end of code--------------------
ASP

Avatar of undefined
Last Comment
Steynsk

8/22/2022 - Mon
SOLUTION
arodrigues

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Bardobrave

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Steynsk

ASKER
Thanks
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23