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, #ptrue?, #put_deprecate_message, #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:



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

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
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

#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_changed.



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

def header_footer_changed
  @header_footer_changed
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

Parameters:

  • value

    the value to set the attribute page_start to.



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

Instance Method Details

#center_horizontallyObject



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

def center_horizontally
  @print_options_changed = true
  @hcenter               = true
end

#center_verticallyObject



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

def center_vertically
  @print_options_changed = true
  @vcenter               = true
end

#hide_gridlines(option) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 65

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



39
40
41
42
43
44
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 39

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


56
57
58
59
60
61
62
63
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 56

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.



139
140
141
142
143
144
145
146
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 139

def write_header_footer(writer) #:nodoc:
  return unless @header_footer_changed

  writer.tag_elements('headerFooter') do
    write_odd_header(writer) if @header && @header != ''
    write_odd_footer(writer) if @footer && @footer != ''
  end
end

#write_page_margins(writer) ⇒ Object

Write the <pageMargins> element.



118
119
120
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 118

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"

/>



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 94

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 << ['orientation',
                 if @orientation
                   'portrait'
                 else
                   'landscape'
                 end
                ]
  attributes << ['useFirstPageNumber', @page_start] if ptrue?(@page_start)

  writer.empty_tag('pageSetup', attributes)
end

#write_print_options(writer) ⇒ Object

Write the <printOptions> element.



125
126
127
128
129
130
131
132
133
134
# File 'lib/write_xlsx/worksheet/page_setup.rb', line 125

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