roo-rb / roo

Roo provides an interface to spreadsheets of several sorts.
MIT License
2.78k stars 503 forks source link

Refactoring to make fods (ODF Flat XML) file support easier #537

Open sonota88 opened 4 years ago

sonota88 commented 4 years ago

Summary

By this PR, users will be able to read fods files by creating a class that extends the LibreOffice or OpenOffice class as follows.

module Roo
  class LibreOfficeFlatXml < LibreOffice
    def supported_extension
      '.fods'
    end

    def open_oo_file(options)
      roo_content_xml_path = ::File.join(@tmpdir, 'roo_content.xml')
      FileUtils.cp @filename, roo_content_xml_path
    end

    # Unlike content.xml in ods files, fods files contain line breaks,
    # so text nodes need to be excluded.
    def cell_elements(table_element)
      table_element.children
        .reject { |child| child.is_a? Nokogiri::XML::Text }
    end
  end
end

Originally I wanted to support reading ODF Flat XML, but limited the changes to the bare minimum to avoid big PR. As you can see, these changes are simple refactorings, so these changes obviously don't break any tests.

Other Information

Nothing in particular.

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.01%) to 94.348% when pulling 00773dc55bba72de66dac74f549bb1a22bfa5c45 on sonota88:refactor_for_fods into d416f1520c50bbab160ca2ed9a49498fcc3edf50 on roo-rb:master.

simonoff commented 4 years ago

@sonota88 I think will be better to create also a Libreoffice class too.

paddor commented 6 months ago

What's the status here? I'd highly appreciate FODS support.