axlsx 1.2.0 → 2.0.0

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 (208) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +3 -2
  3. data/.yardopts_guide +19 -0
  4. data/CHANGELOG.md +64 -1
  5. data/README.md +105 -87
  6. data/Rakefile +0 -5
  7. data/examples/2010_comments.rb +17 -0
  8. data/examples/anchor_swapping.rb +28 -0
  9. data/examples/auto_filter.rb +16 -0
  10. data/examples/basic_charts.rb +4 -0
  11. data/examples/colored_links.rb +59 -0
  12. data/examples/conditional_formatting/example_conditional_formatting.rb +4 -2
  13. data/examples/example.rb +569 -258
  14. data/examples/ios_preview.rb +14 -0
  15. data/examples/page_setup.rb +11 -0
  16. data/examples/pivot_table.rb +39 -0
  17. data/examples/skydrive/real_example.rb +8 -8
  18. data/examples/styles.rb +66 -0
  19. data/examples/underline.rb +13 -0
  20. data/examples/wrap_text.rb +21 -0
  21. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  22. data/lib/axlsx/content_type/content_type.rb +1 -1
  23. data/lib/axlsx/content_type/default.rb +6 -37
  24. data/lib/axlsx/content_type/override.rb +6 -38
  25. data/lib/axlsx/doc_props/app.rb +10 -7
  26. data/lib/axlsx/doc_props/core.rb +6 -1
  27. data/lib/axlsx/drawing/axes.rb +61 -0
  28. data/lib/axlsx/drawing/axis.rb +20 -17
  29. data/lib/axlsx/drawing/bar_3D_chart.rb +31 -22
  30. data/lib/axlsx/drawing/cat_axis.rb +2 -10
  31. data/lib/axlsx/drawing/chart.rb +33 -6
  32. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  33. data/lib/axlsx/drawing/drawing.rb +11 -17
  34. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  35. data/lib/axlsx/drawing/hyperlink.rb +42 -36
  36. data/lib/axlsx/drawing/line_3D_chart.rb +28 -70
  37. data/lib/axlsx/drawing/line_chart.rb +99 -0
  38. data/lib/axlsx/drawing/line_series.rb +20 -2
  39. data/lib/axlsx/drawing/marker.rb +38 -18
  40. data/lib/axlsx/drawing/num_data.rb +6 -6
  41. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  42. data/lib/axlsx/drawing/one_cell_anchor.rb +28 -21
  43. data/lib/axlsx/drawing/pic.rb +43 -45
  44. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  45. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -1
  46. data/lib/axlsx/drawing/scaling.rb +13 -13
  47. data/lib/axlsx/drawing/scatter_chart.rb +32 -21
  48. data/lib/axlsx/drawing/ser_axis.rb +15 -16
  49. data/lib/axlsx/drawing/series.rb +3 -6
  50. data/lib/axlsx/drawing/str_data.rb +3 -3
  51. data/lib/axlsx/drawing/str_val.rb +7 -8
  52. data/lib/axlsx/drawing/two_cell_anchor.rb +7 -27
  53. data/lib/axlsx/drawing/val_axis.rb +14 -13
  54. data/lib/axlsx/drawing/view_3D.rb +52 -38
  55. data/lib/axlsx/drawing/vml_shape.rb +20 -79
  56. data/lib/axlsx/package.rb +58 -28
  57. data/lib/axlsx/rels/relationship.rb +75 -9
  58. data/lib/axlsx/rels/relationships.rb +8 -1
  59. data/lib/axlsx/stylesheet/border.rb +29 -20
  60. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  61. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  62. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  63. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  64. data/lib/axlsx/stylesheet/color.rb +20 -17
  65. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  66. data/lib/axlsx/stylesheet/font.rb +22 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  68. data/lib/axlsx/stylesheet/num_fmt.rb +23 -14
  69. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  70. data/lib/axlsx/stylesheet/styles.rb +37 -22
  71. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  72. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  73. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  74. data/lib/axlsx/stylesheet/xf.rb +28 -26
  75. data/lib/axlsx/util/accessors.rb +64 -0
  76. data/lib/axlsx/util/constants.rb +127 -6
  77. data/lib/axlsx/util/options_parser.rb +15 -0
  78. data/lib/axlsx/util/serialized_attributes.rb +79 -0
  79. data/lib/axlsx/util/simple_typed_list.rb +50 -15
  80. data/lib/axlsx/util/validators.rb +51 -16
  81. data/lib/axlsx/version.rb +2 -2
  82. data/lib/axlsx/workbook/defined_name.rb +14 -59
  83. data/lib/axlsx/workbook/shared_strings_table.rb +13 -4
  84. data/lib/axlsx/workbook/workbook.rb +85 -6
  85. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  86. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
  87. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
  88. data/lib/axlsx/workbook/worksheet/break.rb +37 -0
  89. data/lib/axlsx/workbook/worksheet/cell.rb +109 -107
  90. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +144 -0
  91. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  92. data/lib/axlsx/workbook/worksheet/cfvos.rb +15 -0
  93. data/lib/axlsx/workbook/worksheet/col.rb +43 -29
  94. data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
  95. data/lib/axlsx/workbook/worksheet/color_scale.rb +62 -28
  96. data/lib/axlsx/workbook/worksheet/comment.rb +28 -37
  97. data/lib/axlsx/workbook/worksheet/comments.rb +3 -3
  98. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  99. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +31 -27
  100. data/lib/axlsx/workbook/worksheet/data_bar.rb +75 -41
  101. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  102. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +6 -5
  103. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  104. data/lib/axlsx/workbook/worksheet/header_footer.rb +54 -0
  105. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  106. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  107. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
  108. data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
  109. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  110. data/lib/axlsx/workbook/worksheet/pivot_table.rb +273 -0
  111. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -0
  112. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -0
  113. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  114. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  115. data/lib/axlsx/workbook/worksheet/row.rb +59 -83
  116. data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
  117. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  118. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
  119. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +60 -0
  120. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
  121. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  122. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  123. data/lib/axlsx/workbook/worksheet/table.rb +25 -19
  124. data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
  125. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  126. data/lib/axlsx/workbook/worksheet/worksheet.rb +174 -35
  127. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -5
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +4 -10
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -0
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  131. data/lib/axlsx.rb +55 -5
  132. data/lib/schema/sml.xsd +4 -0
  133. data/test/axlsx.qcachegrind +2226 -0
  134. data/test/benchmark.rb +2 -3
  135. data/test/content_type/tc_default.rb +0 -11
  136. data/test/content_type/tc_override.rb +0 -13
  137. data/test/doc_props/tc_core.rb +7 -0
  138. data/test/drawing/tc_axes.rb +8 -0
  139. data/test/drawing/tc_axis.rb +15 -17
  140. data/test/drawing/tc_bar_3D_chart.rb +6 -0
  141. data/test/drawing/tc_cat_axis.rb +9 -9
  142. data/test/drawing/tc_chart.rb +20 -0
  143. data/test/drawing/tc_d_lbls.rb +14 -4
  144. data/test/drawing/tc_drawing.rb +0 -5
  145. data/test/drawing/tc_graphic_frame.rb +5 -3
  146. data/test/drawing/tc_hyperlink.rb +0 -4
  147. data/test/drawing/tc_line_chart.rb +39 -0
  148. data/test/drawing/tc_line_series.rb +8 -2
  149. data/test/drawing/tc_pic.rb +14 -3
  150. data/test/drawing/tc_ser_axis.rb +13 -12
  151. data/test/drawing/tc_two_cell_anchor.rb +3 -3
  152. data/test/drawing/tc_val_axis.rb +6 -6
  153. data/test/drawing/tc_vml_shape.rb +9 -3
  154. data/test/profile.rb +11 -21
  155. data/test/rels/tc_relationship.rb +32 -9
  156. data/test/rels/tc_relationships.rb +12 -1
  157. data/test/stylesheet/tc_color.rb +6 -0
  158. data/test/stylesheet/tc_styles.rb +15 -2
  159. data/test/tc_axlsx.rb +35 -2
  160. data/test/tc_helper.rb +7 -1
  161. data/test/tc_package.rb +44 -5
  162. data/test/util/tc_serialized_attributes.rb +19 -0
  163. data/test/util/tc_validators.rb +26 -1
  164. data/test/workbook/tc_defined_name.rb +2 -2
  165. data/test/workbook/tc_shared_strings_table.rb +6 -0
  166. data/test/workbook/tc_workbook.rb +38 -1
  167. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  168. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  169. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  170. data/test/workbook/worksheet/tc_break.rb +49 -0
  171. data/test/workbook/worksheet/tc_cell.rb +40 -6
  172. data/test/workbook/worksheet/tc_col.rb +11 -1
  173. data/test/workbook/worksheet/tc_color_scale.rb +31 -2
  174. data/test/workbook/worksheet/tc_comment.rb +21 -6
  175. data/test/workbook/worksheet/tc_comments.rb +2 -2
  176. data/test/workbook/worksheet/tc_conditional_formatting.rb +7 -0
  177. data/test/workbook/worksheet/tc_data_bar.rb +7 -0
  178. data/test/workbook/worksheet/tc_date_time_converter.rb +3 -11
  179. data/test/workbook/worksheet/tc_header_footer.rb +151 -0
  180. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  181. data/test/workbook/worksheet/tc_page_setup.rb +6 -1
  182. data/test/workbook/worksheet/tc_pane.rb +5 -45
  183. data/test/workbook/worksheet/tc_pivot_table.rb +120 -0
  184. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +54 -0
  185. data/test/workbook/worksheet/tc_row.rb +4 -4
  186. data/test/workbook/worksheet/tc_selection.rb +9 -48
  187. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  188. data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -0
  189. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  190. data/test/workbook/worksheet/tc_sheet_view.rb +39 -39
  191. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +8 -3
  192. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  193. data/test/workbook/worksheet/tc_worksheet.rb +131 -16
  194. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -0
  195. metadata +97 -64
  196. data/examples/example.xlsx +0 -0
  197. data/examples/example_streamed.xlsx +0 -0
  198. data/examples/extractive.pdf +0 -0
  199. data/examples/image1.gif +0 -0
  200. data/examples/image1.jpg +0 -0
  201. data/examples/image1.png +0 -0
  202. data/examples/no-use_autowidth.xlsx +0 -0
  203. data/examples/sample.png +0 -0
  204. data/examples/scraping_html.rb +0 -91
  205. data/examples/shared_strings_example.xlsx +0 -0
  206. data/examples/sheet_view.rb +0 -34
  207. data/examples/two_cell_anchor_image.rb +0 -11
  208. data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
@@ -7,8 +7,24 @@ module Axlsx
7
7
  # @see ConditionalFormattingRule#initialize
8
8
  class IconSet
9
9
 
10
- # instance values that must be serialized as their own elements - e.g. not attributes.
11
- CHILD_ELEMENTS = [:value_objects]
10
+ include Axlsx::OptionsParser
11
+ include Axlsx::SerializedAttributes
12
+
13
+ # Creates a new icon set object
14
+ # @option options [String] iconSet
15
+ # @option options [Boolean] reverse
16
+ # @option options [Boolean] percent
17
+ # @option options [Boolean] showValue
18
+ def initialize(options = {})
19
+ @percent = @showValue = true
20
+ @reverse = false
21
+ @iconSet = "3TrafficLights1"
22
+ initialize_value_objects
23
+ parse_options options
24
+ yield self if block_given?
25
+ end
26
+
27
+ serializable_attributes :iconSet, :percent, :reverse, :showValue
12
28
 
13
29
  # The icon set to display.
14
30
  # Allowed values are: 3Arrows, 3ArrowsGray, 3Flags, 3TrafficLights1, 3TrafficLights2, 3Signs, 3Symbols, 3Symbols2, 4Arrows, 4ArrowsGray, 4RedToBlack, 4Rating, 4TrafficLights, 5Arrows, 5ArrowsGray, 5Rating, 5Quarters
@@ -31,23 +47,7 @@ module Axlsx
31
47
  # @return [Boolean]
32
48
  attr_reader :showValue
33
49
 
34
- # Creates a new icon set object
35
- # @option options [String] iconSet
36
- # @option options [Boolean] reverse
37
- # @option options [Boolean] percent
38
- # @option options [Boolean] showValue
39
- def initialize(options = {})
40
- @percent = @showValue = true
41
- @reverse = false
42
- @iconSet = "3TrafficLights1"
43
- initialize_value_objects
44
- options.each do |o|
45
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
46
- end
47
- yield self if block_given?
48
- end
49
-
50
- # @see iconSet
50
+ # @see iconSet
51
51
  def iconSet=(v); Axlsx::validate_icon_set(v); @iconSet = v end
52
52
 
53
53
  # @see showValue
@@ -64,7 +64,7 @@ module Axlsx
64
64
  # @return [String]
65
65
  def to_xml_string(str="")
66
66
  str << '<iconSet '
67
- str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ')
67
+ serialized_attributes str
68
68
  str << '>'
69
69
  @value_objects.each { |cfvo| cfvo.to_xml_string(str) }
70
70
  str << '</iconSet>'
@@ -10,6 +10,26 @@ module Axlsx
10
10
  # @see Worksheet#initialize
11
11
  class PageMargins
12
12
 
13
+ include Axlsx::OptionsParser
14
+ include Axlsx::SerializedAttributes
15
+
16
+ # Creates a new PageMargins object
17
+ # @option options [Numeric] left The left margin in inches
18
+ # @option options [Numeric] right The right margin in inches
19
+ # @option options [Numeric] bottom The bottom margin in inches
20
+ # @option options [Numeric] top The top margin in inches
21
+ # @option options [Numeric] header The header margin in inches
22
+ # @option options [Numeric] footer The footer margin in inches
23
+ def initialize(options={})
24
+ # Default values taken from MS Excel for Mac 2011
25
+ @left = @right = DEFAULT_LEFT_RIGHT
26
+ @top = @bottom = DEFAULT_TOP_BOTTOM
27
+ @header = @footer = DEFAULT_HEADER_FOOTER
28
+ parse_options options
29
+ end
30
+
31
+ serializable_attributes :left, :right, :bottom, :top, :header, :footer
32
+
13
33
  # Default left and right margin (in inches)
14
34
  DEFAULT_LEFT_RIGHT = 0.75
15
35
 
@@ -43,24 +63,6 @@ module Axlsx
43
63
  # @return [Float]
44
64
  attr_reader :footer
45
65
 
46
- # Creates a new PageMargins object
47
- # @option options [Numeric] left The left margin in inches
48
- # @option options [Numeric] right The right margin in inches
49
- # @option options [Numeric] bottom The bottom margin in inches
50
- # @option options [Numeric] top The top margin in inches
51
- # @option options [Numeric] header The header margin in inches
52
- # @option options [Numeric] footer The footer margin in inches
53
- def initialize(options={})
54
- # Default values taken from MS Excel for Mac 2011
55
- @left = @right = DEFAULT_LEFT_RIGHT
56
- @top = @bottom = DEFAULT_TOP_BOTTOM
57
- @header = @footer = DEFAULT_HEADER_FOOTER
58
-
59
- options.each do |o|
60
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
61
- end
62
- end
63
-
64
66
  # Set some or all margins at once.
65
67
  # @param [Hash] margins the margins to set (possible keys are :left, :right, :top, :bottom, :header and :footer).
66
68
  def set(margins)
@@ -90,7 +92,7 @@ module Axlsx
90
92
  # @see #custom_margins_specified?
91
93
  def to_xml_string(str = '')
92
94
  str << '<pageMargins '
93
- str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' }.join(' ')
95
+ serialized_attributes str
94
96
  str << '/>'
95
97
  end
96
98
  end
@@ -0,0 +1,44 @@
1
+ module Axlsx
2
+
3
+ # Page setup properties of the worksheet
4
+ # This class name is not a typo, its spec.
5
+ class PageSetUpPr
6
+
7
+ include Axlsx::OptionsParser
8
+ include Axlsx::SerializedAttributes
9
+
10
+ # creates a new page setup properties object
11
+ # @param [Hash] options
12
+ # @option [Boolean] auto_page_breaks Flag indicating whether the sheet displays Automatic Page Breaks.
13
+ # @option [Boolean] fit_to_page Flag indicating whether the Fit to Page print option is enabled.
14
+ def initialize(options = {})
15
+ parse_options options
16
+ end
17
+
18
+ serializable_attributes :auto_page_breaks, :fit_to_page
19
+
20
+ attr_reader :auto_page_breaks
21
+ attr_reader :fit_to_page
22
+
23
+ # Flag indicating whether the Fit to Page print option is enabled.
24
+ # @param [Boolean] value
25
+ # @return [Boolean]
26
+ def fit_to_page=(value)
27
+ Axlsx.validate_boolean value
28
+ @fit_to_page = value
29
+ end
30
+
31
+ # Flag indicating whether the sheet displays Automatic Page Breaks.
32
+ # @param [Boolean] value
33
+ # @return [Boolean]
34
+ def auto_page_breaks=(value)
35
+ Axlsx.validate_boolean value
36
+ @auto_page_breaks = value
37
+ end
38
+
39
+ # serialize to xml
40
+ def to_xml_string(str='')
41
+ str << '<pageSetUpPr ' << serialized_attributes << '/>'
42
+ end
43
+ end
44
+ end
@@ -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