diff options
| author | Randy Morgan <[email protected]> | 2012-05-16 08:43:34 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-05-16 08:43:34 +0900 |
| commit | 5dddaaf46d4849d370f3a5587e46979c75a3c848 (patch) | |
| tree | fa9ba5e135a4763b20f8a95f0f2612c12fc86ee4 /lib/axlsx/workbook/worksheet/page_setup.rb | |
| parent | 80252d12123118f2ebbd9736931f3c0150cf1653 (diff) | |
| download | caxlsx-5dddaaf46d4849d370f3a5587e46979c75a3c848.tar.gz caxlsx-5dddaaf46d4849d370f3a5587e46979c75a3c848.zip | |
If worksheet.fit_to_page must be true, lets set it to true. I am far too lazy and forgetful to remember to set that every time I want to fit_to_width or fit_to_height.
Diffstat (limited to 'lib/axlsx/workbook/worksheet/page_setup.rb')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/page_setup.rb | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/axlsx/workbook/worksheet/page_setup.rb b/lib/axlsx/workbook/worksheet/page_setup.rb index f8441570..20e05f66 100644 --- a/lib/axlsx/workbook/worksheet/page_setup.rb +++ b/lib/axlsx/workbook/worksheet/page_setup.rb @@ -1,9 +1,6 @@ module Axlsx # Page setup settings for printing a worksheet. All settings are optional. # - # When using {#fit_to_width} and/or {#fit_to_height}, make sure to also set {Worksheet#fit_to_page} to true – - # otherwise this setting will not have any effect. - # # @note The recommended way to manage print options is via Worksheet#page_setup # @see Worksheet#print_options # @see Worksheet#initialize @@ -26,12 +23,10 @@ module Axlsx # Number of vertical pages to fit on. # @return [Integer] - # @note Make sure to also set {Worksheet#fit_to_page} to true – otherwise this setting will not have any effect. attr_reader :fit_to_height # Number of horizontal pages to fit on. # @return [Integer] - # @note Make sure to also set {Worksheet#fit_to_page} to true – otherwise this setting will not have any effect. attr_reader :fit_to_width # Orientation of the page (:default, :landscape, :portrait) @@ -50,6 +45,8 @@ module Axlsx # @return [Integer] attr_reader :scale + # The worksheet that owns this page_setup. + attr_reader :worksheet # Creates a new PageSetup object # @option options [Integer] fit_to_height Number of vertical pages to fit on @@ -59,6 +56,8 @@ module Axlsx # @option options [String] paper_width Width of paper (number followed by unit identifier: "210mm", "8.5in") # @option options [Integer] scale Print scaling (percent value, integer ranging from 10 to 400) def initialize(options = {}) + raise ArgumentError, "Worksheet option is required" unless options[:worksheet].is_a?(Worksheet) + @worksheet = options[:worksheet] set(options) end @@ -71,9 +70,9 @@ module Axlsx end # @see fit_to_height - def fit_to_height=(v); Axlsx::validate_unsigned_int(v); @fit_to_height = v; end + def fit_to_height=(v); Axlsx::validate_unsigned_int(v); @fit_to_height = v; @worksheet.fit_to_page = true; end # @see fit_to_width - def fit_to_width=(v); Axlsx::validate_unsigned_int(v); @fit_to_width = v; end + def fit_to_width=(v); Axlsx::validate_unsigned_int(v); @fit_to_width = v; @worksheet.fit_to_page = true; end # @see orientation def orientation=(v); Axlsx::validate_page_orientation(v); @orientation = v; end # @see paper_height @@ -88,7 +87,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') str << '<pageSetup ' - str << instance_values.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v}"} }.join(' ') + str << instance_values.reject{ |k, v| k == 'worksheet' }.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v}"} }.join(' ') str << '/>' end end |
