module RubyXL::WorkbookConvenienceMethods

Constants

SHEET_NAME_TEMPLATE

Public Instance Methods

[](ind) click to toggle source

Finds worksheet by its name or numerical index

# File lib/rubyXL/convenience_methods.rb, line 7
def [](ind)
  case ind
  when Integer then worksheets[ind]
  when String  then worksheets.find { |ws| ws.sheet_name == ind }
  end
end
add_worksheet(name = nil) click to toggle source

Create new simple worksheet and add it to the workbook worksheets

@param [String] The name for the new worksheet

# File lib/rubyXL/convenience_methods.rb, line 17
def add_worksheet(name = nil)
  if name.nil? then
    n = 0

    begin
      name = SHEET_NAME_TEMPLATE % (n += 1)
    end until self[name].nil?
  end

  new_worksheet = Worksheet.new(:workbook => self, :sheet_name => name)
  worksheets << new_worksheet
  new_worksheet
end
application() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 53
def application
  root.document_properties.application && root.document_properties.application.value
end
application=(v) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 57
def application=(v)
  root.document_properties.application ||= StringNode.new
  root.document_properties.application.value = v
end
appversion() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 62
def appversion
  root.document_properties.app_version && root.document_properties.app_version.value
end
appversion=(v) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 66
def appversion=(v)
  root.document_properties.app_version ||= StringNode.new
  root.document_properties.app_version.value = v
end
borders() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 115
def borders # Stylesheet should be pre-filled with defaults on initialize()
  stylesheet.borders
end
cell_xfs() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 103
def cell_xfs # Stylesheet should be pre-filled with defaults on initialize()
  stylesheet.cell_xfs
end
company() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 44
def company
  root.document_properties.company && root.document_properties.company.value
end
company=(v) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 48
def company=(v)
  root.document_properties.company ||= StringNode.new
  root.document_properties.company.value = v
end
created_at() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 87
def created_at
  root.core_properties.created_at
end
created_at=(v) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 91
def created_at=(v)
  root.core_properties.created_at = v
end
creator() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 71
def creator
  root.core_properties.creator
end
creator=(v) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 75
def creator=(v)
  root.core_properties.creator = v
end
date1904() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 35
def date1904
  workbook_properties && workbook_properties.date1904
end
date1904=(v) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 39
def date1904=(v)
  self.workbook_properties ||= RubyXL::WorkbookProperties.new
  workbook_properties.date1904 = v
end
each() { |i| ... } click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 31
def each
  worksheets.each{ |i| yield i }
end
fills() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 111
def fills # Stylesheet should be pre-filled with defaults on initialize()
  stylesheet.fills
end
fonts() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 107
def fonts # Stylesheet should be pre-filled with defaults on initialize()
  stylesheet.fonts
end
get_fill_color(xf) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 119
def get_fill_color(xf)
  fill = fills[xf.fill_id]
  pattern = fill && fill.pattern_fill
  color = pattern && pattern.fg_color
  color && color.rgb || 'ffffff'
end
modified_at() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 95
def modified_at
  root.core_properties.modified_at
end
modified_at=(v) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 99
def modified_at=(v)
  root.core_properties.modified_at = v
end
modifier() click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 79
def modifier
  root.core_properties.modifier
end
modifier=(v) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 83
def modifier=(v)
  root.core_properties.modifier = v
end
modify_alignment(style_index) { |alignment| ... } click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 151
def modify_alignment(style_index, &block)
  xf = cell_xfs[style_index || 0].dup
  xf.alignment ||= RubyXL::Alignment.new
  yield(xf.alignment)
  xf.apply_alignment = true

  register_new_xf(xf)
end
modify_border(style_index, direction, weight) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 168
def modify_border(style_index, direction, weight)
  xf = cell_xfs[style_index || 0].dup
  new_border = borders[xf.border_id || 0].dup
  new_border.set_edge_style(direction, weight)

  xf.border_id = borders.find_index { |x| x == new_border } # Reuse existing border, if it exists
  xf.border_id ||= borders.size # If this border has never existed before, add it to collection.
  borders[xf.border_id] = new_border
  xf.apply_border = true

  register_new_xf(xf)
end
modify_fill(style_index, rgb) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 160
def modify_fill(style_index, rgb)
  xf = cell_xfs[style_index || 0].dup
  new_fill = RubyXL::Fill.new(:pattern_fill =>
               RubyXL::PatternFill.new(:pattern_type => 'solid',
                                       :fg_color => RubyXL::Color.new(:rgb => rgb)))
  register_new_xf(register_new_fill(new_fill, xf))
end
register_new_fill(new_fill, old_xf) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 126
def register_new_fill(new_fill, old_xf)
  new_xf = old_xf.dup
  new_xf.apply_fill = true
  new_xf.fill_id = fills.find_index { |x| x == new_fill } # Reuse existing fill, if it exists
  new_xf.fill_id ||= fills.size # If this fill has never existed before, add it to collection.
  fills[new_xf.fill_id] = new_fill
  new_xf
end
register_new_font(new_font, old_xf) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 135
def register_new_font(new_font, old_xf)
  new_xf = old_xf.dup
  new_xf.font_id = fonts.find_index { |x| x == new_font } # Reuse existing font, if it exists
  new_xf.font_id ||= fonts.size # If this font has never existed before, add it to collection.
  fonts[new_xf.font_id] = new_font
  new_xf.apply_font = true
  new_xf
end
register_new_xf(new_xf) click to toggle source
# File lib/rubyXL/convenience_methods.rb, line 144
def register_new_xf(new_xf)
  new_xf_id = cell_xfs.find_index { |xf| xf == new_xf } # Reuse existing XF, if it exists
  new_xf_id ||= cell_xfs.size # If this XF has never existed before, add it to collection.
  cell_xfs[new_xf_id] = new_xf
  new_xf_id
end