Class: Axlsx::PrintOptions

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

Overview

Note:

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

Options for printing a worksheet. All options are boolean and false by default.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PrintOptions

Creates a new PrintOptions object

Parameters:

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

    a customizable set of options

Options Hash (options):

  • grid_lines (Boolean)

    Whether grid lines should be printed

  • headings (Boolean)

    Whether row and column headings should be printed

  • horizontal_centered (Boolean)

    Whether the content should be centered horizontally

  • vertical_centered (Boolean)

    Whether the content should be centered vertically



30
31
32
33
# File 'lib/axlsx/workbook/worksheet/print_options.rb', line 30

def initialize(options = {})
  @grid_lines = @headings = @horizontal_centered = @vertical_centered = false
  set(options)
end

Instance Attribute Details

#grid_linesBoolean

Whether grid lines should be printed.

Returns:

  • (Boolean)


11
12
13
# File 'lib/axlsx/workbook/worksheet/print_options.rb', line 11

def grid_lines
  @grid_lines
end

#headingsBoolean

Whether row and column headings should be printed.

Returns:

  • (Boolean)


15
16
17
# File 'lib/axlsx/workbook/worksheet/print_options.rb', line 15

def headings
  @headings
end

#horizontal_centeredBoolean

Whether the content should be centered horizontally on the page.

Returns:

  • (Boolean)


19
20
21
# File 'lib/axlsx/workbook/worksheet/print_options.rb', line 19

def horizontal_centered
  @horizontal_centered
end

#vertical_centeredBoolean

Whether the content should be centered vertically on the page.

Returns:

  • (Boolean)


23
24
25
# File 'lib/axlsx/workbook/worksheet/print_options.rb', line 23

def vertical_centered
  @vertical_centered
end

Instance Method Details

#set(options) ⇒ Object

Set some or all options at once.

Parameters:

  • options (Hash)

    The options to set (possible keys are :grid_lines, :headings, :horizontal_centered, and :vertical_centered).



37
38
39
40
41
# File 'lib/axlsx/workbook/worksheet/print_options.rb', line 37

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

#to_xml_string(str = '') ⇒ String

Note:

As all attributes default to "false" according to the xml schema definition, the generated xml includes only those attributes that are set to true.

Serializes the page options element.

Parameters:

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

Returns:

  • (String)


56
57
58
59
60
61
# File 'lib/axlsx/workbook/worksheet/print_options.rb', line 56

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