Class: Axlsx::HeaderFooter

Inherits:
Object
  • Object
show all
Includes:
Accessors, OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/workbook/worksheet/header_footer.rb

Overview

Note:

The recommended way of managing header/footers is via Worksheet#header_footer

Header/Footer options for printing a worksheet. All settings are optional.

Headers and footers are generated using a string which is a combination of plain text and control characters. A fairly comprehensive list of control characters can be found here: https://github.com/randym/axlsx/blob/master/notes_on_header_footer.md     

Instance Method Summary collapse

Methods included from SerializedAttributes

#declared_attributes, included, #serialized_attributes, #serialized_element_attributes

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(options = {}) ⇒ HeaderFooter

Creates a new HeaderFooter object

Parameters:

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

    a customizable set of options

Options Hash (options):

  • odd_header (String)

    The content for headers on odd numbered pages.

  • odd_footer (String)

    The content for footers on odd numbered pages.

  • even_header (String)

    The content for headers on even numbered pages.

  • even_footer (String)

    The content for footers on even numbered pages.

  • first_header (String)

    The content for headers on even numbered pages.

  • first_footer (String)

    The content for footers on even numbered pages.

  • different_odd_even (Boolean)

    Setting this to true will show different headers/footers on odd and even pages. When false, the odd headers/footers are used on each page. (Default: false)

  • different_first (Boolean)

    If true, will use the first header/footer on page 1. Otherwise, the odd header/footer is used.



26
27
28
# File 'lib/axlsx/workbook/worksheet/header_footer.rb', line 26

def initialize(options = {})
  parse_options options
end

Instance Method Details

#set(options) ⇒ Object

Set some or all header/footers at once.

Parameters:

  • options (Hash)

    The header/footer options to set (possible keys are :odd_header, :odd_footer, :even_header, :even_footer, :first_header, :first_footer, :different_odd_even, and :different_first).



37
38
39
# File 'lib/axlsx/workbook/worksheet/header_footer.rb', line 37

def set(options)
  parse_options options
end

#to_xml_string(str = '') ⇒ String

Serializes the header/footer object.

Parameters:

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

Returns:

  • (String)


44
45
46
47
48
49
50
51
52
# File 'lib/axlsx/workbook/worksheet/header_footer.rb', line 44

def to_xml_string(str = '')
  str << "<headerFooter "
  serialized_attributes str
  str << ">"
  serialized_element_attributes(str) do |value|
    value = ::CGI.escapeHTML(value)
  end
  str << "</headerFooter>"
end