Thursday, April 30, 2009

Converting CSV file to HTML file by using VIM

I wrote a small VIM script to convert CSV file to HTML file.

You can get it from

Usage is : vim -s csvtohtml.vim <filename>

After running the above command, the file will contain html code in place of CSV. This script will not work, if there are new lines or commas in any cell.

First row will be taken as header, and the color for that is ff80ff. For all the remaining rows, the color would be changed alternatively (b0ffff and ffff80). You can change the corresponding colors in the script (for bgcolor in tr tag), and the html would be created with the colors given.

Contents of csvtohtml.vim

:%s/<tr>/<tr bgcolor="#b0ffff">/
:%s/<tr>/<tr bgcolor="#ffff80">/
:1 s/bgcolor="[^"]*"/bgcolor="#ff80ff"/
:1 s/^/<table>\r/
:$ s/$/\r<\/table>/

I have used the above script to create the tables for MLA and MP Contestants at and

1 comment:

  1. hi dear!!!!!!!!!!!
    you can easily convert the CSV data into the HTML using the