From 00773dc55bba72de66dac74f549bb1a22bfa5c45 Mon Sep 17 00:00:00 2001 From: sonota88 Date: Sun, 24 May 2020 22:17:57 +0900 Subject: [PATCH] Refactor for fods (ODF flat XML) file support --- lib/roo/open_office.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/roo/open_office.rb b/lib/roo/open_office.rb index f172363c..0dd5cf28 100644 --- a/lib/roo/open_office.rb +++ b/lib/roo/open_office.rb @@ -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 @@ -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 @@ -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' @@ -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')