class Osheet::XmlssWriter

Attributes

style_cache[R]

The writer maintains a set of used xmlss styles and handles creating xmlss style objects as needed and manages style keys

xmlss_workbook[R]

The writer maintains a set of used xmlss styles and handles creating xmlss style objects as needed and manages style keys

Public Class Methods

new(*args, &block) click to toggle source
# 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

Public Instance Methods

bind(osheet_workbook) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/osheet/xmlss_writer.rb, line 101
def colspan(count)
  @xmlss_workbook.merge_across(cell_merge(count))
end
column(column, &build) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/osheet/xmlss_writer.rb, line 105
def rowspan(count)
  @xmlss_workbook.merge_down(cell_merge(count))
end
style(style_class, format=nil) click to toggle source

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

# 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_data()
Alias for: to_s
to_file(file_path) click to toggle source
# File lib/osheet/xmlss_writer.rb, line 34
def to_file(file_path)
  @xmlss_workbook.to_file(file_path)
end
to_s() click to toggle source
# File lib/osheet/xmlss_writer.rb, line 29
def to_s
  @xmlss_workbook.to_s
end
Also aliased as: to_data
worksheet(worksheet, &build) click to toggle source

Element writers

# 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

Protected Instance Methods

cell_merge(span) click to toggle source

convert osheet col/row span value to xmlss merge value

# File lib/osheet/xmlss_writer.rb, line 136
def cell_merge(span)
  span.kind_of?(::Fixnum) && span > 1 ? span-1 : 0
end