Class: Fastxl::Workbook
- Inherits:
-
Object
- Object
- Fastxl::Workbook
- Defined in:
- lib/fastxl/workbook.rb
Instance Method Summary collapse
- #append(sheet_name, sheet_content) ⇒ Object
- #delete(sheet_name) ⇒ Object
- #flush ⇒ Object
-
#initialize(xlsx) ⇒ Workbook
constructor
A new instance of Workbook.
- #prepend(sheet_name, sheet_content) ⇒ Object
- #sheets ⇒ Object
- #write(sheet_index, sheet_content) ⇒ Object
Constructor Details
#initialize(xlsx) ⇒ Workbook
Returns a new instance of Workbook.
2 3 4 5 6 |
# File 'lib/fastxl/workbook.rb', line 2 def initialize(xlsx) @xlsx = xlsx @modifications = {} @virtual_dom = {} end |
Instance Method Details
#append(sheet_name, sheet_content) ⇒ Object
16 17 |
# File 'lib/fastxl/workbook.rb', line 16 def append(sheet_name, sheet_content) end |
#delete(sheet_name) ⇒ Object
19 20 |
# File 'lib/fastxl/workbook.rb', line 19 def delete(sheet_name) end |
#flush ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fastxl/workbook.rb', line 22 def flush buffer = Zip::OutputStream.write_buffer do |out| document_paths = @virtual_dom.keys @xlsx.entries.each do |e| if document_paths.include?(e.name) document_path = e.name out.put_next_entry(document_path) out.write(sheet_content_to_xml(@virtual_dom[document_path])) else out.put_next_entry(e.name) out.write e.get_input_stream.read end end end buffer end |
#prepend(sheet_name, sheet_content) ⇒ Object
13 14 |
# File 'lib/fastxl/workbook.rb', line 13 def prepend(sheet_name, sheet_content) end |
#sheets ⇒ Object
8 9 10 11 |
# File 'lib/fastxl/workbook.rb', line 8 def sheets doc = xml_doc('xl/workbook.xml') doc.xpath('//xmlns:sheet').map { |t| t.attributes['name'].value } end |
#write(sheet_index, sheet_content) ⇒ Object
41 42 43 44 45 |
# File 'lib/fastxl/workbook.rb', line 41 def write(sheet_index, sheet_content) @virtual_dom.merge!({ "xl/worksheets/sheet#{sheet_index}.xml" => sheet_content }) end |