Skip to content

Commit

Permalink
Pull out Roo::Excel, Excel2003XMl, and Google, to be provided in sepa…
Browse files Browse the repository at this point in the history
…rate libraries, roo-xls and roo-google.
  • Loading branch information
Empact committed Nov 17, 2014
1 parent 2d32906 commit a7edbec
Show file tree
Hide file tree
Showing 67 changed files with 123 additions and 89,805 deletions.
27 changes: 3 additions & 24 deletions Gemfile.lock
Expand Up @@ -13,29 +13,9 @@ GEM
crack (0.4.1)
safe_yaml (~> 0.9.0)
diff-lcs (1.2.5)
faraday (0.8.7)
multipart-post (~> 1.1)
google_drive (0.3.6)
nokogiri (>= 1.4.4, != 1.5.2, != 1.5.1)
oauth (>= 0.3.6)
oauth2 (>= 0.5.0)
httpauth (0.2.0)
jwt (0.1.8)
multi_json (>= 1.5)
multi_json (1.7.3)
multi_xml (0.5.3)
multipart-post (1.2.0)
nokogiri (1.5.6)
nokogiri (1.5.6-java)
oauth (0.4.7)
oauth2 (0.9.1)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
multi_xml (~> 0.5)
rack (~> 1.2)
rack (1.5.2)
mini_portile (0.5.2)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
rake (10.3.2)
rspec (2.14.1)
rspec-core (~> 2.14.0)
Expand Down Expand Up @@ -66,7 +46,6 @@ PLATFORMS

DEPENDENCIES
bundler (~> 1.7)
google_drive
rake (~> 10.0)
roo!
rspec (>= 2.14)
Expand Down
21 changes: 4 additions & 17 deletions README.markdown
Expand Up @@ -2,34 +2,21 @@

Roo implements read access for all spreadsheet types and read/write access for
Google spreadsheets. It can handle
* OpenOffice
* Excel
* Google spreadsheets
* Excelx
* LibreOffice
* OpenOffice / LibreOffice
* CSV

### XLS
## Additional libraries

There is no support for formulas in Roo for .xls files - you can get the result
of a formula but not the formula itself.

### Google Spreadsheet

Using Roo to access Google spreadsheets requires you install the 'google-spreadsheet-ruby' gem separately.

## License

While Roo is licensed under the MIT / Expat license, please note that the 'spreadsheet' gem [is released under](https://github.com/zdavatz/spreadsheet/blob/master/LICENSE.txt) the GPLv3 license.
In addition, the roo-xls and roo-google gems exist to Google Spreadsheet add classic Excel
handling capabilities to roo.

## Usage:

```ruby
require 'roo'

s = Roo::OpenOffice.new("myspreadsheet.ods") # loads an OpenOffice Spreadsheet
s = Roo::Excel.new("myspreadsheet.xls") # loads an Excel Spreadsheet
s = Roo::Google.new("myspreadsheetkey_at_google") # loads a Google Spreadsheet
s = Roo::Excelx.new("myspreadsheet.xlsx") # loads an Excel Spreadsheet for Excel .xlsx files
s = Roo::CSV.new("mycsv.csv") # loads a CSV file

Expand Down
22 changes: 19 additions & 3 deletions lib/roo.rb
@@ -1,12 +1,28 @@
module Roo
CLASS_FOR_EXTENSION = {
'.ods' => 'Roo::OpenOffice',
'.xlsx' => 'Roo::Excelx',
'.csv' => 'Roo::CSV'
}

def self.const_missing(const_name)
case const_name
when :Excel
raise "Excel support has been extracted to roo-xls due to its dependency on the GPL'd spreadsheet gem. Install roo-xls to use Roo::Excel."
when :Excel2003XML
raise "Excel SpreadsheetML support has been extracted to roo-xls. Install roo-xls to use Roo::Excel2003XML."
when :Google
raise "Google support has been extracted to roo-google. Install roo-google to use Roo::Google."
else
super
end
end

autoload :Spreadsheet, 'roo/spreadsheet'
autoload :Base, 'roo/base'

autoload :OpenOffice, 'roo/open_office'
autoload :LibreOffice, 'roo/libre_office'
autoload :Excel, 'roo/excel'
autoload :Excelx, 'roo/excelx'
autoload :Excel2003XML, 'roo/excel2003xml'
autoload :Google, 'roo/google'
autoload :CSV, 'roo/csv'
end
37 changes: 16 additions & 21 deletions lib/roo/base.rb
Expand Up @@ -2,15 +2,17 @@

require 'tmpdir'
require 'stringio'
require 'nokogiri'

begin
require 'zip/zipfilesystem'
Roo::ZipFile = Zip::ZipFile
rescue LoadError
# For rubyzip >= 1.0.0
require 'zip/filesystem'
Roo::ZipFile = Zip::File
end
Roo::ZipFile =
begin
require 'zip/zipfilesystem'
Zip::ZipFile
rescue LoadError
# For rubyzip >= 1.0.0
require 'zip/filesystem'
Zip::File
end

# Base class for all other types of spreadsheets
class Roo::Base
Expand Down Expand Up @@ -276,7 +278,7 @@ def row(rownumber,sheet=nil)
# column numbers are 1,2,3,... like in the spreadsheet
def column(columnnumber,sheet=nil)
if columnnumber.class == String
columnnumber = Roo::Excel.letter_to_number(columnnumber)
columnnumber = self.class.letter_to_number(columnnumber)
end
sheet ||= @default_sheet
read_cells(sheet)
Expand Down Expand Up @@ -499,22 +501,15 @@ def load_xml(path)
end

def file_type_check(filename, ext, name, warning_level, packed=nil)
new_expression = {
'.ods' => 'Roo::OpenOffice.new',
'.xls' => 'Roo::Excel.new',
'.xlsx' => 'Roo::Excelx.new',
'.csv' => 'Roo::CSV.new',
'.xml' => 'Roo::Excel2003XML.new',
}
if packed == :zip
# lalala.ods.zip => lalala.ods
# hier wird KEIN unzip gemacht, sondern nur der Name der Datei
# getestet, falls es eine gepackte Datei ist.
filename = File.basename(filename,File.extname(filename))
# lalala.ods.zip => lalala.ods
# hier wird KEIN unzip gemacht, sondern nur der Name der Datei
# getestet, falls es eine gepackte Datei ist.
filename = File.basename(filename,File.extname(filename))
end
case ext
when '.ods', '.xls', '.xlsx', '.csv', '.xml'
correct_class = "use #{new_expression[ext]} to handle #{ext} spreadsheet files. This has #{File.extname(filename).downcase}"
correct_class = "use #{Roo::CLASS_FOR_EXTENSION[ext]}.new to handle #{ext} spreadsheet files. This has #{File.extname(filename).downcase}"
else
raise "unknown file type: #{ext}"
end
Expand Down

0 comments on commit a7edbec

Please sign in to comment.