Class: Axlsx::PageSetup

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/page_setup.rb

Overview

Note:

The recommended way to manage print options is via Worksheet#page_setup

Page setup settings for printing a worksheet. All settings are optional.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PageSetup

Creates a new PageSetup object

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • fit_to_height (Integer)

    Number of vertical pages to fit on

  • fit_to_width (Integer)

    Number of horizontal pages to fit on

  • orientation (Symbol)

    Orientation of the page (:default, :landscape, :portrait)

  • paper_height (String)

    Height of paper (number followed by unit identifier: "297mm", "11in")

  • paper_width (String)

    Width of paper (number followed by unit identifier: "210mm", "8.5in")

  • scale (Integer)

    Print scaling (percent value, integer ranging from 10 to 400)



59
60
61
# File 'lib/axlsx/workbook/worksheet/page_setup.rb', line 59

def initialize(options = {})
  set(options)
end

Instance Attribute Details

#fit_to_heightInteger

Returns:

  • (Integer)


28
29
30
# File 'lib/axlsx/workbook/worksheet/page_setup.rb', line 28

def fit_to_height
  @fit_to_height
end

#fit_to_widthInteger

Note:

PageSetup#fit_to is the recomended way to manage page fitting as only specifying one of width/height will result in the counterpart

Number of horizontal pages to fit on. being set to 1.

Returns:

  • (Integer)


34
35
36
# File 'lib/axlsx/workbook/worksheet/page_setup.rb', line 34

def fit_to_width
  @fit_to_width
end

#orientationSymbol

Orientation of the page (:default, :landscape, :portrait)

Returns:

  • (Symbol)


38
39
40
# File 'lib/axlsx/workbook/worksheet/page_setup.rb', line 38

def orientation
  @orientation
end

#paper_heightString

Height of paper (string containing a number followed by a unit identifier: "297mm", "11in")

Returns:

  • (String)


42
43
44
# File 'lib/axlsx/workbook/worksheet/page_setup.rb', line 42

def paper_height
  @paper_height
end

#paper_widthString

Width of paper (string containing a number followed by a unit identifier: "210mm", "8.5in")

Returns:

  • (String)


46
47
48
# File 'lib/axlsx/workbook/worksheet/page_setup.rb', line 46

def paper_width
  @paper_width
end

#scaleInteger

Print scaling (percent value, given as integer ranging from 10 to 400)

Returns:

  • (Integer)


50
51
52
# File 'lib/axlsx/workbook/worksheet/page_setup.rb', line 50

def scale
  @scale
end

Instance Method Details

#fit_to(options = {}) ⇒ Object

Note:

This method will overwrite any value you explicitly set via the fit_to_height or fit_to_width methods.

convenience method to achieve sanity when setting fit_to_width and fit_to_height as they both default to 1 if only their counterpart is specified.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • width (Integer)

    The number of pages to fit this worksheet on horizontally. Default 9999

  • height (Integer)

    The number of pages to fit this worksheet on vertically. Default 9999



89
90
91
92
93
# File 'lib/axlsx/workbook/worksheet/page_setup.rb', line 89

def fit_to(options={})
  self.fit_to_width = options[:width] || 9999
  self.fit_to_height = options[:height] || 9999
  [@fit_to_width, @fit_to_height]
end

#fit_to_page?Boolean

helper method for worksheet to determine if the page setup is configured for fit to page printing We treat any page set up that has a value set for fit_to_width or fit_to_height value as fit_to_page.

Returns:

  • (Boolean)


99
100
101
102
# File 'lib/axlsx/workbook/worksheet/page_setup.rb', line 99

def fit_to_page?
   # is there some better what to express this?
   (fit_to_width != nil || fit_to_height != nil)
end

#set(options) ⇒ Object

Set some or all page settings at once.

Parameters:

  • options (Hash)

    The page settings to set (possible keys are :fit_to_height, :fit_to_width, :orientation, :paper_height, :paper_width, and :scale).



65
66
67
68
69
# File 'lib/axlsx/workbook/worksheet/page_setup.rb', line 65

def set(options)
  options.each do |k, v|
    send("#{k}=", v) if respond_to? "#{k}="
  end
end

#to_xml_string(str = '') ⇒ String

Serializes the page settings element.

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


107
108
109
110
111
# File 'lib/axlsx/workbook/worksheet/page_setup.rb', line 107

def to_xml_string(str = '')
  str << '<pageSetup '
  str << instance_values.reject{ |k, v| k == 'worksheet' }.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v}"} }.join(' ')
  str << '/>'
end