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



883
884
885
886
# File 'lib/rubyXL/convenience_methods.rb', line 883

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

#change_border_color(direction, color) ⇒ Object



888
889
890
891
892
# File 'lib/rubyXL/convenience_methods.rb', line 888

def change_border_color(direction, color)
  validate_worksheet
  Color.validate_color(color)
  self.style_index = workbook.modify_border_color(self.style_index, direction, color)
end

#change_contents(data, formula_expression = nil) ⇒ Object



830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
# File 'lib/rubyXL/convenience_methods.rb', line 830

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_fill(rgb = 'ffffff') ⇒ Object

Changes fill color of cell



977
978
979
980
981
# File 'lib/rubyXL/convenience_methods.rb', line 977

def change_fill(rgb = 'ffffff')
  validate_worksheet
  Color.validate_color(rgb)
  self.style_index = workbook.modify_fill(self.style_index, rgb)
end

#change_font_bold(bolded = false) ⇒ Object

Changes font bold settings of cell



1022
1023
1024
1025
1026
1027
1028
# File 'lib/rubyXL/convenience_methods.rb', line 1022

def change_font_bold(bolded = false)
  validate_worksheet

  font = get_cell_font.dup
  font.set_bold(bolded)
  update_font_references(font)
end

#change_font_color(font_color = '000000') ⇒ Object

Changes font color of cell



1003
1004
1005
1006
1007
1008
1009
1010
# File 'lib/rubyXL/convenience_methods.rb', line 1003

def change_font_color(font_color = '000000')
  validate_worksheet
  Color.validate_color(font_color)

  font = get_cell_font.dup
  font.set_rgb_color(font_color)
  update_font_references(font)
end

#change_font_italics(italicized = false) ⇒ Object

Changes font italics settings of cell



1013
1014
1015
1016
1017
1018
1019
# File 'lib/rubyXL/convenience_methods.rb', line 1013

def change_font_italics(italicized = false)
  validate_worksheet

  font = get_cell_font.dup
  font.set_italic(italicized)
  update_font_references(font)
end

#change_font_name(new_font_name = 'Verdana') ⇒ Object

Changes font name of cell



984
985
986
987
988
989
990
# File 'lib/rubyXL/convenience_methods.rb', line 984

def change_font_name(new_font_name = 'Verdana')
  validate_worksheet

  font = get_cell_font.dup
  font.set_name(new_font_name)
  update_font_references(font)
end

#change_font_size(font_size = 10) ⇒ Object

Changes font size of cell



993
994
995
996
997
998
999
1000
# File 'lib/rubyXL/convenience_methods.rb', line 993

def change_font_size(font_size = 10)
  validate_worksheet
  raise 'Argument must be a number' unless font_size.is_a?(Integer) || font_size.is_a?(Float)

  font = get_cell_font.dup
  font.set_size(font_size)
  update_font_references(font)
end

#change_font_strikethrough(struckthrough = false) ⇒ Object



1039
1040
1041
1042
1043
1044
1045
# File 'lib/rubyXL/convenience_methods.rb', line 1039

def change_font_strikethrough(struckthrough = false)
  validate_worksheet

  font = get_cell_font.dup
  font.set_strikethrough(struckthrough)
  update_font_references(font)
end

#change_font_underline(underlined = false) ⇒ Object

Changes font underline settings of cell



1031
1032
1033
1034
1035
1036
1037
# File 'lib/rubyXL/convenience_methods.rb', line 1031

def change_font_underline(underlined = false)
  validate_worksheet

  font = get_cell_font.dup
  font.set_underline(underlined)
  update_font_references(font)
end

#change_horizontal_alignment(alignment = 'center') ⇒ Object



858
859
860
861
# File 'lib/rubyXL/convenience_methods.rb', line 858

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

#change_text_indent(indent) ⇒ Object



878
879
880
881
# File 'lib/rubyXL/convenience_methods.rb', line 878

def change_text_indent(indent)
  validate_worksheet
  self.style_index = workbook.modify_alignment(self.style_index) { |a| a.indent = indent }
end

#change_text_rotation(rot) ⇒ Object



873
874
875
876
# File 'lib/rubyXL/convenience_methods.rb', line 873

def change_text_rotation(rot)
  validate_worksheet
  self.style_index = workbook.modify_alignment(self.style_index) { |a| a.text_rotation = rot }
end

#change_text_wrap(wrap = false) ⇒ Object



868
869
870
871
# File 'lib/rubyXL/convenience_methods.rb', line 868

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



863
864
865
866
# File 'lib/rubyXL/convenience_methods.rb', line 863

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

#fill_colorObject



929
930
931
932
# File 'lib/rubyXL/convenience_methods.rb', line 929

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

#font_colorObject



924
925
926
927
# File 'lib/rubyXL/convenience_methods.rb', line 924

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

#font_nameObject



914
915
916
917
# File 'lib/rubyXL/convenience_methods.rb', line 914

def font_name()
  validate_worksheet
  get_cell_font.get_name
end

#font_sizeObject



919
920
921
922
# File 'lib/rubyXL/convenience_methods.rb', line 919

def font_size()
  validate_worksheet
  get_cell_font.get_size
end

#font_switch(change_type, arg) ⇒ Object

Performs correct modification based on what type of change_type is specified



1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
# File 'lib/rubyXL/convenience_methods.rb', line 1055

def font_switch(change_type, arg)
  case change_type
  when Worksheet::NAME          then change_font_name(arg)
  when Worksheet::SIZE          then change_font_size(arg)
  when Worksheet::COLOR         then change_font_color(arg)
  when Worksheet::ITALICS       then change_font_italics(arg)
  when Worksheet::BOLD          then change_font_bold(arg)
  when Worksheet::UNDERLINE     then change_font_underline(arg)
  when Worksheet::STRIKETHROUGH then change_font_strikethrough(arg)
  else raise 'Invalid change_type'
  end
end

#get_border(direction) ⇒ Object



848
849
850
851
# File 'lib/rubyXL/convenience_methods.rb', line 848

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

#get_border_color(direction) ⇒ Object



853
854
855
856
# File 'lib/rubyXL/convenience_methods.rb', line 853

def get_border_color(direction)
  validate_worksheet
  get_cell_border.get_edge_color(direction)
end

#horizontal_alignmentObject



934
935
936
937
938
939
# File 'lib/rubyXL/convenience_methods.rb', line 934

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

#is_boldedObject



899
900
901
902
# File 'lib/rubyXL/convenience_methods.rb', line 899

def is_bolded()
  validate_worksheet
  get_cell_font.is_bold
end

#is_italicizedObject



894
895
896
897
# File 'lib/rubyXL/convenience_methods.rb', line 894

def is_italicized()
  validate_worksheet
  get_cell_font.is_italic
end

#is_struckthroughObject



909
910
911
912
# File 'lib/rubyXL/convenience_methods.rb', line 909

def is_struckthrough()
  validate_worksheet
  get_cell_font.is_strikethrough
end

#is_underlinedObject



904
905
906
907
# File 'lib/rubyXL/convenience_methods.rb', line 904

def is_underlined()
  validate_worksheet
  get_cell_font.is_underlined
end

#set_number_format(format_code) ⇒ Object



969
970
971
972
973
974
# File 'lib/rubyXL/convenience_methods.rb', line 969

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_indentObject



962
963
964
965
966
967
# File 'lib/rubyXL/convenience_methods.rb', line 962

def text_indent()
  validate_worksheet
  xf_obj = get_cell_xf
  return nil if xf_obj.alignment.nil?
  xf_obj.alignment.indent
end

#text_rotationObject



955
956
957
958
959
960
# File 'lib/rubyXL/convenience_methods.rb', line 955

def text_rotation
  validate_worksheet
  xf_obj = get_cell_xf
  return nil if xf_obj.alignment.nil?
  xf_obj.alignment.text_rotation    
end

#text_wrapObject



948
949
950
951
952
953
# File 'lib/rubyXL/convenience_methods.rb', line 948

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



941
942
943
944
945
946
# File 'lib/rubyXL/convenience_methods.rb', line 941

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