lib/roo/openoffice.rb in roo-1.9.5 vs lib/roo/openoffice.rb in roo-1.9.6
- old
+ new
@@ -13,45 +13,38 @@
# initialization and opening of a spreadsheet file
# values for packed: :zip
def initialize(filename, packed=nil, file_warning=:error, tmpdir=nil) #, create = false)
@file_warning = file_warning
super()
- @tmpdir = "oo_"+$$.to_s
+ file_type_check(filename,'.ods','an openoffice', packed)
+ @tmpdir = GenericSpreadsheet.next_tmpdir
@tmpdir = File.join(ENV['ROO_TMP'], @tmpdir) if ENV['ROO_TMP']
@tmpdir = File.join(tmpdir, @tmpdir) if tmpdir
unless File.exists?(@tmpdir)
FileUtils::mkdir(@tmpdir)
end
filename = open_from_uri(filename) if filename[0,7] == "http://"
filename = unzip(filename) if packed and packed == :zip
- begin
- begin
- file_type_check(filename,'.ods','an openoffice')
- rescue TypeError
- FileUtils::rm_r @tmpdir
- raise
- end
- #if create and ! File.exists?(filename)
- # self.create_openoffice(filename)
- #end
- @cells_read = Hash.new
- #TODO: @cells_read[:default] = false
- @filename = filename
- unless File.file?(@filename)
- raise IOError, "file #{@filename} does not exist"
- end
- @@nr += 1
- @file_nr = @@nr
- extract_content
- file = File.new(File.join(@tmpdir, @file_nr.to_s+"_roo_content.xml"))
- @doc = Nokogiri::XML(file)
- file.close
- ensure
- unless Dir.glob(@tmpdir).empty?
+ #if create and ! File.exists?(filename)
+ # self.create_openoffice(filename)
+ #end
+ @cells_read = Hash.new
+ #TODO: @cells_read[:default] = false
+ @filename = filename
+ unless File.file?(@filename)
FileUtils::rm_r(@tmpdir)
- end
+ raise IOError, "file #{@filename} does not exist"
end
+ @@nr += 1
+ @file_nr = @@nr
+ extract_content
+ file = File.new(File.join(@tmpdir, @file_nr.to_s+"_roo_content.xml"))
+ @doc = Nokogiri::XML(file)
+ file.close
+ #unless Dir.glob(@tmpdir).empty?
+ FileUtils::rm_r(@tmpdir)
+ #end
@default_sheet = self.sheets.first
@cell = Hash.new
@cell_type = Hash.new
@formula = Hash.new
@first_row = Hash.new
@@ -499,5 +492,9 @@
}
result
end
end # class
+
+# Libreoffice is just an alias for Openoffice class
+class Libreoffice < Openoffice
+end