Created
March 1, 2012 13:10
-
-
Save tuxdna/1949731 to your computer and use it in GitHub Desktop.
Convert a spreadsheet contents into Trac Wiki format
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/bin/ruby | |
# Convert a spreadsheet contents into Trac Wiki format | |
# How to use? | |
# sudo gem install spreadsheet | |
# ruby tracwiki.rb /path/to/spreadsheet.xls "sheet-name" | |
# | |
require 'rubygems' | |
require 'spreadsheet' | |
xlsfile = ARGV[0] if ARGV.length > 0 | |
sheetname = ARGV[1] if ARGV.length > 1 | |
exit unless xlsfile | |
book = Spreadsheet.open xlsfile | |
sheet1 = book.worksheet sheetname | |
sheet1.each_with_index do |r,i| | |
s = nil | |
if i==0 | |
then | |
s = "||"+r.map do |k| | |
"'''#{k}'''" | |
end.join("||")+"||" | |
else | |
s= "||"+r.map do |k| | |
if k.is_a?(Float) | |
k = k.to_i | |
else | |
k | |
end | |
end.join("||")+"||" | |
end | |
puts s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great - thanks.
However, I was having problems with empty cells, so I added the following where you were testing for Float
and that seemed to do the trick.