diff options
| author | raiis <[email protected]> | 2012-11-26 21:13:55 +0200 |
|---|---|---|
| committer | raiis <[email protected]> | 2012-11-26 21:13:55 +0200 |
| commit | 0962f913904343db03d253cc72681c8213aacea3 (patch) | |
| tree | 1e700d31f7413d9620592d450c564f1b389db6da | |
| parent | 25ebea9143c136999bdaeb372fb26d2c070ca730 (diff) | |
| download | caxlsx-0962f913904343db03d253cc72681c8213aacea3.tar.gz caxlsx-0962f913904343db03d253cc72681c8213aacea3.zip | |
Added individual border override options.
| -rw-r--r-- | examples/styles.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/stylesheet/styles.rb | 7 |
2 files changed, 10 insertions, 1 deletions
diff --git a/examples/styles.rb b/examples/styles.rb index b69251b4..e8047ab1 100644 --- a/examples/styles.rb +++ b/examples/styles.rb @@ -48,6 +48,9 @@ wb.styles do |style| # A style that a applies a font size and a custom formatting code custom_format = wb.styles.add_style :sz => 20, :format_code => 'yyyy-mm-dd' + # A style that overrides top and left border style + one_border = wb.styles.add_style :border => { :style => :thin, :color =>"FAAC58", :edges => [:right, :top, :left] }, :border_top => { :style => :thick, :color => "01DF74" }, :border_left => { :color => "0101DF" } + wb.add_worksheet do |sheet| @@ -55,6 +58,7 @@ wb.styles do |style| sheet.add_row [123, "123", Time.now], style: [nil, large_font, predefined_format] sheet.add_row [123, "123", Date.new(2012, 9, 14)], style: [large_font, nil, custom_format] sheet.add_row [123, "123", Date.new(2000, 9, 12)] # This uses the axlsx default format_code (14) + sheet.add_row [123, "123", Time.now], style: [large_font, one_border, predefined_format] end end diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index da5b277f..ab2903f2 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -308,6 +308,8 @@ module Axlsx # may include an :edges entry that references an array of symbols identifying which border edges # you wish to apply the style or any other valid Border initializer options. # If the :edges entity is not provided the style is applied to all edges of cells that reference this style. + # Also available :border_top, :border_right, :border_bottom and :border_left options with :style and/or :color + # key-value entries, which override :border values. # @example # #apply a thick red border to the top and bottom # { :border => { :style => :thick, :color => "FFFF0000", :edges => [:top, :bottom] } @@ -319,7 +321,10 @@ module Axlsx raise ArgumentError, (ERR_INVALID_BORDER_OPTIONS % b_opts) unless b_opts.keys.include?(:style) && b_opts.keys.include?(:color) border = Border.new b_opts (b_opts[:edges] || [:left, :right, :top, :bottom]).each do |edge| - b_options = { :name => edge, :style => b_opts[:style], :color => Color.new(:rgb => b_opts[:color]) } + sb_opts = options["border_#{edge}".to_sym] + style = (!sb_opts.nil? && sb_opts.keys.include?(:style)) ? sb_opts[:style] : b_opts[:style] + color = (!sb_opts.nil? && sb_opts.keys.include?(:color)) ? sb_opts[:color] : b_opts[:color] + b_options = { :name => edge, :style => style, :color => Color.new(:rgb => color) } border.prs << BorderPr.new(b_options) end options[:type] == :dxf ? border : borders << border |
