Skip to content

Commit

Permalink
Refactor for fods (ODF flat XML) file support
Browse files Browse the repository at this point in the history
  • Loading branch information
sonota88 committed May 29, 2020
1 parent d416f15 commit 00773dc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/roo/open_office.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(filename, options = {})
file_warning = options[:file_warning] || :error

@only_visible_sheets = options[:only_visible_sheets]
file_type_check(filename, '.ods', 'an Roo::OpenOffice', file_warning, packed)
file_type_check(filename, supported_extension, 'an Roo::OpenOffice', file_warning, packed)
# NOTE: Create temp directory and allow Ruby to cleanup the temp directory
# when the object is garbage collected. Initially, the finalizer was
# created in the Roo::Tempdir module, but that led to a segfault
Expand Down Expand Up @@ -53,6 +53,10 @@ def initialize(filename, options = {})
raise
end

def supported_extension
'.ods'
end

def open_oo_file(options)
Zip::File.open(@filename) do |zip_file|
content_entry = zip_file.glob('content.xml').first
Expand Down Expand Up @@ -446,6 +450,10 @@ def set_cell_values(sheet, x, y, i, v, value_type, formula, table_cell, str_v, s
end
end

def cell_elements(table_element)
table_element.children
end

# read all cells in the selected sheet
#--
# the following construct means '4 blanks'
Expand All @@ -471,7 +479,7 @@ def read_cells(sheet = default_sheet)
skip_row = attribute(table_element, 'number-rows-repeated').to_s.to_i
row = row + skip_row - 1
end
table_element.children.each do |cell|
cell_elements(table_element).each do |cell|
skip_col = attribute(cell, 'number-columns-repeated')
formula = attribute(cell, 'formula')
value_type = attribute(cell, 'value-type')
Expand Down

0 comments on commit 00773dc

Please sign in to comment.