diff options
| author | Randy Morgan <[email protected]> | 2012-03-23 00:48:42 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-03-23 00:48:42 +0900 |
| commit | 43d31eb7c4f04e3ddf3bf865d55e6ce8de7b7a69 (patch) | |
| tree | 44b89d66539724341e95cfc29d6aa70c771d77ca /lib/axlsx/stylesheet | |
| parent | 6df8104a5b059497d7363d45118a5d1379c4db6a (diff) | |
| download | caxlsx-43d31eb7c4f04e3ddf3bf865d55e6ce8de7b7a69.tar.gz caxlsx-43d31eb7c4f04e3ddf3bf865d55e6ce8de7b7a69.zip | |
update add Styles#add_style to allow a simple hash to create a new border style
Diffstat (limited to 'lib/axlsx/stylesheet')
| -rw-r--r-- | lib/axlsx/stylesheet/border.rb | 8 | ||||
| -rw-r--r-- | lib/axlsx/stylesheet/styles.rb | 12 |
2 files changed, 15 insertions, 5 deletions
diff --git a/lib/axlsx/stylesheet/border.rb b/lib/axlsx/stylesheet/border.rb index 534521e6..f3d329fa 100644 --- a/lib/axlsx/stylesheet/border.rb +++ b/lib/axlsx/stylesheet/border.rb @@ -21,13 +21,13 @@ module Axlsx # @option options [Boolean] outline # @example Making a border # p = Axlsx::Package.new - # red_border = Axlsx::Border.new - # [:left, :right, :top, :bottom].each {|item| red_border.prs << Axlsx::BorderPr.new(:name => item, :style=>:thin, :color => Axlsx::Color.new(:rgb => "FFFF0000"))} - # red_border = p.workbook.styles.borders << red_border - # red_border = p.workbook.styles.add_style :border => red_border + # red_border = p.workbook.styles.add_style :border => {:style =>: thin, :color => "FFFF0000"} # ws = p.workbook.add_worksheet # ws.add_row [1,2,3], :style => red_border # p.serialize('red_border.xlsx') + # + # @note The recommended way to manage borders is with Style#add_style + # @see Style#add_style def initialize(options={}) @prs = SimpleTypedList.new BorderPr options.each do |o| diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index cb40ee74..a05067cd 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -133,7 +133,7 @@ module Axlsx # @option options [String] font_name The name of the font to use # @option options [Integer] num_fmt The number format to apply # @option options [String] format_code The formatting to apply. If this is specified, num_fmt is ignored. - # @option options [Integer] border The border style to use. + # @option options [Integer] border The border style to use. This can be the index of an existing border or a hash like {:style => :thin, :color => "FFFF0000"} to create a new border style # @option options [String] bg_color The background color to apply to the cell # @option options [Boolean] hidden Indicates if the cell should be hidden # @option options [Boolean] locked Indicates if the cell should be locked @@ -201,6 +201,16 @@ module Axlsx borderId = options[:border] || 0 + if borderId.is_a?(Hash) + raise ArgumentError, "border hash definitions must include both style and color" unless borderId.keys.include?(:style) && borderId.keys.include?(:color) + + s = borderId.delete :style + c = borderId.delete :color + border = Border.new + [:left, :right, :top, :bottom].each {|pr| border.prs << BorderPr.new(:name => pr, :style=>s, :color => Color.new(:rgb => c))} + borderId = self.borders << border + end + raise ArgumentError, "Invalid borderId" unless borderId < borders.size fill = if options[:bg_color] |
