class RubyXL::OOXMLTopLevelObject
their own .xml
files in .xslx
zip container.
Extension class providing functionality for top-level OOXML objects that are represented by
def self.filepath
def self.filepath raise 'Subclass responsebility' end
def self.parse_file(dirpath)
=== Parameters
directory containing the unzipped contents of .xslx
Generates the top-level OOXML object by parsing its XML file from the temporary
def self.parse_file(dirpath) full_path = File.join(dirpath, filepath) return nil unless File.exist?(full_path) parse(File.open(full_path, 'r')) end
def self.set_namespaces(namespace_hash)
set_namespaces('xmlns' => 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
==== Examples
* +namespace_hash+ - Hash of namespaces in the form of "prefix" => "url"
=== Parameters
Sets the list of namespaces on this object to be added when writing out XML. Valid only on top-level objects.
def self.set_namespaces(namespace_hash) self.class_variable_set(:@@ooxml_namespaces, namespace_hash) end
def add_to_zip(zipfile)
=== Parameters
Saves the contents of the object as XML to respective location in .xslx zip container.
def add_to_zip(zipfile) xml_string = write_xml return if xml_string.empty? zipfile.get_output_stream(self.filepath) { |f| f << xml_string } end
def filepath
Prototype method. For top-level OOXML object, returns the path at which the current object's XML file
def filepath self.class.filepath end