Problems converting CSV data to HTML table

Posted on 2011-09-20
Last Modified: 2012-05-12
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. .  I have attached the CSV data file.

<title> to HTML)</title>
<body bgcolor="#FFFFFF">
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 the top line by comma

'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

'Split the file up by comma

'Count the number of splits 
'This will be the numer of cells in the table
<table width="100%">
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>
'Reset the counter
' 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) 
next ' end of the observation 
<% next 'end of the csv %>

Open in new window

Question by:smith2001ja
  • 2
LVL 22

Expert Comment

by:Kim Walker
ID: 36567436
What is the source of your .csv file? Line 11 should be converting your line breaks to commas but doesn't appear to be doing so. Your file may have new lines chr(10) but no carriage returns chr(13). Try changing line 11 to replace new lines.

imported_text = replace(imported_text,chr(10),",")

Open in new window


Author Comment

ID: 36568381
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?
LVL 22

Accepted Solution

Kim Walker earned 500 total points
ID: 36568473
I just noticed a redundancy. Line 11 is apparently for the header row only. Try doing the same thing to line 27.

I have confirmed that the lines end with a new line instead of a carriage return.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML and CSS for a complex page 20 57
wordpress url rewriting plugin 5 45
Centering a nested div 16 58
FIELDSETs and LEGENDs in email markup 1 11
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now