954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

html table to .csv

Does anyone know how to do this? I have tables that are generated from asp that i would like to allow clients to download to a .csv file to their pc.

Thanks

jjorgensen626
Junior Poster in Training
69 posts since Oct 2003
Reputation Points: 41
Solved Threads: 2
 

if you alter the same script that generate the tables, get rid of the and , get rid of all , replace all instances of with a tab, and replace all instances of wit ha line break, you have a properly formatted csv file (provided there are no tabs or line breaks in your data). You can then make a button that calls a script that generate the file for download.

Do you know how to create headers that force a download?

Arizona Web
Junior Poster
118 posts since Jun 2004
Reputation Points: 16
Solved Threads: 2
 

left.gifright.gifsmall.gifHome       small.gifNCL Facts and History       small.gifNCL Program       small.gif NCL Chapters       small.gif FAQ       small.gif Contact Information        small.gif My NCL  
<%=(userName.Fields.Item("Fname").Value)%>, here are your current hours loged:


Location
Activity
Job
Hours
Date
Comment
Edit

<% While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) %>
<%=(Recordset1.Fields.Item("location").Value)%>
<%=(Recordset1.Fields.Item("activity").Value)%>
<%=(Recordset1.Fields.Item("job").Value)%>
<%=(Recordset1.Fields.Item("hours").Value)%>
<%=(Recordset1.Fields.Item("dateAC").Value)%>
<%=(Recordset1.Fields.Item("info").Value)%>
" class="gray">EDIT

<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>


 

You may need Macromedia Flash Player
to view parts of this site. You may download it here. Copyright 2004, NCL Glendale. All rights reserved.
Support and development by PC Techies

Attachments table.jpg 209.84KB
jjorgensen626
Junior Poster in Training
69 posts since Oct 2003
Reputation Points: 41
Solved Threads: 2
 

Any Clues?

jjorgensen626
Junior Poster in Training
69 posts since Oct 2003
Reputation Points: 41
Solved Threads: 2
 

Hi jjorgensen626,

maybe I can help, but I have only done that in jsp-pages.

To export a table, I have a button, which opens a new jsp-Page, just call it excel.jsp. In excel.jsp I set the following values of the Response-object:

response.setContentType("application/binary");
response.setHeader("Content-Disposition", "attachment; filename=\""+ strFile +"\";");

Afterwards, I open the connection to the database, get the ResultSet and instead of writing it into a table, I use a OutputStream, which I get from the Response-Object:
OutputStream ostr = response.getOutputStream();


For every col I add a ";" after the colvalue, after every row I add a "\n" for a linebreak.

Resultset rs = dbcon.createStatement().executeQuery(query);
while (rs.next()){
ostr.write((rs.getString("col1")+";").toBytes());
ostr.write((rs.getString("col2")+";").toBytes());
ostr.write("\n".toBytes());
}
rs.close()........


Maybe this helps and you can change it so it works in asp, c#/.net.

best regards,
Moritz

Moritz
Newbie Poster
1 post since Sep 2004
Reputation Points: 10
Solved Threads: 0
 
DaveSW
Master Poster
769 posts since Jul 2004
Reputation Points: 54
Solved Threads: 20
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You