Class: Writexlsx::Worksheet::PageSetup

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

Overview

:nodoc:

Constant Summary

Constants included from Utility

Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, #dash_types, delete_files, #fill_properties, #float_to_str, #layout_properties, #line_fill_properties, #line_properties, #palette_color, #pixels_to_points, #process_workbook_options, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #value_or_raise, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_div, #write_fill, #write_font, #write_stroke, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Constructor Details

#initializePageSetup

:nodoc:


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

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:


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

def across=(value)
  @across = value
end

#black_whiteObject

:nodoc:


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

def black_white
  @black_white
end

#fit_heightObject

:nodoc:


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

def fit_height
  @fit_height
end

#fit_pageObject

:nodoc:


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

def fit_page
  @fit_page
end

#fit_widthObject

:nodoc:


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

def fit_width
  @fit_width
end

Returns the value of attribute footer


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

def footer
  @footer
end

#hbreaksObject

:nodoc:


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

def hbreaks
  @hbreaks
end

#headerObject

Returns the value of attribute header


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

def header
  @header
end

Returns the value of attribute header_footer_aligns


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

def header_footer_aligns
  @header_footer_aligns
end

Returns the value of attribute header_footer_changed


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

def header_footer_changed
  @header_footer_changed
end

Returns the value of attribute header_footer_scales


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

def header_footer_scales
  @header_footer_scales
end

#horizontal_dpi=(value) ⇒ Object (writeonly)

Sets the attribute horizontal_dpi


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

def horizontal_dpi=(value)
  @horizontal_dpi = value
end

#margin_bottomObject

:nodoc:


8
9
10
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 8

def margin_bottom
  @margin_bottom
end

:nodoc:


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

def margin_footer
  @margin_footer
end

#margin_headerObject

:nodoc:


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

def margin_header
  @margin_header
end

#margin_leftObject

:nodoc:


8
9
10
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 8

def margin_left
  @margin_left
end

#margin_rightObject

:nodoc:


8
9
10
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 8

def margin_right
  @margin_right
end

#margin_topObject

:nodoc:


8
9
10
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 8

def margin_top
  @margin_top
end

#orientationObject

:nodoc:


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

def orientation
  @orientation
end

#page_setup_changedObject

:nodoc:


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

def page_setup_changed
  @page_setup_changed
end

#page_start=(value) ⇒ Object (writeonly)

Sets the attribute page_start


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

def page_start=(value)
  @page_start = value
end

:nodoc:


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

def print_area
  @print_area
end

:nodoc:


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

def print_options_changed
  @print_options_changed
end

#repeat_colsObject

:nodoc:


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

def repeat_cols
  @repeat_cols
end

#repeat_rowsObject

:nodoc:


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

def repeat_rows
  @repeat_rows
end

#scaleObject

:nodoc:


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

def scale
  @scale
end

#vbreaksObject

:nodoc:


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

def vbreaks
  @vbreaks
end

#vertical_dpi=(value) ⇒ Object (writeonly)

Sets the attribute vertical_dpi


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

def vertical_dpi=(value)
  @vertical_dpi = value
end

Instance Method Details

#center_horizontallyObject


49
50
51
52
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 49

def center_horizontally
  @print_options_changed = true
  @hcenter               = true
end

#center_verticallyObject


54
55
56
57
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 54

def center_vertically
  @print_options_changed = true
  @vcenter               = true
end

#hide_gridlines(option) ⇒ Object


68
69
70
71
72
73
74
75
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 68

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


42
43
44
45
46
47
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 42

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

59
60
61
62
63
64
65
66
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 59

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

Write the <headerFooter> element.


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

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 <pageMargins> element.


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

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

#write_page_setup(writer) ⇒ Object

Write the <pageSetup> element.

The following is an example taken from Excel.

<pageSetup

paperSize="9"
scale="110"
fitToWidth="2"
fitToHeight="2"
pageOrder="overThenDown"
orientation="portrait"
useFirstPageNumber="1"
blackAndWhite="1"
draft="1"
horizontalDpi="200"
verticalDpi="200"
r:id="rId1"

/>


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

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 << ['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 <printOptions> element.


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

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