Class: BerkeleyLibrary::Util::ODS::Spreadsheet
- Inherits:
-
Object
- Object
- BerkeleyLibrary::Util::ODS::Spreadsheet
- Includes:
- Logging
- Defined in:
- lib/berkeley_library/util/ods/spreadsheet.rb
Instance Method Summary collapse
-
#add_table(name, protected: true) ⇒ BerkeleyLibrary::Util::ODS::XML::Table::Table
Adds a table ('worksheet') to the spreadsheet.
-
#auto_styles ⇒ BerkeleyLibrary::Util::ODS::XML::Office::AutomaticStyles
Gets the document styles.
-
#content ⇒ XML::ContentDoc
Returns the content document.
-
#manifest ⇒ XML::ManifestDoc
Returns the container manifest.
-
#styles ⇒ XML::StylesDoc
Returns the container styles.
-
#write_exploded_to(dir) ⇒ Array<String>
Writes this spreadsheet as an exploded set of pretty-printed XML files.
-
#write_to(out = nil) ⇒ Object
noinspection RubyYardReturnMatch.
-
#write_to_file(path) ⇒ Object
Writes to the specified file.
-
#write_to_stream(out) ⇒ Object
Writes to the specified output stream.
-
#write_to_string ⇒ Object
Writes to a new string.
Instance Method Details
#add_table(name, protected: true) ⇒ BerkeleyLibrary::Util::ODS::XML::Table::Table
Adds a table ('worksheet') to the spreadsheet.
22 23 24 |
# File 'lib/berkeley_library/util/ods/spreadsheet.rb', line 22 def add_table(name, protected: true) content.document_content.add_table(name, protected: protected) end |
#auto_styles ⇒ BerkeleyLibrary::Util::ODS::XML::Office::AutomaticStyles
Gets the document styles
53 54 55 |
# File 'lib/berkeley_library/util/ods/spreadsheet.rb', line 53 def auto_styles content.document_content.automatic_styles end |
#content ⇒ XML::ContentDoc
Returns the content document
31 32 33 |
# File 'lib/berkeley_library/util/ods/spreadsheet.rb', line 31 def content @content ||= XML::ContentDoc.new end |
#manifest ⇒ XML::ManifestDoc
Returns the container manifest
43 44 45 46 47 48 |
# File 'lib/berkeley_library/util/ods/spreadsheet.rb', line 43 def manifest @manifest ||= XML::ManifestDoc.new.tap do |mf_doc| manifest = mf_doc.manifest manifest_docs.each { |doc| manifest.add_entry_for(doc) } end end |
#styles ⇒ XML::StylesDoc
Returns the container styles
37 38 39 |
# File 'lib/berkeley_library/util/ods/spreadsheet.rb', line 37 def styles @styles ||= XML::StylesDoc.new end |
#write_exploded_to(dir) ⇒ Array<String>
Writes this spreadsheet as an exploded set of pretty-printed XML files. NOTE: OpenOffice itself and many other tools get confused by the extra text nodes in the pretty-printed files and won't read them properly; this method is mostly for debugging.
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/berkeley_library/util/ods/spreadsheet.rb', line 112 def write_exploded_to(dir) raise ArgumentError, "Not a directory: #{dir.inspect}" unless File.directory?(dir) [].tap do |files_written| each_document do |doc| output_path = write_exploded(doc, dir) files_written << File.absolute_path(output_path) logger.debug("Wrote #{files_written.last}") end end end |
#write_to ⇒ String #write_to(out) ⇒ Object #write_to(path) ⇒ Object
noinspection RubyYardReturnMatch
74 75 76 77 78 79 80 |
# File 'lib/berkeley_library/util/ods/spreadsheet.rb', line 74 def write_to(out = nil) return write_to_string unless out return write_to_stream(out) if io_like?(out) return write_exploded_to(out) if File.directory?(out) write_to_file(out) end |
#write_to_file(path) ⇒ Object
Writes to the specified file.
102 103 104 |
# File 'lib/berkeley_library/util/ods/spreadsheet.rb', line 102 def write_to_file(path) File.open(path, 'wb') { |f| write_to_stream(f) } end |
#write_to_stream(out) ⇒ Object
Writes to the specified output stream.
90 91 92 93 94 95 96 97 98 |
# File 'lib/berkeley_library/util/ods/spreadsheet.rb', line 90 def write_to_stream(out) zip64_orig = Zip.write_zip64_support begin Zip.write_zip64_support = true write_zipfile(out) ensure Zip.write_zip64_support = zip64_orig end end |
#write_to_string ⇒ Object
Writes to a new string.
83 84 85 86 |
# File 'lib/berkeley_library/util/ods/spreadsheet.rb', line 83 def write_to_string # noinspection RubyYardParamTypeMatch StringIO.new.tap { |out| write_to_stream(out) }.string end |