Class: Writexlsx::PageSetup

Inherits:
Object
  • Object
show all
Includes:
Utility::Common
Defined in:
lib/write_xlsx/page_setup.rb

Overview

:nodoc:

Constant Summary

Constants included from Utility::Common

Utility::Common::PERL_TRUE_VALUES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility::Common

#absolute_char, #check_parameter, #float_to_str, #ptrue?, #put_deprecate_message

Constructor Details

#initializePageSetup

:nodoc:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/write_xlsx/page_setup.rb', line 21

def initialize # :nodoc:
  @margin_left = 0.7
  @margin_right = 0.7
  @margin_top = 0.75
  @margin_bottom = 0.75
  @margin_header = 0.3
  @margin_footer = 0.3
  @repeat_rows   = ''
  @repeat_cols   = ''
  @print_area    = ''
  @hbreaks = []
  @vbreaks = []
  @scale = 100
  @fit_page = false
  @fit_width  = nil
  @fit_height = nil
  @page_setup_changed = false
  @across = false
  @orientation = true
  @header_footer_aligns = true
  @header_footer_scales = true
end

Instance Attribute Details

#across=(value) ⇒ Object (writeonly)

:nodoc:



15
16
17
# File 'lib/write_xlsx/page_setup.rb', line 15

def across=(value)
  @across = value
end

#black_whiteObject

:nodoc:



16
17
18
# File 'lib/write_xlsx/page_setup.rb', line 16

def black_white
  @black_white
end

#fit_heightObject

:nodoc:



14
15
16
# File 'lib/write_xlsx/page_setup.rb', line 14

def fit_height
  @fit_height
end

#fit_pageObject

:nodoc:



14
15
16
# File 'lib/write_xlsx/page_setup.rb', line 14

def fit_page
  @fit_page
end

#fit_widthObject

:nodoc:



14
15
16
# File 'lib/write_xlsx/page_setup.rb', line 14

def fit_width
  @fit_width
end

Returns the value of attribute footer.



17
18
19
# File 'lib/write_xlsx/page_setup.rb', line 17

def footer
  @footer
end

#hbreaksObject

:nodoc:



13
14
15
# File 'lib/write_xlsx/page_setup.rb', line 13

def hbreaks
  @hbreaks
end

#headerObject

Returns the value of attribute header.



17
18
19
# File 'lib/write_xlsx/page_setup.rb', line 17

def header
  @header
end

Returns the value of attribute header_footer_aligns.



17
18
19
# File 'lib/write_xlsx/page_setup.rb', line 17

def header_footer_aligns
  @header_footer_aligns
end

Returns the value of attribute header_footer_changed.



17
18
19
# File 'lib/write_xlsx/page_setup.rb', line 17

def header_footer_changed
  @header_footer_changed
end

Returns the value of attribute header_footer_scales.



17
18
19
# File 'lib/write_xlsx/page_setup.rb', line 17

def header_footer_scales
  @header_footer_scales
end

#horizontal_dpi=(value) ⇒ Object (writeonly)

Sets the attribute horizontal_dpi

Parameters:

  • value

    the value to set the attribute horizontal_dpi to.



19
20
21
# File 'lib/write_xlsx/page_setup.rb', line 19

def horizontal_dpi=(value)
  @horizontal_dpi = value
end

#margin_bottomObject

:nodoc:



10
11
12
# File 'lib/write_xlsx/page_setup.rb', line 10

def margin_bottom
  @margin_bottom
end

:nodoc:



11
12
13
# File 'lib/write_xlsx/page_setup.rb', line 11

def margin_footer
  @margin_footer
end

#margin_headerObject

:nodoc:



11
12
13
# File 'lib/write_xlsx/page_setup.rb', line 11

def margin_header
  @margin_header
end

#margin_leftObject

:nodoc:



10
11
12
# File 'lib/write_xlsx/page_setup.rb', line 10

def margin_left
  @margin_left
end

#margin_rightObject

:nodoc:



10
11
12
# File 'lib/write_xlsx/page_setup.rb', line 10

def margin_right
  @margin_right
end

#margin_topObject

:nodoc:



10
11
12
# File 'lib/write_xlsx/page_setup.rb', line 10

def margin_top
  @margin_top
end

#orientationObject

:nodoc:



16
17
18
# File 'lib/write_xlsx/page_setup.rb', line 16

def orientation
  @orientation
end

#page_setup_changedObject

:nodoc:



14
15
16
# File 'lib/write_xlsx/page_setup.rb', line 14

def page_setup_changed
  @page_setup_changed
end

#page_start=(value) ⇒ Object (writeonly)

Sets the attribute page_start

Parameters:

  • value

    the value to set the attribute page_start to.



18
19
20
# File 'lib/write_xlsx/page_setup.rb', line 18

def page_start=(value)
  @page_start = value
end

:nodoc:



12
13
14
# File 'lib/write_xlsx/page_setup.rb', line 12

def print_area
  @print_area
end

:nodoc:



16
17
18
# File 'lib/write_xlsx/page_setup.rb', line 16

def print_options_changed
  @print_options_changed
end

#repeat_colsObject

:nodoc:



12
13
14
# File 'lib/write_xlsx/page_setup.rb', line 12

def repeat_cols
  @repeat_cols
end

#repeat_rowsObject

:nodoc:



12
13
14
# File 'lib/write_xlsx/page_setup.rb', line 12

def repeat_rows
  @repeat_rows
end

#scaleObject

:nodoc:



13
14
15
# File 'lib/write_xlsx/page_setup.rb', line 13

def scale
  @scale
end

#vbreaksObject

:nodoc:



13
14
15
# File 'lib/write_xlsx/page_setup.rb', line 13

def vbreaks
  @vbreaks
end

#vertical_dpi=(value) ⇒ Object (writeonly)

Sets the attribute vertical_dpi

Parameters:

  • value

    the value to set the attribute vertical_dpi to.



19
20
21
# File 'lib/write_xlsx/page_setup.rb', line 19

def vertical_dpi=(value)
  @vertical_dpi = value
end

Instance Method Details

#center_horizontallyObject



51
52
53
54
# File 'lib/write_xlsx/page_setup.rb', line 51

def center_horizontally
  @print_options_changed = true
  @hcenter               = true
end

#center_verticallyObject



56
57
58
59
# File 'lib/write_xlsx/page_setup.rb', line 56

def center_vertically
  @print_options_changed = true
  @vcenter               = true
end

#hide_gridlines(option) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/write_xlsx/page_setup.rb', line 70

def hide_gridlines(option)
  if option == 0 || !option
    @print_gridlines = true
    @print_options_changed = true
  else
    @print_gridlines  = false
  end
end

#paper=(paper_size) ⇒ Object



44
45
46
47
48
49
# File 'lib/write_xlsx/page_setup.rb', line 44

def paper=(paper_size)
  if paper_size
    @paper_size = paper_size
    @page_setup_changed = true
  end
end


61
62
63
64
65
66
67
68
# File 'lib/write_xlsx/page_setup.rb', line 61

def print_row_col_headers(headers)
  if headers
    @print_headers         = true
    @print_options_changed = true
  else
    @print_headers         = false
  end
end

Write the element.



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/write_xlsx/page_setup.rb', line 149

def write_header_footer(writer, excel2003_style) # :nodoc:
  tag = 'headerFooter'
  attributes = []
  attributes << ['scaleWithDoc', 0]     unless ptrue?(@header_footer_scales)
  attributes << ['alignWithMargins', 0] unless ptrue?(@header_footer_aligns)

  if @header_footer_changed
    writer.tag_elements(tag, attributes) do
      write_odd_header(writer) if @header && @header != ''
      write_odd_footer(writer) if @footer && @footer != ''
    end
  elsif excel2003_style
    writer.empty_tag(tag, attributes)
  end
end

#write_page_margins(writer) ⇒ Object

Write the element.



128
129
130
# File 'lib/write_xlsx/page_setup.rb', line 128

def write_page_margins(writer) # :nodoc:
  writer.empty_tag('pageMargins', margin_attributes)
end

#write_page_setup(writer) ⇒ Object

Write the element.

The following is an example taken from Excel.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/write_xlsx/page_setup.rb', line 99

def write_page_setup(writer) # :nodoc:
  return unless @page_setup_changed

  attributes = []
  attributes << ['paperSize',       @paper_size]    if @paper_size
  attributes << ['scale',           @scale]         if @scale != 100
  attributes << ['fitToWidth',      @fit_width]     if @fit_page && @fit_width != 1
  attributes << ['fitToHeight',     @fit_height]    if @fit_page && @fit_height != 1
  attributes << %w[pageOrder overThenDown] if @across
  attributes << ['firstPageNumber', @page_start]    if @page_start && @page_start > 1
  attributes << ['orientation',
                 if @orientation
                   'portrait'
                 else
                   'landscape'
                 end]
  attributes << ['blackAndWhite', 1]      if @black_white
  attributes << ['useFirstPageNumber', 1] if ptrue?(@page_start)

  # Set the DPI. Mainly only for testing.
  attributes << ['horizontalDpi',  @horizontal_dpi] if @horizontal_dpi
  attributes << ['verticalDpi',    @vertical_dpi]   if @vertical_dpi

  writer.empty_tag('pageSetup', attributes)
end

#write_print_options(writer) ⇒ Object

Write the element.



135
136
137
138
139
140
141
142
143
144
# File 'lib/write_xlsx/page_setup.rb', line 135

def write_print_options(writer) # :nodoc:
  return unless @print_options_changed

  attributes = []
  attributes << ['horizontalCentered', 1] if @hcenter
  attributes << ['verticalCentered',   1] if @vcenter
  attributes << ['headings',           1] if @print_headers
  attributes << ['gridLines',          1] if @print_gridlines
  writer.empty_tag('printOptions', attributes)
end