Skip to content

Commit

Permalink
Merge pull request roo-rb#320 from orhantoy/feature/parse-ods-sheets-…
Browse files Browse the repository at this point in the history
…once

Parse sheets in ODS files once (to improve performance)
  • Loading branch information
stevendaniels authored Jun 19, 2016
2 parents 211f89b + 31fb15c commit 63ad941
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/roo/open_office.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ def initialize(filename, options = {})
open_oo_file(options)
super(filename, options)
initialize_default_variables

unless @table_display.any?
doc.xpath(XPATH_FIND_TABLE_STYLES).each do |style|
read_table_styles(style)
end
end

@sheet_names = doc.xpath(XPATH_LOCAL_NAME_TABLE).map do |sheet|
if !@only_visible_sheets || @table_display[attribute(sheet, 'style-name')]
sheet.attributes['name'].value
end
end.compact
rescue => e # clean up any temp files, but only if an error was raised
close
raise e
Expand Down Expand Up @@ -132,16 +144,7 @@ def celltype(row, col, sheet = nil)
end

def sheets
unless @table_display.any?
doc.xpath(XPATH_FIND_TABLE_STYLES).each do |style|
read_table_styles(style)
end
end
doc.xpath(XPATH_LOCAL_NAME_TABLE).map do |sheet|
if !@only_visible_sheets || @table_display[attribute(sheet, 'style-name')]
sheet.attributes['name'].value
end
end.compact
@sheet_names
end

# version of the Roo::OpenOffice document
Expand Down

0 comments on commit 63ad941

Please sign in to comment.