Created
September 12, 2010 03:19
-
-
Save mourdok/575805 to your computer and use it in GitHub Desktop.
Simple Xls to Html Converter
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
# To use this application, you need to install the following and specify RubyGem | |
# >> sudo gem install roo -v 1.3.11 | |
# Which should return something like | |
# >> Successfully installed ruby-ole-1.2.10.1 | |
# >> Successfully installed spreadsheet-0.6.4.1 | |
# >> Successfully installed GData-0.0.4 | |
# >> Successfully installed roo-1.3.11 | |
# >> 4 gems installed | |
# So here we have our basic class | |
require "rubygems" | |
require "roo" | |
class SimpleXls2HtmlConverter | |
def initialize(file = "", default_sheet = 0) | |
@spreadsheet = Excel.new(file) | |
@spreadsheet.default_sheet = @spreadsheet.sheets[default_sheet] | |
end | |
def converts_column(column_name = "A") | |
lines_converted = [] | |
(@spreadsheet.first_row).upto(@spreadsheet.last_row) do |line| | |
lines_converted << @spreadsheet.cell(column_name, line).to_s.gsub("\n", "<br/>") | |
end | |
lines_converted | |
end | |
def object | |
@spreadsheet | |
end | |
end | |
# And here the implementation of this class | |
spreadsheet = SimpleXls2HtmlConverter.new("base.xls") | |
puts spreadsheet.object.info | |
puts spreadsheet.converts_column | |
puts spreadsheet.converts_column("B") | |
puts spreadsheet.converts_column("C") | |
# More information | |
# Visit: http://github.com/hmcgowan/roo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks,I can use online tool to convert excel to html:https://tableconvert.com/