February 5th, 2012
CSV File to HTML Table

The tool found on the following page can be used to convert a Comma Separated Variable (CSV) file into an HTML table. The tool also provides simple formatting options which will produce CSS style code that can be used as is or modified for more complex formatting. After specifying your CSV file to be converted, you will have the option to either preview the generated table or download the HTML code. The generated code can be included on your SiteSpinner page via a Code Object.

The first line of a CSV file often contains text which describes the contents of each field, but this is not a requirement. The conversion tool provides an option to use the first line as table headings if your CSV file is formatted this way

The PHP routine used to read the CSV file does not make any assumptions about the file contents, so data items such as money ($1,399.99) or names (Last Name,First Name) that contain commas could cause the script to create more table cells than necessary. To compensate for this, an option is provided for you to specify a different delimiter (separator) character. Another option is to surround the data containing a comma with double-quotes; e.g., $1,399.99 becomes "1,399.99" and Flintstone,Fred would be "Flintstone,Fred". The double-quote method is often used by spreadsheet programs. If your data contains a single-quote or apostrophe, it must be enclosed by double-quotes; for example, Harry's Hot Dog Stand becomes "Harry's Hot Dog Stand".

Use The Tool

CSV Files

If you are unfamiliar with CSV files, they are plain text files that contain data which are separated by a common delimiter, usually a comma. For example, if I want to maintain an inventory of all the fruit in my home, I could create a text file such as:

Fruit Name,Qty,Purchase Date,Location
Apples,5,1/1/2008,refrigerator fruit drawer
Oranges,6,12/24/2007,dining room fruit bowl
Bananas,3,1/3/2008,dining room fruit bowl
Cherries,0,1/3/2008,
...