axlsx 1.2.0 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. data/.yardopts +3 -2
  2. data/CHANGELOG.md +34 -1
  3. data/README.md +47 -33
  4. data/Rakefile +1 -1
  5. data/examples/auto_filter.rb +16 -0
  6. data/examples/basic_charts.rb +4 -0
  7. data/examples/colored_links.rb +59 -0
  8. data/examples/doc/_index.html +88 -0
  9. data/examples/doc/class_list.html +53 -0
  10. data/examples/doc/css/common.css +1 -0
  11. data/examples/doc/css/full_list.css +57 -0
  12. data/examples/doc/css/style.css +328 -0
  13. data/examples/doc/file_list.html +52 -0
  14. data/examples/doc/frames.html +28 -0
  15. data/examples/doc/index.html +88 -0
  16. data/examples/doc/js/app.js +214 -0
  17. data/examples/doc/js/full_list.js +173 -0
  18. data/examples/doc/js/jquery.js +4 -0
  19. data/examples/doc/method_list.html +52 -0
  20. data/examples/doc/top-level-namespace.html +102 -0
  21. data/examples/example.rb +447 -257
  22. data/examples/finance.rb +82 -0
  23. data/examples/hyperlinks.rb +23 -0
  24. data/examples/page_setup.rb +11 -0
  25. data/examples/skydrive/axlsx.csv +1 -0
  26. data/examples/skydrive/axlsx.xlsx +0 -0
  27. data/examples/skydrive/real_example.rb +8 -8
  28. data/examples/sprk2012/Screen Shot 2012-09-11 at 10.42.06 PM.png +0 -0
  29. data/examples/sprk2012/Screen Shot 2012-09-11 at 11.07.48 PM.png +0 -0
  30. data/examples/sprk2012/Screen Shot 2012-09-11 at 8.31.50 PM.png +0 -0
  31. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.23.27 PM.png +0 -0
  32. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.32.06 PM.png +0 -0
  33. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.33.35 PM.png +0 -0
  34. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.46.44 PM.png +0 -0
  35. data/examples/sprk2012/Screen Shot 2012-09-12 at 5.07.23 PM.png +0 -0
  36. data/examples/sprk2012/basics.rb +11 -0
  37. data/examples/sprk2012/basics.xlsx +0 -0
  38. data/examples/sprk2012/gravatar.jpeg +0 -0
  39. data/examples/sprk2012/hair_club.jpg +0 -0
  40. data/examples/sprk2012/images.rb +9 -0
  41. data/examples/{example.xlsx → sprk2012/images.xlsx} +0 -0
  42. data/examples/sprk2012/line_chart.rb +56 -0
  43. data/examples/sprk2012/line_chart.xlsx +0 -0
  44. data/examples/sprk2012/sprk2012.key +0 -0
  45. data/examples/sprk2012/styles.rb +20 -0
  46. data/examples/sprk2012/styles.xlsx +0 -0
  47. data/examples/styles.rb +62 -0
  48. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  49. data/lib/axlsx/content_type/content_type.rb +1 -1
  50. data/lib/axlsx/content_type/default.rb +6 -37
  51. data/lib/axlsx/content_type/override.rb +6 -38
  52. data/lib/axlsx/doc_props/app.rb +10 -7
  53. data/lib/axlsx/drawing/axis.rb +4 -4
  54. data/lib/axlsx/drawing/chart.rb +2 -3
  55. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  56. data/lib/axlsx/drawing/drawing.rb +6 -0
  57. data/lib/axlsx/drawing/hyperlink.rb +40 -32
  58. data/lib/axlsx/drawing/marker.rb +13 -13
  59. data/lib/axlsx/drawing/num_data.rb +6 -6
  60. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  61. data/lib/axlsx/drawing/one_cell_anchor.rb +20 -22
  62. data/lib/axlsx/drawing/pic.rb +25 -27
  63. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  64. data/lib/axlsx/drawing/scaling.rb +13 -13
  65. data/lib/axlsx/drawing/scatter_chart.rb +3 -3
  66. data/lib/axlsx/drawing/series.rb +3 -6
  67. data/lib/axlsx/drawing/str_data.rb +3 -3
  68. data/lib/axlsx/drawing/str_val.rb +7 -8
  69. data/lib/axlsx/drawing/view_3D.rb +52 -38
  70. data/lib/axlsx/drawing/vml_shape.rb +23 -23
  71. data/lib/axlsx/package.rb +14 -17
  72. data/lib/axlsx/stylesheet/border.rb +29 -20
  73. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  74. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  75. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  76. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  77. data/lib/axlsx/stylesheet/color.rb +19 -16
  78. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  79. data/lib/axlsx/stylesheet/font.rb +22 -22
  80. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  81. data/lib/axlsx/stylesheet/num_fmt.rb +22 -13
  82. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  83. data/lib/axlsx/stylesheet/styles.rb +11 -2
  84. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  85. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  86. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  87. data/lib/axlsx/stylesheet/xf.rb +28 -26
  88. data/lib/axlsx/util/accessors.rb +49 -0
  89. data/lib/axlsx/util/constants.rb +105 -4
  90. data/lib/axlsx/util/options_parser.rb +15 -0
  91. data/lib/axlsx/util/serialized_attributes.rb +46 -0
  92. data/lib/axlsx/util/simple_typed_list.rb +16 -2
  93. data/lib/axlsx/util/validators.rb +33 -8
  94. data/lib/axlsx/version.rb +2 -2
  95. data/lib/axlsx/workbook/defined_name.rb +13 -58
  96. data/lib/axlsx/workbook/workbook.rb +33 -2
  97. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  98. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
  99. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
  100. data/lib/axlsx/workbook/worksheet/cell.rb +82 -45
  101. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  102. data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -0
  103. data/lib/axlsx/workbook/worksheet/col.rb +34 -27
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +7 -13
  105. data/lib/axlsx/workbook/worksheet/comment.rb +14 -11
  106. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  107. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +27 -25
  108. data/lib/axlsx/workbook/worksheet/data_bar.rb +44 -34
  109. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  110. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -1
  111. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  112. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  113. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  114. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
  115. data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
  116. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  117. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  118. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  119. data/lib/axlsx/workbook/worksheet/row.rb +48 -81
  120. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  121. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
  122. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
  123. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  124. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  125. data/lib/axlsx/workbook/worksheet/table.rb +22 -17
  126. data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
  127. data/lib/axlsx/workbook/worksheet/worksheet.rb +51 -14
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +79 -0
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  131. data/lib/axlsx.rb +19 -5
  132. data/test/content_type/tc_default.rb +0 -11
  133. data/test/content_type/tc_override.rb +0 -13
  134. data/test/drawing/tc_d_lbls.rb +14 -4
  135. data/test/stylesheet/tc_styles.rb +13 -0
  136. data/test/tc_axlsx.rb +20 -2
  137. data/test/tc_package.rb +1 -0
  138. data/test/util/tc_validators.rb +22 -1
  139. data/test/workbook/tc_defined_name.rb +2 -2
  140. data/test/workbook/tc_workbook.rb +15 -0
  141. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  142. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  143. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  144. data/test/workbook/worksheet/tc_cell.rb +35 -5
  145. data/test/workbook/worksheet/tc_col.rb +11 -1
  146. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  147. data/test/workbook/worksheet/tc_page_setup.rb +6 -1
  148. data/test/workbook/worksheet/tc_pane.rb +5 -45
  149. data/test/workbook/worksheet/tc_row.rb +4 -4
  150. data/test/workbook/worksheet/tc_selection.rb +9 -48
  151. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  152. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  153. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +6 -1
  154. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  155. data/test/workbook/worksheet/tc_worksheet.rb +17 -3
  156. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +64 -0
  157. metadata +74 -10
  158. data/examples/example_streamed.xlsx +0 -0
  159. data/examples/no-use_autowidth.xlsx +0 -0
  160. data/examples/shared_strings_example.xlsx +0 -0
  161. data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
@@ -6,8 +6,24 @@ module Axlsx
6
6
  # @see Worksheet#initialize
7
7
  class PageSetup
8
8
 
9
+ include Axlsx::OptionsParser
10
+ include Axlsx::SerializedAttributes
11
+
12
+ # Creates a new PageSetup object
13
+ # @option options [Integer] fit_to_height Number of vertical pages to fit on
14
+ # @option options [Integer] fit_to_width Number of horizontal pages to fit on
15
+ # @option options [Symbol] orientation Orientation of the page (:default, :landscape, :portrait)
16
+ # @option options [String] paper_height Height of paper (number followed by unit identifier: "297mm", "11in")
17
+ # @option options [String] paper_width Width of paper (number followed by unit identifier: "210mm", "8.5in")
18
+ # @option options [Integer] scale Print scaling (percent value, integer ranging from 10 to 400)
19
+ # @option options [Integer] paper_size - the size of paper to use
20
+ def initialize(options = {})
21
+ parse_options options
22
+ end
23
+
24
+ serializable_attributes :fit_to_height, :fit_to_width, :orientation, :paper_height, :paper_width, :scale, :paper_size
25
+
9
26
  # TODO: Attributes defined by Open XML spec that are not implemented yet:
10
- #
11
27
  # * blackAndWhite
12
28
  # * cellComments
13
29
  # * copies
@@ -16,15 +32,14 @@ module Axlsx
16
32
  # * firstPageNumber
17
33
  # * horizontalDpi
18
34
  # * pageOrder
19
- # * paperSize
20
35
  # * useFirstPageNumber
21
36
  # * usePrinterDefaults
22
37
  # * verticalDpi
23
-
38
+
24
39
  # Number of vertical pages to fit on.
25
40
  # @note PageSetup#fit_to is the recomended way to manage page fitting as only specifying one of fit_to_width/fit_to_height will result in the counterpart
26
41
  # being set to 1.
27
- # @return [Integer]
42
+ # @return [Integer]
28
43
  attr_reader :fit_to_height
29
44
 
30
45
  # Number of horizontal pages to fit on.
@@ -36,7 +51,7 @@ module Axlsx
36
51
  # Orientation of the page (:default, :landscape, :portrait)
37
52
  # @return [Symbol]
38
53
  attr_reader :orientation
39
-
54
+
40
55
  # Height of paper (string containing a number followed by a unit identifier: "297mm", "11in")
41
56
  # @return [String]
42
57
  attr_reader :paper_height
@@ -44,28 +59,142 @@ module Axlsx
44
59
  # Width of paper (string containing a number followed by a unit identifier: "210mm", "8.5in")
45
60
  # @return [String]
46
61
  attr_reader :paper_width
47
-
62
+
48
63
  # Print scaling (percent value, given as integer ranging from 10 to 400)
49
64
  # @return [Integer]
50
65
  attr_reader :scale
51
66
 
52
- # Creates a new PageSetup object
53
- # @option options [Integer] fit_to_height Number of vertical pages to fit on
54
- # @option options [Integer] fit_to_width Number of horizontal pages to fit on
55
- # @option options [Symbol] orientation Orientation of the page (:default, :landscape, :portrait)
56
- # @option options [String] paper_height Height of paper (number followed by unit identifier: "297mm", "11in")
57
- # @option options [String] paper_width Width of paper (number followed by unit identifier: "210mm", "8.5in")
58
- # @option options [Integer] scale Print scaling (percent value, integer ranging from 10 to 400)
59
- def initialize(options = {})
60
- set(options)
67
+ # The paper size to use in printing
68
+ #1 = Letter paper (8.5 in. by 11 in.)
69
+ #2 = Letter small paper (8.5 in. by 11 in.)
70
+ #3 = Tabloid paper (11 in. by 17 in.)
71
+ #4 = Ledger paper (17 in. by 11 in.)
72
+ #5 = Legal paper (8.5 in. by 14 in.)
73
+ #6 = Statement paper (5.5 in. by 8.5 in.)
74
+ #7 = Executive paper (7.25 in. by 10.5 in.)
75
+ #8 = A3 paper (297 mm by 420 mm)
76
+ #9 = A4 paper (210 mm by 297 mm)
77
+ #10 = A4 small paper (210 mm by 297 mm)
78
+ #11 = A5 paper (148 mm by 210 mm)
79
+ #12 = B4 paper (250 mm by 353 mm)
80
+ #13 = B5 paper (176 mm by 250 mm)
81
+ #14 = Folio paper (8.5 in. by 13 in.)
82
+ #15 = Quarto paper (215 mm by 275 mm)
83
+ #16 = Standard paper (10 in. by 14 in.)
84
+ #17 = Standard paper (11 in. by 17 in.)
85
+ #18 = Note paper (8.5 in. by 11 in.)
86
+ #19 = #9 envelope (3.875 in. by 8.875 in.)
87
+ #20 = #10 envelope (4.125 in. by 9.5 in.)
88
+ #21 = #11 envelope (4.5 in. by 10.375 in.)
89
+ #22 = #12 envelope (4.75 in. by 11 in.)
90
+ #23 = #14 envelope (5 in. by 11.5 in.) 24 = C paper (17 in. by 22 in.)
91
+ #25 = D paper (22 in. by 34 in.)
92
+ #26 = E paper (34 in. by 44 in.)
93
+ #27 = DL envelope (110 mm by 220 mm)
94
+ #28 = C5 envelope (162 mm by 229 mm)
95
+ #29 = C3 envelope (324 mm by 458 mm)
96
+ #30 = C4 envelope (229 mm by 324 mm)
97
+ #31 = C6 envelope (114 mm by 162 mm)
98
+ #32 = C65 envelope (114 mm by 229 mm)
99
+ #33 = B4 envelope (250 mm by 353 mm)
100
+ #34 = B5 envelope (176 mm by 250 mm)
101
+ #35 = B6 envelope (176 mm by 125 mm)
102
+ #36 = Italy envelope (110 mm by 230 mm)
103
+ #37 = Monarch envelope (3.875 in. by 7.5 in.). 38 = 6 3/4 envelope (3.625 in. by 6.5 in.)
104
+ #39 = US standard fanfold (14.875 in. by 11 in.)
105
+ #40 = German standard fanfold (8.5 in. by 12 in.)
106
+ #41 = German legal fanfold (8.5 in. by 13 in.)
107
+ #42 = ISO B4 (250 mm by 353 mm)
108
+ #43 = Japanese double postcard (200 mm by 148 mm)
109
+ #44 = Standard paper (9 in. by 11 in.)
110
+ #45 = Standard paper (10 in. by 11 in.)
111
+ #46 = Standard paper (15 in. by 11 in.)
112
+ #47 = Invite envelope (220 mm by 220 mm)
113
+ #50 = Letter extra paper (9.275 in. by 12 in.)
114
+ #51 = Legal extra paper (9.275 in. by 15 in.)
115
+ #52 = Tabloid extra paper (11.69 in. by 18 in.)
116
+ #53 = A4 extra paper (236 mm by 322 mm)
117
+ #54 = Letter transverse paper (8.275 in. by 11 in.)
118
+ #55 = A4 transverse paper (210 mm by 297 mm)
119
+ #56 = Letter extra transverse paper (9.275 in. by 12 in.)
120
+ #57 = SuperA/SuperA/A4 paper (227 mm by 356 mm)
121
+ #58 = SuperB/SuperB/A3 paper (305 mm by 487 mm)
122
+ #59 = Letter plus paper (8.5 in. by 12.69 in.)
123
+ #60 = A4 plus paper (210 mm by 330 mm)
124
+ #61 = A5 transverse paper (148 mm by 210 mm)
125
+ #62 = JIS B5 transverse paper (182 mm by 257 mm)
126
+ #63 = A3 extra paper (322 mm by 445 mm)
127
+ #64 = A5 extra paper (174 mm by 235 mm)
128
+ #65 = ISO B5 extra paper (201 mm by 276 mm)
129
+ #66 = A2 paper (420 mm by 594 mm)
130
+ #67 = A3 transverse paper (297 mm by 420 mm)
131
+ #68 = A3 extra transverse paper (322 mm by 445 mm)
132
+ #69 = Japanese Double Postcard (200 mm x 148 mm)
133
+ #70 = A6 (105 mm x 148 mm
134
+ #71 = Japanese Envelope Kaku #2
135
+ #72 = Japanese Envelope Kaku #3
136
+ #73 = Japanese Envelope Chou #3
137
+ #74 = Japanese Envelope Chou #4
138
+ #75 = Letter Rotated (11in x 8 1/2 11 in)
139
+ #76 = A3 Rotated (420 mm x 297 mm)
140
+ #77 = A4 Rotated (297 mm x 210 mm)
141
+ #78 = A5 Rotated (210 mm x 148 mm)
142
+ #79 = B4 (JIS) Rotated (364 mm x 257 mm)
143
+ #80 = B5 (JIS) Rotated (257 mm x 182 mm)
144
+ #81 = Japanese Postcard Rotated (148 mm x 100 mm)
145
+ #82 = Double Japanese Postcard Rotated (148 mm x 200 mm)
146
+ #83 = A6 Rotated (148 mm x 105 mm)
147
+ #84 = Japanese Envelope Kaku #2 Rotated
148
+ #85 = Japanese Envelope Kaku #3 Rotated
149
+ #86 = Japanese Envelope Chou #3 Rotated
150
+ #87 = Japanese Envelope Chou #4 Rotated
151
+ #88 = B6 (JIS) (128 mm x 182 mm)
152
+ #89 = B6 (JIS) Rotated (182 mm x 128 mm)
153
+ #90 = (12 in x 11 in)
154
+ #91 = Japanese Envelope You #4
155
+ #92 = Japanese Envelope You #4 Rotated
156
+ #93 = PRC 16K (146 mm x 215 mm)
157
+ #94 = PRC 32K (97 mm x 151 mm)
158
+ #95 = PRC 32K(Big) (97 mm x 151 mm)
159
+ #96 = PRC Envelope #1 (102 mm x 165 mm)
160
+ #97 = PRC Envelope #2 (102 mm x 176 mm)
161
+ #98 = PRC Envelope #3 (125 mm x 176 mm)
162
+ #99 = PRC Envelope #4 (110 mm x 208 mm)
163
+ #100 = PRC Envelope #5 (110 mm x 220 mm)
164
+ #101 = PRC Envelope #6 (120 mm x 230 mm)
165
+ #102 = PRC Envelope #7 (160 mm x 230 mm)
166
+ #103 = PRC Envelope #8 (120 mm x 309 mm)
167
+ #104 = PRC Envelope #9 (229 mm x 324 mm)
168
+ #105 = PRC Envelope #10 (324 mm x 458 mm)
169
+ #106 = PRC 16K Rotated
170
+ #107 = PRC 32K Rotated
171
+ #108 = PRC 32K(Big) Rotated
172
+ #109 = PRC Envelope #1 Rotated (165 mm x 102 mm)
173
+ #110 = PRC Envelope #2 Rotated (176 mm x 102 mm)
174
+ #111 = PRC Envelope #3 Rotated (176 mm x 125 mm)
175
+ #112 = PRC Envelope #4 Rotated (208 mm x 110 mm)
176
+ #113 = PRC Envelope #5 Rotated (220 mm x 110 mm)
177
+ #114 = PRC Envelope #6 Rotated (230 mm x 120 mm)
178
+ #115 = PRC Envelope #7 Rotated (230 mm x 160 mm)
179
+ #116 = PRC Envelope #8 Rotated (309 mm x 120 mm)
180
+ #117 = PRC Envelope #9 Rotated (324 mm x 229 mm)
181
+ #118 = PRC Envelope #10 Rotated (458 mm x 324 mm)
182
+ # @return [Integer]
183
+ attr_reader :paper_size
184
+
185
+
186
+ # Sets the paper size for printing.
187
+ # @see PageSetup#paper_size
188
+ # @return integer
189
+ def paper_size=(size)
190
+ RestrictionValidator.validate 'paper_size', (1..118), size
191
+ @paper_size = size
61
192
  end
62
193
 
63
- # Set some or all page settings at once.
194
+ # Set some or all page settings at once.
64
195
  # @param [Hash] options The page settings to set (possible keys are :fit_to_height, :fit_to_width, :orientation, :paper_height, :paper_width, and :scale).
65
196
  def set(options)
66
- options.each do |k, v|
67
- send("#{k}=", v) if respond_to? "#{k}="
68
- end
197
+ parse_options options
69
198
  end
70
199
 
71
200
  # @see fit_to_height
@@ -80,7 +209,7 @@ module Axlsx
80
209
  def paper_width=(v); Axlsx::validate_number_with_unit(v); @paper_width = v; end
81
210
  # @see scale
82
211
  def scale=(v); Axlsx::validate_scale_10_400(v); @scale = v; end
83
-
212
+
84
213
  # convenience method to achieve sanity when setting fit_to_width and fit_to_height
85
214
  # as they both default to 1 if only their counterpart is specified.
86
215
  # @note This method will overwrite any value you explicitly set via the fit_to_height or fit_to_width methods.
@@ -97,8 +226,8 @@ module Axlsx
97
226
  # We treat any page set up that has a value set for fit_to_width or fit_to_height value as fit_to_page.
98
227
  # @return [Boolean]
99
228
  def fit_to_page?
100
- # is there some better what to express this?
101
- (fit_to_width != nil || fit_to_height != nil)
229
+ # is there some better what to express this?
230
+ (fit_to_width != nil || fit_to_height != nil)
102
231
  end
103
232
 
104
233
  # Serializes the page settings element.
@@ -106,7 +235,7 @@ module Axlsx
106
235
  # @return [String]
107
236
  def to_xml_string(str = '')
108
237
  str << '<pageSetup '
109
- str << instance_values.reject{ |k, v| k == 'worksheet' }.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v}"} }.join(' ')
238
+ serialized_attributes str
110
239
  str << '/>'
111
240
  end
112
241
  end
@@ -1,11 +1,27 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # Pane options for a worksheet.
4
3
  #
5
4
  # @note The recommended way to manage the pane options is via SheetView#pane
6
5
  # @see SheetView#pane
7
6
  class Pane
8
-
7
+
8
+ include Axlsx::OptionsParser
9
+ include Axlsx::SerializedAttributes
10
+ # Creates a new {Pane} object
11
+ # @option options [Symbol] active_pane Active Pane
12
+ # @option options [Symbol] state Split State
13
+ # @option options [Cell, String] top_left_cell Top Left Visible Cell
14
+ # @option options [Integer] x_split Horizontal Split Position
15
+ # @option options [Integer] y_split Vertical Split Position
16
+ def initialize(options={})
17
+ #defaults
18
+ @active_pane = @state = @top_left_cell = nil
19
+ @x_split = @y_split = 0
20
+ parse_options options
21
+ end
22
+
23
+ serializable_attributes :active_pane, :state, :top_left_cell, :x_split, :y_split
24
+
9
25
  # Active Pane
10
26
  # The pane that is active.
11
27
  # Options are
@@ -32,8 +48,8 @@ module Axlsx
32
48
  # @return [Symbol]
33
49
  # default nil
34
50
  attr_reader :active_pane
35
-
36
-
51
+
52
+
37
53
  # Split State
38
54
  # Indicates whether the pane has horizontal / vertical
39
55
  # splits, and whether those splits are frozen.
@@ -51,8 +67,7 @@ module Axlsx
51
67
  # @return [Symbol]
52
68
  # default nil
53
69
  attr_reader :state
54
-
55
-
70
+
56
71
  # Top Left Visible Cell
57
72
  # Location of the top left visible cell in the bottom
58
73
  # right pane (when in Left-To-Right mode).
@@ -60,8 +75,7 @@ module Axlsx
60
75
  # @return [String]
61
76
  # default nil
62
77
  attr_reader :top_left_cell
63
-
64
-
78
+
65
79
  # Horizontal Split Position
66
80
  # Horizontal position of the split, in 1/20th of a point; 0 (zero)
67
81
  # if none. If the pane is frozen, this value indicates the number
@@ -70,8 +84,7 @@ module Axlsx
70
84
  # @return [Integer]
71
85
  # default 0
72
86
  attr_reader :x_split
73
-
74
-
87
+
75
88
  # Vertical Split Position
76
89
  # Vertical position of the split, in 1/20th of a point; 0 (zero)
77
90
  # if none. If the pane is frozen, this value indicates the number
@@ -80,65 +93,49 @@ module Axlsx
80
93
  # @return [Integer]
81
94
  # default 0
82
95
  attr_reader :y_split
83
-
84
-
85
- # Creates a new {Pane} object
86
- # @option options [Symbol] active_pane Active Pane
87
- # @option options [Symbol] state Split State
88
- # @option options [Cell, String] top_left_cell Top Left Visible Cell
89
- # @option options [Integer] x_split Horizontal Split Position
90
- # @option options [Integer] y_split Vertical Split Position
91
- def initialize(options={})
92
- #defaults
93
- @active_pane = @state = @top_left_cell = nil
94
- @x_split = @y_split = 0
95
-
96
- # write options to instance variables
97
- options.each do |o|
98
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
99
- end
100
- end
101
-
102
-
96
+
103
97
  # @see active_pane
104
- def active_pane=(v); Axlsx::validate_pane_type(v); @active_pane = v end
105
-
106
-
98
+ def active_pane=(v)
99
+ Axlsx::validate_pane_type(v)
100
+ @active_pane = Axlsx::camel(v.to_s, false)
101
+ end
102
+
107
103
  # @see state
108
- def state=(v); Axlsx::validate_split_state_type(v); @state = v end
109
-
110
-
104
+ def state=(v)
105
+ Axlsx::validate_split_state_type(v)
106
+ @state = Axlsx::camel(v.to_s, false)
107
+ end
108
+
111
109
  # @see top_left_cell
112
110
  def top_left_cell=(v)
113
111
  cell = (v.class == Axlsx::Cell ? v.r_abs : v)
114
- Axlsx::validate_string(cell)
115
- @top_left_cell = cell
112
+ Axlsx::validate_string(cell)
113
+ @top_left_cell = cell
116
114
  end
117
-
118
-
115
+
119
116
  # @see x_split
120
117
  def x_split=(v); Axlsx::validate_unsigned_int(v); @x_split = v end
121
-
122
-
118
+
123
119
  # @see y_split
124
120
  def y_split=(v); Axlsx::validate_unsigned_int(v); @y_split = v end
125
-
126
-
121
+
127
122
  # Serializes the data validation
128
123
  # @param [String] str
129
124
  # @return [String]
130
125
  def to_xml_string(str = '')
131
- if @state == :frozen && @top_left_cell.nil?
126
+ finalize
127
+ str << '<pane '
128
+ serialized_attributes str
129
+ str << '/>'
130
+ end
131
+ private
132
+
133
+ def finalize
134
+ if @state == 'frozen' && @top_left_cell.nil?
132
135
  row = @y_split || 0
133
136
  column = @x_split || 0
134
-
135
137
  @top_left_cell = "#{('A'..'ZZ').to_a[column]}#{row+1}"
136
138
  end
137
-
138
- str << '<pane '
139
- str << instance_values.map { |key, value| '' << key.gsub(/_(.)/){ $1.upcase } <<
140
- %{="#{[:active_pane, :state].include?(key.to_sym) ? value.to_s.gsub(/_(.)/){ $1.upcase } : value}"} unless value.nil? }.join(' ')
141
- str << '/>'
142
139
  end
143
140
  end
144
141
  end
@@ -6,22 +6,9 @@ module Axlsx
6
6
  # @see Worksheet#initialize
7
7
  class PrintOptions
8
8
 
9
- # Whether grid lines should be printed.
10
- # @return [Boolean]
11
- attr_reader :grid_lines
12
-
13
- # Whether row and column headings should be printed.
14
- # @return [Boolean]
15
- attr_reader :headings
16
-
17
- # Whether the content should be centered horizontally on the page.
18
- # @return [Boolean]
19
- attr_reader :horizontal_centered
20
-
21
- # Whether the content should be centered vertically on the page.
22
- # @return [Boolean]
23
- attr_reader :vertical_centered
24
-
9
+ include Axlsx::OptionsParser
10
+ include Axlsx::SerializedAttributes
11
+ include Axlsx::Accessors
25
12
  # Creates a new PrintOptions object
26
13
  # @option options [Boolean] grid_lines Whether grid lines should be printed
27
14
  # @option options [Boolean] headings Whether row and column headings should be printed
@@ -32,31 +19,22 @@ module Axlsx
32
19
  set(options)
33
20
  end
34
21
 
22
+ serializable_attributes :grid_lines, :headings, :horizontal_centered, :vertical_centered
23
+ boolean_attr_accessor :grid_lines, :headings, :horizontal_centered, :vertical_centered
24
+
35
25
  # Set some or all options at once.
36
26
  # @param [Hash] options The options to set (possible keys are :grid_lines, :headings, :horizontal_centered, and :vertical_centered).
37
27
  def set(options)
38
- options.each do |k, v|
39
- send("#{k}=", v) if respond_to? "#{k}="
40
- end
28
+ parse_options options
41
29
  end
42
30
 
43
- # @see grid_lines
44
- def grid_lines=(v); Axlsx::validate_boolean(v); @grid_lines = v; end
45
- # @see headings
46
- def headings=(v); Axlsx::validate_boolean(v); @headings = v; end
47
- # @see horizontal_centered
48
- def horizontal_centered=(v); Axlsx::validate_boolean(v); @horizontal_centered = v; end
49
- # @see vertical_centered
50
- def vertical_centered=(v); Axlsx::validate_boolean(v); @vertical_centered = v; end
51
-
52
31
  # Serializes the page options element.
53
32
  # @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.
54
33
  # @param [String] str
55
34
  # @return [String]
56
35
  def to_xml_string(str = '')
57
36
  str << '<printOptions '
58
- #
59
- str << instance_values.select{ |k,v| v == true }.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v}"} }.join(' ')
37
+ serialized_attributes str
60
38
  str << '/>'
61
39
  end
62
40
  end
@@ -4,6 +4,18 @@ module Axlsx
4
4
  # @see Worksheet#protect_range
5
5
  class ProtectedRange
6
6
 
7
+ include Axlsx::OptionsParser
8
+ include Axlsx::SerializedAttributes
9
+
10
+ # Initializes a new protected range object
11
+ # @option [String] sqref The cell range reference to protect. This can be an absolute or a relateve range however, it only applies to the current sheet.
12
+ # @option [String] name An optional name for the protected name.
13
+ def initialize(options={})
14
+ parse_options options
15
+ yield self if block_given?
16
+ end
17
+
18
+ serializable_attributes :sqref, :name
7
19
  # The reference for the protected range
8
20
  # @return [String]
9
21
  attr_reader :sqref
@@ -12,16 +24,6 @@ module Axlsx
12
24
  # @return [String]
13
25
  attr_reader :name
14
26
 
15
- # Initializes a new protected range object
16
- # @option [String] sqref The cell range reference to protect. This can be an absolute or a relateve range however, it only applies to the current sheet.
17
- # @option [String] name An optional name for the protected name.
18
- def initialize(options={})
19
- options.each do |o|
20
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
21
- end
22
- yield self if block_given?
23
- end
24
-
25
27
  # @see sqref
26
28
  def sqref=(v)
27
29
  Axlsx.validate_string(v)
@@ -33,14 +35,15 @@ module Axlsx
33
35
  Axlsx.validate_string(v)
34
36
  @name = v
35
37
  end
36
-
38
+
37
39
  # serializes the proteted range
38
40
  # @param [String] str if this string object is provided we append
39
41
  # our output to that object. Use this - it helps limit the number of
40
42
  # objects created during serialization
41
43
  def to_xml_string(str="")
42
- attrs = self.instance_values.reject{ |key, value| value == nil }
43
- str << '<protectedRange ' << attrs.map { |key, value| '' << key << '="' << value.to_s << '"' }.join(' ') << '/>'
44
+ str << '<protectedRange '
45
+ serialized_attributes str
46
+ str << '/>'
44
47
  end
45
48
  end
46
49
  end