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 | |
| 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')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/page_setup.rb | 15 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 5 |
2 files changed, 9 insertions, 11 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 diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 887968e0..3789ba60 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -90,7 +90,6 @@ module Axlsx # # # using options when creating the worksheet. # ws = wb.add_worksheet :page_setup => {:fit_to_width => 2, :orientation => :landscape} - # ws.fit_to_page = true # otherwise fit_to_width will be ignored # # # use the set method of the page_setup object # ws.page_setup.set(:paper_width => "297mm", :paper_height => "210mm") @@ -103,7 +102,7 @@ module Axlsx # @see PageSetup#initialize # @return [PageSetup] def page_setup - @page_setup ||= PageSetup.new + @page_setup ||= PageSetup.new(:worksheet => self) yield @page_setup if block_given? @page_setup end @@ -157,7 +156,7 @@ module Axlsx @show_gridlines = true self.name = "Sheet" + (index+1).to_s @page_margins = PageMargins.new options[:page_margins] if options[:page_margins] - @page_setup = PageSetup.new options[:page_setup] if options[:page_setup] + @page_setup = PageSetup.new options[:page_setup].merge(:worksheet=>self) if options[:page_setup] @print_options = PrintOptions.new options[:print_options] if options[:print_options] @rows = SimpleTypedList.new Row @column_info = SimpleTypedList.new Col |
