Created
June 30, 2009 22:07
-
-
Save chaserx/138469 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/ruby | |
require "rubygems" | |
require "fastercsv" | |
require "html/table" | |
include HTML | |
# new file | |
outfile = File.open("outfile.html", "w") | |
# Create a new table | |
# Explicit syntax | |
table = HTML::Table.new{ |t| | |
t.border = 1 | |
t.cellpadding = 5 | |
t.cellspacing = 0 | |
} | |
# setup this variable for the loop | |
header_row = false | |
# open and loop thru each line of the CSV file | |
FasterCSV.foreach("memberlist.csv") do |row| | |
# use row here... | |
# push each row into the table | |
if header_row | |
table.push Table::Row.new{ |r| | |
r.content = row | |
} | |
else | |
new_header = Table::Row.new | |
row.each { |e| | |
temp = Table::Row::Header.new(e) | |
new_header.push temp | |
} | |
table.push new_header | |
# set header_row so that the loop executes the if statement not the else | |
header_row = true | |
end | |
end | |
# send formatted table into the outfile | |
outfile << table.html | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment