Class: Osheet::XmlssWriter
- Inherits:
-
Object
- Object
- Osheet::XmlssWriter
- Defined in:
- lib/osheet/xmlss_writer.rb
Instance Attribute Summary collapse
-
#style_cache ⇒ Object
readonly
The writer maintains a set of used xmlss styles and handles creating xmlss style objects as needed and manages style keys.
-
#xmlss_workbook ⇒ Object
readonly
The writer maintains a set of used xmlss styles and handles creating xmlss style objects as needed and manages style keys.
Instance Method Summary collapse
- #bind(osheet_workbook) ⇒ Object
- #cell(cell, &build) ⇒ Object
- #colspan(count) ⇒ Object
- #column(column, &build) ⇒ Object
-
#initialize(*args, &block) ⇒ XmlssWriter
constructor
A new instance of XmlssWriter.
- #name(value) ⇒ Object
- #row(row, &build) ⇒ Object
- #rowspan(count) ⇒ Object
-
#style(style_class, format = nil) ⇒ Object
given an elements style_class or format attributes: 1) write a new xmlss style object and 2) set the current element’s style_id attribute.
- #to_file(file_path) ⇒ Object
- #to_s ⇒ Object (also: #to_data)
-
#worksheet(worksheet, &build) ⇒ Object
Element writers.
Constructor Details
#initialize(*args, &block) ⇒ XmlssWriter
Returns a new instance of XmlssWriter.
17 18 19 20 21 22 |
# File 'lib/osheet/xmlss_writer.rb', line 17 def initialize(*args, &block) @xmlss_workbook = ::Xmlss::Workbook.new(::Xmlss::Writer.new(*args, &block)) @osheet_workbook = nil @osheet_worksheet_names = [] @style_cache = nil end |
Instance Attribute Details
#style_cache ⇒ Object (readonly)
The writer maintains a set of used xmlss styles and handles creating xmlss style objects as needed and manages style keys
15 16 17 |
# File 'lib/osheet/xmlss_writer.rb', line 15 def style_cache @style_cache end |
#xmlss_workbook ⇒ Object (readonly)
The writer maintains a set of used xmlss styles and handles creating xmlss style objects as needed and manages style keys
15 16 17 |
# File 'lib/osheet/xmlss_writer.rb', line 15 def xmlss_workbook @xmlss_workbook end |
Instance Method Details
#bind(osheet_workbook) ⇒ Object
24 25 26 27 |
# File 'lib/osheet/xmlss_writer.rb', line 24 def bind(osheet_workbook) @osheet_workbook = osheet_workbook @style_cache = Osheet::Xmlss::StyleCache.new(@osheet_workbook, @xmlss_workbook) end |
#cell(cell, &build) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/osheet/xmlss_writer.rb', line 72 def cell(cell, &build) attrs = { :href => cell.href, :index => cell.index, :merge_across => cell_merge(cell.colspan), :merge_down => cell_merge(cell.rowspan), :formula => cell.formula } if s = @style_cache.get(cell.style_class, cell.format) attrs[:style_id] = s.id end @xmlss_workbook.cell(cell.data, attrs, &build) end |
#colspan(count) ⇒ Object
101 102 103 |
# File 'lib/osheet/xmlss_writer.rb', line 101 def colspan(count) @xmlss_workbook.merge_across(cell_merge(count)) end |
#column(column, &build) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/osheet/xmlss_writer.rb', line 48 def column(column, &build) attrs = { :width => column.width, :auto_fit_width => column.autofit, :hidden => column.hidden } if s = @style_cache.get(column.style_class, column.format) attrs[:style_id] = s.id end @xmlss_workbook.column(attrs, &build) end |
#name(value) ⇒ Object
109 110 111 112 113 |
# File 'lib/osheet/xmlss_writer.rb', line 109 def name(value) @osheet_worksheet_names.pop @osheet_worksheet_names << value @xmlss_workbook.name(value) end |
#row(row, &build) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/osheet/xmlss_writer.rb', line 60 def row(row, &build) attrs = { :height => row.height, :auto_fit_height => row.autofit, :hidden => row.hidden } if s = @style_cache.get(row.style_class, row.format) attrs[:style_id] = s.id end @xmlss_workbook.row(attrs, &build) end |
#rowspan(count) ⇒ Object
105 106 107 |
# File 'lib/osheet/xmlss_writer.rb', line 105 def rowspan(count) @xmlss_workbook.merge_down(cell_merge(count)) end |
#style(style_class, format = nil) ⇒ Object
given an elements style_class or format attributes: 1) write a new xmlss style object and 2) set the current element’s style_id attribute
92 93 94 95 96 97 98 99 |
# File 'lib/osheet/xmlss_writer.rb', line 92 def style(style_class, format=nil) xs = @style_cache.get( style_class, format || Osheet::Format.new(:general) ) @xmlss_workbook.style_id(xs.id) if xs xs end |
#to_file(file_path) ⇒ Object
34 35 36 |
# File 'lib/osheet/xmlss_writer.rb', line 34 def to_file(file_path) @xmlss_workbook.to_file(file_path) end |
#to_s ⇒ Object Also known as: to_data
29 30 31 |
# File 'lib/osheet/xmlss_writer.rb', line 29 def to_s @xmlss_workbook.to_s end |
#worksheet(worksheet, &build) ⇒ Object
Element writers
40 41 42 43 44 45 46 |
# File 'lib/osheet/xmlss_writer.rb', line 40 def worksheet(worksheet, &build) if @osheet_workbook && @osheet_worksheet_names.include?(worksheet.name.to_s) raise ArgumentError, "you can't write two worksheets with the same name ('#{worksheet.name}')" end @osheet_worksheet_names << worksheet.name.to_s @xmlss_workbook.worksheet(worksheet.name, &build) end |