smith2001ja
asked on
Problems converting CSV data to HTML table
I have a CSV file that is populated by an HTLM form. I have been looking for some kind of script that I can use to import this comma delimited data into an HTML table. I found a sample program on the Internet, but it has problems. Can you tell me what is wrong with this code? It reads the first line of the CSV data and creates the column headers. It reads the second line and puts it into the table, but it puts the Email from the second line and the date from the third line under the Email column. It puts the remainder of the third line under the wrong columns because it already used the date on the second row. It only reads part of the third line of data. This is the URL, if you want to look at the results.
http://ww2.nscc.edu/smith_judy/csvconverter.asp . I have attached the CSV data file.
Thanks,
Judy
formdata.csv
http://ww2.nscc.edu/smith_judy/csvconverter.asp . I have attached the CSV data file.
Thanks,
Judy
formdata.csv
<title>CodeAve.com(CSV to HTML)</title>
<body bgcolor="#FFFFFF">
<%
csv_to_read="formdata.csv"
set fso = createobject("scripting.filesystemobject")
set act = fso.opentextfile(server.mappath(csv_to_read))
imported_text = act.readline
'Read the first line of the csv, typically these are colum headings
imported_text = replace(imported_text,chr(13),",")
'Change the line breaks to commas to delimit through-out
imported_text = replace(imported_text,chr(34),"")
'Remove al quotes (If your csv has quotes other than to seperate text
'You may want to remove this modifier to the imported text
split_text=split(imported_text,",")
'Split the top line by comma
num_imported=ubound(split_text)+1
'Count the number of splits and add one for the last element
total_imported_text = act.readall
'Read the rest of the csv
total_imported_text = replace(total_imported_text,chr(13),",")
'Change the line breaks to commas to delimit through-out
total_imported_text = replace(total_imported_text,chr(34),"")
'Remove al quotes (If your csv has quotes other than to seperate text
'You may want to remove this modifier to the imported text
total_split_text=split(total_imported_text,",")
'Split the file up by comma
total_num_imported=ubound(total_split_text)
'Count the number of splits
'This will be the numer of cells in the table
%>
<table width="100%">
<tr>
<%
for table = 0 to num_imported -1
'This will create a table cell for each column in the csv
' (-1 is used because arrays begin with 0)
%>
<td width="<% response.write 100/(num_imported) 'make the cell widths even %>%">
<b><%= split_text(count) %></b>
</td>
<%
count=count+1
next
%>
</tr>
<tr>
<%
'Reset the counter
count=0
' This will determine how many rows are in the csv
for tablea = 0 to (total_num_imported/ (num_imported)-1)
%>
<%
for table = 0 to num_imported -1
'This will create a table cell for each column in the csv
' (-1 is used because arrays begin with 0)
%><td width="<%= 100/(num_imported) %>%">
<%= total_split_text(count)
%>
</td>
<%
count=count+1
next ' end of the observation
%></tr>
<% next 'end of the csv %>
</table>
ASKER
The source of my CSV file is the attached formdata.csv. Formdata.csv is generated by an HTML web form. I made the change you suggested and I am still getting the same results. What next?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window