Module: RubyXL::CellConvenienceMethods

Included in:
Cell
Defined in:
lib/rubyXL/convenience_methods.rb

Instance Method Summary collapse

Instance Method Details

#change_border(direction, weight) ⇒ Object



676
677
678
679
# File 'lib/rubyXL/convenience_methods.rb', line 676

def change_border(direction, weight)
  validate_worksheet
  self.style_index = workbook.modify_border(self.style_index, direction, weight)
end

#change_contents(data, formula_expression = nil) ⇒ Object



638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
# File 'lib/rubyXL/convenience_methods.rb', line 638

def change_contents(data, formula_expression = nil)
  validate_worksheet

  if formula_expression then
    self.datatype = nil
    self.formula = RubyXL::Formula.new(:expression => formula_expression)
  else
    self.datatype = case data
                    when Date, Numeric then nil
                    else RubyXL::DataType::RAW_STRING
                    end
  end

  data = workbook.date_to_num(data) if data.is_a?(Date)

  self.raw_value = data
end

#change_horizontal_alignment(alignment = 'center') ⇒ Object



661
662
663
664
# File 'lib/rubyXL/convenience_methods.rb', line 661

def change_horizontal_alignment(alignment = 'center')
  validate_worksheet
  self.style_index = workbook.modify_alignment(self.style_index) { |a| a.horizontal = alignment }
end

#change_text_wrap(wrap = false) ⇒ Object



671
672
673
674
# File 'lib/rubyXL/convenience_methods.rb', line 671

def change_text_wrap(wrap = false)
  validate_worksheet
  self.style_index = workbook.modify_alignment(self.style_index) { |a| a.wrap_text = wrap }
end

#change_vertical_alignment(alignment = 'center') ⇒ Object



666
667
668
669
# File 'lib/rubyXL/convenience_methods.rb', line 666

def change_vertical_alignment(alignment = 'center')
  validate_worksheet
  self.style_index = workbook.modify_alignment(self.style_index) { |a| a.vertical = alignment }
end

#fill_colorObject



716
717
718
719
# File 'lib/rubyXL/convenience_methods.rb', line 716

def fill_color()
  validate_worksheet
  return workbook.get_fill_color(get_cell_xf)
end

#font_colorObject



711
712
713
714
# File 'lib/rubyXL/convenience_methods.rb', line 711

def font_color()
  validate_worksheet
  get_cell_font.get_rgb_color || '000000'
end

#font_nameObject



701
702
703
704
# File 'lib/rubyXL/convenience_methods.rb', line 701

def font_name()
  validate_worksheet
  get_cell_font.get_name
end

#font_sizeObject



706
707
708
709
# File 'lib/rubyXL/convenience_methods.rb', line 706

def font_size()
  validate_worksheet
  get_cell_font.get_size
end

#get_border(direction) ⇒ Object



656
657
658
659
# File 'lib/rubyXL/convenience_methods.rb', line 656

def get_border(direction)
  validate_worksheet
  get_cell_border.get_edge_style(direction)
end

#horizontal_alignmentObject



721
722
723
724
725
726
# File 'lib/rubyXL/convenience_methods.rb', line 721

def horizontal_alignment()
  validate_worksheet
  xf_obj = get_cell_xf
  return nil if xf_obj.alignment.nil?
  xf_obj.alignment.horizontal
end

#is_boldedObject



686
687
688
689
# File 'lib/rubyXL/convenience_methods.rb', line 686

def is_bolded()
  validate_worksheet
  get_cell_font.is_bold
end

#is_italicizedObject



681
682
683
684
# File 'lib/rubyXL/convenience_methods.rb', line 681

def is_italicized()
  validate_worksheet
  get_cell_font.is_italic
end

#is_struckthroughObject



696
697
698
699
# File 'lib/rubyXL/convenience_methods.rb', line 696

def is_struckthrough()
  validate_worksheet
  get_cell_font.is_strikethrough
end

#is_underlinedObject



691
692
693
694
# File 'lib/rubyXL/convenience_methods.rb', line 691

def is_underlined()
  validate_worksheet
  get_cell_font.is_underlined
end

#set_number_format(format_code) ⇒ Object



742
743
744
745
746
747
# File 'lib/rubyXL/convenience_methods.rb', line 742

def set_number_format(format_code)
  new_xf = get_cell_xf.dup
  new_xf.num_fmt_id = workbook.stylesheet.register_number_format(format_code)
  new_xf.apply_number_format = true
  self.style_index = workbook.register_new_xf(new_xf)
end

#text_wrapObject



735
736
737
738
739
740
# File 'lib/rubyXL/convenience_methods.rb', line 735

def text_wrap()
  validate_worksheet
  xf_obj = get_cell_xf
  return nil if xf_obj.alignment.nil?
  xf_obj.alignment.wrap_text
end

#vertical_alignmentObject



728
729
730
731
732
733
# File 'lib/rubyXL/convenience_methods.rb', line 728

def vertical_alignment()
  validate_worksheet
  xf_obj = get_cell_xf
  return nil if xf_obj.alignment.nil?
  xf_obj.alignment.vertical
end