lib/axlsx/stylesheet/styles.rb in axlsx-1.3.4 vs lib/axlsx/stylesheet/styles.rb in axlsx-1.3.5
- old
+ new
@@ -151,13 +151,13 @@
# ws = p.workbook.add_worksheet
#
# # black text on a white background at 14pt with thin borders!
# title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
#
- # ws.add_row :values => ["Least Popular Pets"]
- # ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
- # ws.add_row :values => ["Votes", 6, 4, 1], :style=>Axlsx::STYLE_THIN_BORDER
+ # ws.add_row ["Least Popular Pets"]
+ # ws.add_row ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
+ # ws.add_row ["Votes", 6, 4, 1], :style=>Axlsx::STYLE_THIN_BORDER
# f = File.open('example_you_got_style.xlsx', 'w')
# p.serialize(f)
#
# @example Styling specifically
# # an example of applying specific styles to specific cells
@@ -181,17 +181,17 @@
#
# currency = ws.style.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
# :border=>Axlsx::STYLE_THIN_BORDER)
#
# # build your rows
- # ws.add_row :values => ["Genreated At:", Time.now], :styles=>[nil, date_time]
- # ws.add_row :values => ["Previous Year Quarterly Profits (JPY)"], :style=>title
- # ws.add_row :values => ["Quarter", "Profit", "% of Total"], :style=>title
- # ws.add_row :values => ["Q1", 4000, 40], :style=>[title, currency, percent]
- # ws.add_row :values => ["Q2", 3000, 30], :style=>[title, currency, percent]
- # ws.add_row :values => ["Q3", 1000, 10], :style=>[title, currency, percent]
- # ws.add_row :values => ["Q4", 2000, 20], :style=>[title, currency, percent]
+ # ws.add_row ["Genreated At:", Time.now], :styles=>[nil, date_time]
+ # ws.add_row ["Previous Year Quarterly Profits (JPY)"], :style=>title
+ # ws.add_row ["Quarter", "Profit", "% of Total"], :style=>title
+ # ws.add_row ["Q1", 4000, 40], :style=>[title, currency, percent]
+ # ws.add_row ["Q2", 3000, 30], :style=>[title, currency, percent]
+ # ws.add_row ["Q3", 1000, 10], :style=>[title, currency, percent]
+ # ws.add_row ["Q4", 2000, 20], :style=>[title, currency, percent]
# f = File.open('example_you_got_style.xlsx', 'w')
# p.serialize(f)
#
# @example Differential styling
# # Differential styles apply on top of cell styles. Used in Conditional Formatting. Must specify :type => :dxf, and you can't use :num_fmt.
@@ -205,17 +205,17 @@
# # define your styles
# profitable = wb.styles.add_style(:bg_color => "FFFF0000",
# :fg_color=>"#FF000000",
# :type => :dxf)
#
- # ws.add_row :values => ["Genreated At:", Time.now], :styles=>[nil, date_time]
- # ws.add_row :values => ["Previous Year Quarterly Profits (JPY)"], :style=>title
- # ws.add_row :values => ["Quarter", "Profit", "% of Total"], :style=>title
- # ws.add_row :values => ["Q1", 4000, 40], :style=>[title, currency, percent]
- # ws.add_row :values => ["Q2", 3000, 30], :style=>[title, currency, percent]
- # ws.add_row :values => ["Q3", 1000, 10], :style=>[title, currency, percent]
- # ws.add_row :values => ["Q4", 2000, 20], :style=>[title, currency, percent]
+ # ws.add_row ["Genreated At:", Time.now], :styles=>[nil, date_time]
+ # ws.add_row ["Previous Year Quarterly Profits (JPY)"], :style=>title
+ # ws.add_row ["Quarter", "Profit", "% of Total"], :style=>title
+ # ws.add_row ["Q1", 4000, 40], :style=>[title, currency, percent]
+ # ws.add_row ["Q2", 3000, 30], :style=>[title, currency, percent]
+ # ws.add_row ["Q3", 1000, 10], :style=>[title, currency, percent]
+ # ws.add_row ["Q4", 2000, 20], :style=>[title, currency, percent]
#
# ws.add_conditional_formatting("A1:A7", { :type => :cellIs, :operator => :greaterThan, :formula => "2000", :dxfId => profitable, :priority => 1 })
# f = File.open('example_differential_styling', 'w')
# p.serialize(f)
#
@@ -306,10 +306,12 @@
# @option options [Hash|Integer] A border style definition hash or the index of an existing border.
# Border style definition hashes must include :style and :color key-value entries and
# 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] }
# @return [Border|Integer]
def parse_border_options(options={})
@@ -317,10 +319,12 @@
b_opts = options[:border]
if b_opts.is_a?(Hash)
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
elsif b_opts.is_a? Integer
raise ArgumentError, (ERR_INVALID_BORDER_ID % b_opts) unless b_opts < borders.size