Skip to content

Commit

Permalink
Merge pull request randym#147 from raiis/master
Browse files Browse the repository at this point in the history
Different left/right border style
  • Loading branch information
randym committed Nov 27, 2012
2 parents 3757bd8 + e5c4379 commit 7d3d588
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/styles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@
# 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
override_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|

# We then apply those styles positionally
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, override_border, predefined_format]
end

end
Expand Down
6 changes: 5 additions & 1 deletion lib/axlsx/stylesheet/styles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ def parse_fill_options(options={})
# 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] }
Expand All @@ -319,7 +321,9 @@ def parse_border_options(options={})
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]) }
edge_options = options["border_#{edge}".to_sym] || {}
border_edge = b_opts.merge(edge_options)
b_options = { :name => edge, :style => border_edge[:style], :color => Color.new(:rgb => border_edge[:color]) }
border.prs << BorderPr.new(b_options)
end
options[:type] == :dxf ? border : borders << border
Expand Down

0 comments on commit 7d3d588

Please sign in to comment.