lib/rubyXL/convenience_methods.rb in rubyXL-3.3.13 vs lib/rubyXL/convenience_methods.rb in rubyXL-3.3.14

- old
+ new

@@ -744,8 +744,117 @@ 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 + # Changes fill color of cell + def change_fill(rgb = 'ffffff') + validate_worksheet + Color.validate_color(rgb) + self.style_index = workbook.modify_fill(self.style_index, rgb) + end + + # Changes font name of cell + 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 + + # Changes font size of cell + 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 + + # Changes font color of cell + 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 + + # Changes font italics settings of cell + def change_font_italics(italicized = false) + validate_worksheet + + font = get_cell_font.dup + font.set_italic(italicized) + update_font_references(font) + end + + # Changes font bold settings of cell + def change_font_bold(bolded = false) + validate_worksheet + + font = get_cell_font.dup + font.set_bold(bolded) + update_font_references(font) + end + + # Changes font underline settings of cell + def change_font_underline(underlined = false) + validate_worksheet + + font = get_cell_font.dup + font.set_underline(underlined) + update_font_references(font) + end + + def change_font_strikethrough(struckthrough = false) + validate_worksheet + + font = get_cell_font.dup + font.set_strikethrough(struckthrough) + update_font_references(font) + end + + # Helper method to update the font array and xf array + def update_font_references(modified_font) + xf = workbook.register_new_font(modified_font, get_cell_xf) + self.style_index = workbook.register_new_xf(xf) + end + private :update_font_references + + # Performs correct modification based on what type of change_type is specified + 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 + +=begin + def add_hyperlink(l) + worksheet.hyperlinks ||= RubyXL::Hyperlinks.new + worksheet.hyperlinks << RubyXL::Hyperlink.new(:ref => self.r, :location => l) +# define_attribute(:'r:id', :string) +# define_attribute(:location, :string) +# define_attribute(:tooltip, :string) +# define_attribute(:display, :string) + + end + + def add_shared_string(str) + self.datatype = RubyXL::DataType::SHARED_STRING + self.raw_value = @workbook.shared_strings_container.add(str) + end +=end + end end