lib/rubyXL/convenience_methods.rb in rubyXL-3.3.9 vs lib/rubyXL/convenience_methods.rb in rubyXL-3.3.10
- old
+ new
@@ -138,11 +138,11 @@
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
end
- def register_new_xf(new_xf, old_style_index)
+ def register_new_xf(new_xf)
new_xf_id = cell_xfs.find_index { |xf| xf == new_xf } # Use 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
@@ -150,20 +150,20 @@
def modify_alignment(style_index, &block)
xf = cell_xfs[style_index].dup
xf.alignment ||= RubyXL::Alignment.new
xf.apply_alignment = true
yield(xf.alignment)
- register_new_xf(xf, style_index)
+ register_new_xf(xf)
end
def modify_fill(style_index, rgb)
xf = cell_xfs[style_index].dup
new_fill = RubyXL::Fill.new(:pattern_fill =>
RubyXL::PatternFill.new(:pattern_type => 'solid',
:fg_color => RubyXL::Color.new(:rgb => rgb)))
new_xf = register_new_fill(new_fill, xf)
- register_new_xf(new_xf, style_index)
+ register_new_xf(new_xf)
end
def modify_border(style_index, direction, weight)
old_xf = cell_xfs[style_index].dup
new_border = borders[old_xf.border_id].dup
@@ -174,11 +174,11 @@
new_xf.border_id = borders.find_index { |x| x == new_border } # Use existing border, if it exists
new_xf.border_id ||= borders.size # If this border has never existed before, add it to collection.
borders[new_xf.border_id] = new_border
- register_new_xf(new_xf, style_index)
+ register_new_xf(new_xf)
end
end
@@ -674,9 +674,16 @@
def text_wrap()
validate_worksheet
xf_obj = get_cell_xf
return nil if xf_obj.alignment.nil?
xf_obj.alignment.wrap_text
+ end
+
+ 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
end
end