Skip to content

Instantly share code, notes, and snippets.

@straightjacket
Forked from tuxdna/tracwiki.rb
Created November 14, 2013 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save straightjacket/7473043 to your computer and use it in GitHub Desktop.
Save straightjacket/7473043 to your computer and use it in GitHub Desktop.
#!/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