JavaScript - Grabbing contents of .csv file and displaying as a table

Asked By Jeremy Osinsi on 09-Jul-08 02:47 PM
Is there a way to grab the contents of a .csv file and show them as an HTML table? Alternatively, is there a way to convert the .csv file to an XML file? From there, I have a transform method that applies a stylesheet to display the data. Any help would be greatly appreciated. (I know there is that GridTable tool with sorting, etc., with the code floating around the Web but I would like the data just to display in table form.)

csv to xml - Partha Mandayam replied to Jeremy Osinsi on 09-Jul-08 03:06 PM

Here's  a free csv to xml converter

csv to xml - Jeremy Osinsi replied to Partha Mandayam on 09-Jul-08 09:46 PM


I've actually come across the Creativst converter. I think my situation is unique, where I need that conversion to happen automatically. We have an HTML form where data collects in a CSV file. I would like this CSV data displayed dynamically in an HTML table or in an XML file. (Our form servlet allows for a CSV reset when a button only viewable by authorized users is pushed.) While the site is built in HTML, I do have access to ASP and PHP servers.

Convert CSV File into HTML Table - alice johnson replied to Jeremy Osinsi on 09-Jul-08 10:04 PM

var src  = "sunw.csv";
var dest = "results.html";// The names of our input and output files
// Create some variables
var fso, fin, fout;
var data = new Array();
// Define constants for file access
var forReading   = 1;
var forWriting   = 2;
var forAppending = 8;
// Create File System Object and open input and output files
fso  = new ActiveXObject( "Scripting.FileSystemObject" );
fin  = fso.OpenTextFile( src, forReading );
fout = fso.OpenTextFile( dest, forWriting, true );
// Write out header and start of tablef
out.WriteLine( htmlHeader() );
fout.WriteLine( "<table border='0' cellpadding='1' cellspacing='0' width='100%'>" );
// Loop through entire file
while( !fin.AtEndOfStream )
// Read the next line
 var line = fin.ReadLine(); 
  // If line if blank - skip it 
if( line == "" )  
data = line.split( "," );
fout.WriteLine( "<tr>" );
for( i = 0; i < data.length; i++ )
fout.WriteLine( "<td>" + data[i] + "</td>" );
fout.WriteLine( "</tr>\r\n" );
catch( e )

WScript.Echo( "Error: " + e.description );
fout.WriteLine( "</table>" );
// Close HTML
fout.WriteLine( htmlFooter() );
// Close input and output file

Hello go through this link:

It will surely help you.

CSV to HTML - mv ark replied to Jeremy Osinsi on 10-Jul-08 03:00 AM
Generate an XML file in the background through ASP or PHP using a command line tool like one of these -
csv2xml -

To convert the generated XML file to a Html Table, you can use the Generic XSL stylesheet mentioned here -