axlsx 1.1.4 → 1.3.1

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 (242) hide show
  1. data/.yardopts +6 -2
  2. data/CHANGELOG.md +72 -0
  3. data/README.md +114 -31
  4. data/Rakefile +11 -3
  5. data/examples/auto_filter.rb +16 -0
  6. data/examples/auto_filter.xlsx +0 -0
  7. data/examples/basic_charts.rb +58 -0
  8. data/examples/chart_colors.rb +17 -2
  9. data/examples/data_validation.rb +50 -0
  10. data/examples/example.rb +171 -60
  11. data/examples/example.xlsx +0 -0
  12. data/examples/example_streamed.xlsx +0 -0
  13. data/examples/extractive.pdf +0 -0
  14. data/examples/extractive.rb +3 -0
  15. data/examples/extractive.xlsx +0 -0
  16. data/examples/hyperlinks.rb +23 -0
  17. data/examples/hyperlinks.xlsx +0 -0
  18. data/examples/no-use_autowidth.xlsx +0 -0
  19. data/examples/page_setup.rb +11 -0
  20. data/examples/page_setup.xlsx +0 -0
  21. data/examples/scraping_html.rb +91 -0
  22. data/examples/shared_strings_example.xlsx +0 -0
  23. data/examples/sheet_protection.rb +10 -0
  24. data/examples/sheet_view.rb +34 -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/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/examples/styles.xlsx +0 -0
  49. data/examples/two_cell_anchor_image.rb +11 -0
  50. data/lib/axlsx/content_type/content_type.rb +2 -0
  51. data/lib/axlsx/content_type/default.rb +30 -15
  52. data/lib/axlsx/content_type/override.rb +29 -14
  53. data/lib/axlsx/doc_props/app.rb +161 -104
  54. data/lib/axlsx/doc_props/core.rb +9 -5
  55. data/lib/axlsx/drawing/ax_data_source.rb +7 -6
  56. data/lib/axlsx/drawing/axis.rb +82 -36
  57. data/lib/axlsx/drawing/bar_3D_chart.rb +49 -45
  58. data/lib/axlsx/drawing/bar_series.rb +2 -1
  59. data/lib/axlsx/drawing/cat_axis.rb +43 -39
  60. data/lib/axlsx/drawing/chart.rb +65 -54
  61. data/lib/axlsx/drawing/d_lbls.rb +100 -0
  62. data/lib/axlsx/drawing/drawing.rb +20 -8
  63. data/lib/axlsx/drawing/graphic_frame.rb +2 -1
  64. data/lib/axlsx/drawing/line_3D_chart.rb +3 -10
  65. data/lib/axlsx/drawing/num_data.rb +2 -2
  66. data/lib/axlsx/drawing/num_data_source.rb +4 -1
  67. data/lib/axlsx/drawing/pic.rb +44 -4
  68. data/lib/axlsx/drawing/pie_3D_chart.rb +10 -7
  69. data/lib/axlsx/drawing/scatter_chart.rb +2 -8
  70. data/lib/axlsx/drawing/title.rb +21 -9
  71. data/lib/axlsx/drawing/two_cell_anchor.rb +46 -9
  72. data/lib/axlsx/drawing/view_3D.rb +42 -32
  73. data/lib/axlsx/drawing/vml_drawing.rb +42 -0
  74. data/lib/axlsx/drawing/vml_shape.rb +125 -0
  75. data/lib/axlsx/package.rb +43 -16
  76. data/lib/axlsx/rels/relationship.rb +3 -3
  77. data/lib/axlsx/rels/relationships.rb +1 -11
  78. data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
  79. data/lib/axlsx/stylesheet/styles.rb +11 -2
  80. data/lib/axlsx/stylesheet/table_style.rb +3 -3
  81. data/lib/axlsx/util/constants.rb +131 -2
  82. data/lib/axlsx/util/simple_typed_list.rb +18 -22
  83. data/lib/axlsx/util/validators.rb +100 -9
  84. data/lib/axlsx/version.rb +2 -7
  85. data/lib/axlsx/workbook/defined_name.rb +174 -0
  86. data/lib/axlsx/workbook/defined_names.rb +21 -0
  87. data/lib/axlsx/workbook/workbook.rb +70 -13
  88. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  89. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +102 -0
  90. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +253 -0
  91. data/lib/axlsx/workbook/worksheet/cell.rb +41 -8
  92. data/lib/axlsx/workbook/worksheet/col.rb +15 -0
  93. data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
  94. data/lib/axlsx/workbook/worksheet/comment.rb +101 -0
  95. data/lib/axlsx/workbook/worksheet/comments.rb +85 -0
  96. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
  97. data/lib/axlsx/workbook/worksheet/data_bar.rb +1 -1
  98. data/lib/axlsx/workbook/worksheet/data_validation.rb +245 -0
  99. data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
  100. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -1
  101. data/lib/axlsx/workbook/worksheet/dimension.rb +65 -0
  102. data/lib/axlsx/workbook/worksheet/merged_cells.rb +35 -0
  103. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +47 -0
  104. data/lib/axlsx/workbook/worksheet/page_setup.rb +241 -0
  105. data/lib/axlsx/workbook/worksheet/pane.rb +144 -0
  106. data/lib/axlsx/workbook/worksheet/print_options.rb +63 -0
  107. data/lib/axlsx/workbook/worksheet/protected_range.rb +46 -0
  108. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
  109. data/lib/axlsx/workbook/worksheet/row.rb +36 -20
  110. data/lib/axlsx/workbook/worksheet/selection.rb +111 -0
  111. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +49 -0
  112. data/lib/axlsx/workbook/worksheet/sheet_data.rb +25 -0
  113. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +107 -0
  114. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +224 -0
  115. data/lib/axlsx/workbook/worksheet/sheet_view.rb +379 -0
  116. data/lib/axlsx/workbook/worksheet/table.rb +10 -3
  117. data/lib/axlsx/workbook/worksheet/table_style_info.rb +68 -0
  118. data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
  119. data/lib/axlsx/workbook/worksheet/worksheet.rb +414 -254
  120. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +57 -0
  121. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +64 -0
  122. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +101 -0
  123. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  124. data/lib/axlsx.rb +38 -16
  125. data/test/content_type/tc_content_type.rb +1 -6
  126. data/test/doc_props/tc_app.rb +31 -1
  127. data/test/doc_props/tc_core.rb +3 -1
  128. data/test/drawing/tc_axis.rb +38 -3
  129. data/test/drawing/tc_bar_3D_chart.rb +12 -12
  130. data/test/drawing/tc_bar_series.rb +1 -2
  131. data/test/drawing/tc_cat_axis.rb +3 -3
  132. data/test/drawing/tc_chart.rb +29 -9
  133. data/test/drawing/tc_d_lbls.rb +47 -0
  134. data/test/drawing/tc_drawing.rb +11 -5
  135. data/test/drawing/tc_hyperlink.rb +4 -5
  136. data/test/drawing/tc_line_series.rb +7 -3
  137. data/test/drawing/tc_num_data.rb +5 -1
  138. data/test/drawing/tc_pic.rb +22 -2
  139. data/test/drawing/tc_pie_3D_chart.rb +4 -8
  140. data/test/drawing/tc_pie_series.rb +7 -2
  141. data/test/drawing/tc_scatter_chart.rb +6 -1
  142. data/test/drawing/tc_scatter_series.rb +1 -1
  143. data/test/drawing/tc_series.rb +1 -1
  144. data/test/drawing/tc_title.rb +16 -0
  145. data/test/drawing/tc_two_cell_anchor.rb +1 -2
  146. data/test/drawing/tc_view_3D.rb +18 -18
  147. data/test/drawing/tc_vml_drawing.rb +25 -0
  148. data/test/drawing/tc_vml_shape.rb +100 -0
  149. data/test/rels/tc_relationship.rb +1 -0
  150. data/test/stylesheet/tc_gradient_fill.rb +8 -0
  151. data/test/stylesheet/tc_pattern_fill.rb +7 -1
  152. data/test/stylesheet/tc_styles.rb +16 -4
  153. data/test/stylesheet/tc_table_style.rb +8 -0
  154. data/test/stylesheet/tc_table_style_element.rb +10 -1
  155. data/test/tc_helper.rb +1 -0
  156. data/test/tc_package.rb +94 -17
  157. data/test/util/tc_simple_typed_list.rb +13 -0
  158. data/test/util/tc_validators.rb +101 -8
  159. data/test/workbook/tc_defined_name.rb +41 -0
  160. data/test/workbook/tc_workbook.rb +5 -3
  161. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  162. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  163. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  164. data/test/workbook/worksheet/tc_cell.rb +53 -7
  165. data/test/workbook/worksheet/tc_col.rb +9 -0
  166. data/test/workbook/worksheet/tc_comment.rb +57 -0
  167. data/test/workbook/worksheet/tc_comments.rb +57 -0
  168. data/test/workbook/worksheet/tc_conditional_formatting.rb +44 -0
  169. data/test/workbook/worksheet/tc_data_bar.rb +1 -1
  170. data/test/workbook/worksheet/tc_data_validation.rb +265 -0
  171. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  172. data/test/workbook/worksheet/tc_page_setup.rb +143 -0
  173. data/test/workbook/worksheet/tc_pane.rb +94 -0
  174. data/test/workbook/worksheet/tc_print_options.rb +72 -0
  175. data/test/workbook/worksheet/tc_protected_range.rb +17 -0
  176. data/test/workbook/worksheet/tc_row.rb +32 -14
  177. data/test/workbook/worksheet/tc_selection.rb +94 -0
  178. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  179. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  180. data/test/workbook/worksheet/tc_sheet_protection.rb +117 -0
  181. data/test/workbook/worksheet/tc_sheet_view.rb +214 -0
  182. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +9 -12
  183. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  184. data/test/workbook/worksheet/tc_worksheet.rb +155 -51
  185. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +64 -0
  186. metadata +194 -81
  187. data/examples/#extractive.csv# +0 -0
  188. data/examples/#extractive.rb# +0 -45
  189. data/examples/chart_colors.rb~ +0 -0
  190. data/examples/chart_colors.xlsx +0 -0
  191. data/examples/colored_series_data.xlsx +0 -0
  192. data/examples/conditional_formatting/getting_barred.xlsx +0 -0
  193. data/examples/example.csv +0 -1000
  194. data/examples/extractive.csv +0 -1
  195. data/examples/extractive.csv~ +0 -1
  196. data/examples/extractive.rb~ +0 -3
  197. data/examples/stack.rb +0 -21
  198. data/examples/stack.rb~ +0 -27
  199. data/examples/stack.xlsx +0 -0
  200. data/examples/~$chart_colors.xlsx +0 -0
  201. data/examples/~$extractive.xlsx +0 -0
  202. data/lib/axlsx/drawing/ax_data_source.rb~ +0 -55
  203. data/lib/axlsx/drawing/data_source.rb~ +0 -51
  204. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  205. data/lib/axlsx/drawing/hyperlink.rb~ +0 -64
  206. data/lib/axlsx/drawing/num_data.rb~ +0 -51
  207. data/lib/axlsx/drawing/num_data_source.rb~ +0 -54
  208. data/lib/axlsx/drawing/num_val.rb~ +0 -40
  209. data/lib/axlsx/drawing/picture_locking.rb~ +0 -36
  210. data/lib/axlsx/drawing/ref.rb~ +0 -41
  211. data/lib/axlsx/drawing/str_data.rb~ +0 -58
  212. data/lib/axlsx/drawing/str_val.rb~ +0 -35
  213. data/lib/axlsx/util/cbf.rb +0 -333
  214. data/lib/axlsx/util/cfb.rb~ +0 -201
  215. data/lib/axlsx/util/font_tables.rb~ +0 -0
  216. data/lib/axlsx/util/ms_off_crypto.rb +0 -189
  217. data/lib/axlsx/util/ms_off_crypto.rb~ +0 -3
  218. data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
  219. data/lib/axlsx/util/parser.rb~ +0 -6
  220. data/lib/axlsx/util/storage.rb~ +0 -0
  221. data/lib/axlsx/workbook/shared_strings_table.rb~ +0 -69
  222. data/lib/axlsx/workbook/worksheet/cfvo.rb~ +0 -0
  223. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  224. data/lib/axlsx/workbook/worksheet/color_scale.rb~ +0 -46
  225. data/lib/axlsx/workbook/worksheet/data_bar.rb~ +0 -0
  226. data/lib/axlsx/workbook/worksheet/icon_set.rb~ +0 -95
  227. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  228. data/lib/axlsx/workbook/worksheet/table.rb~ +0 -97
  229. data/lib/schema/dc.xsd~ +0 -118
  230. data/lib/schema/dcterms.xsd~ +0 -331
  231. data/lib/schema/opc-coreProperties.xsd~ +0 -50
  232. data/test/drawing/tc_data_source.rb~ +0 -30
  233. data/test/drawing/tc_num_data.rb~ +0 -35
  234. data/test/drawing/tc_num_val.rb~ +0 -29
  235. data/test/drawing/tc_str_data.rb~ +0 -30
  236. data/test/drawing/tc_str_val.rb~ +0 -26
  237. data/test/workbook/worksheet/table/tc_table.rb~ +0 -72
  238. data/test/workbook/worksheet/tc_cfvo.rb~ +0 -20
  239. data/test/workbook/worksheet/tc_col.rb~ +0 -10
  240. data/test/workbook/worksheet/tc_color_scale.rb~ +0 -0
  241. data/test/workbook/worksheet/tc_data_bar.rb~ +0 -0
  242. data/test/workbook/worksheet/tc_icon_set.rb~ +0 -0
@@ -0,0 +1,245 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+ # Data validation allows the validation of cell data
4
+ #
5
+ # @note The recommended way to manage data validations is via Worksheet#add_data_validation
6
+ # @see Worksheet#add_data_validation
7
+ class DataValidation
8
+
9
+ # instance values that must be serialized as their own elements - e.g. not attributes.
10
+ CHILD_ELEMENTS = [:formula1, :formula2]
11
+
12
+ # Formula1
13
+ # Available for type whole, decimal, date, time, textLength, list, custom
14
+ # @see type
15
+ # @return [String]
16
+ # default nil
17
+ attr_reader :formula1
18
+
19
+ # Formula2
20
+ # Available for type whole, decimal, date, time, textLength
21
+ # @see type
22
+ # @return [String]
23
+ # default nil
24
+ attr_reader :formula2
25
+
26
+ # Allow Blank
27
+ # A boolean value indicating whether the data validation allows the use of empty or blank
28
+ # entries. 1 means empty entries are OK and do not violate the validation constraints.
29
+ # Available for type whole, decimal, date, time, textLength, list, custom
30
+ # @see type
31
+ # @return [Boolean]
32
+ # default true
33
+ attr_reader :allowBlank
34
+
35
+ # Error Message
36
+ # Message text of error alert.
37
+ # Available for type whole, decimal, date, time, textLength, list, custom
38
+ # @see type
39
+ # @return [String]
40
+ # default nil
41
+ attr_reader :error
42
+
43
+ # Error Style (ST_DataValidationErrorStyle)
44
+ # The style of error alert used for this data validation.
45
+ # Options are:
46
+ # * information: This data validation error style uses an information icon in the error alert.
47
+ # * stop: This data validation error style uses a stop icon in the error alert.
48
+ # * warning: This data validation error style uses a warning icon in the error alert.
49
+ # Available for type whole, decimal, date, time, textLength, list, custom
50
+ # @see type
51
+ # @return [Symbol]
52
+ # default :stop
53
+ attr_reader :errorStyle
54
+
55
+ # Error Title
56
+ # Title bar text of error alert.
57
+ # Available for type whole, decimal, date, time, textLength, list, custom
58
+ # @see type
59
+ # @return [String]
60
+ # default nil
61
+ attr_reader :errorTitle
62
+
63
+ # Operator (ST_DataValidationOperator)
64
+ # The relational operator used with this data validation.
65
+ # Options are:
66
+ # * between: Data validation which checks if a value is between two other values.
67
+ # * equal: Data validation which checks if a value is equal to a specified value.
68
+ # * greater_than: Data validation which checks if a value is greater than a specified value.
69
+ # * greater_than_or_equal: Data validation which checks if a value is greater than or equal to a specified value.
70
+ # * less_than: Data validation which checks if a value is less than a specified value.
71
+ # * less_than_or_equal: Data validation which checks if a value is less than or equal to a specified value.
72
+ # * not_between: Data validation which checks if a value is not between two other values.
73
+ # * not_equal: Data validation which checks if a value is not equal to a specified value.
74
+ # Available for type whole, decimal, date, time, textLength
75
+ # @see type
76
+ # @return [Symbol]
77
+ # default nil
78
+ attr_reader :operator
79
+
80
+ # Input prompt
81
+ # Message text of input prompt.
82
+ # Available for type whole, decimal, date, time, textLength, list, custom
83
+ # @see type
84
+ # @return [String]
85
+ # default nil
86
+ attr_reader :prompt
87
+
88
+ # Prompt title
89
+ # Title bar text of input prompt.
90
+ # Available for type whole, decimal, date, time, textLength, list, custom
91
+ # @see type
92
+ # @return [String]
93
+ # default nil
94
+ attr_reader :promptTitle
95
+
96
+ # Show drop down
97
+ # A boolean value indicating whether to display a dropdown combo box for a list type data
98
+ # validation. Be careful: false shows the dropdown list!
99
+ # Available for type list
100
+ # @see type
101
+ # @return [Boolean]
102
+ # default false
103
+ attr_reader :showDropDown
104
+
105
+ # Show error message
106
+ # A boolean value indicating whether to display the error alert message when an invalid
107
+ # value has been entered, according to the criteria specified.
108
+ # Available for type whole, decimal, date, time, textLength, list, custom
109
+ # @see type
110
+ # @return [Boolean]
111
+ # default false
112
+ attr_reader :showErrorMessage
113
+
114
+ # Show input message
115
+ # A boolean value indicating whether to display the input prompt message.
116
+ # Available for type whole, decimal, date, time, textLength, list, custom
117
+ # @see type
118
+ # @return [Boolean]
119
+ # default false
120
+ attr_reader :showInputMessage
121
+
122
+ # Range over which data validation is applied, in "A1:B2" format
123
+ # Available for type whole, decimal, date, time, textLength, list, custom
124
+ # @see type
125
+ # @return [String]
126
+ # default nil
127
+ attr_reader :sqref
128
+
129
+ # The type (ST_DataValidationType) of data validation.
130
+ # Options are:
131
+ # * custom: Data validation which uses a custom formula to check the cell value.
132
+ # * date: Data validation which checks for date values satisfying the given condition.
133
+ # * decimal: Data validation which checks for decimal values satisfying the given condition.
134
+ # * list: Data validation which checks for a value matching one of list of values.
135
+ # * none: No data validation.
136
+ # * textLength: Data validation which checks for text values, whose length satisfies the given condition.
137
+ # * time: Data validation which checks for time values satisfying the given condition.
138
+ # * whole: Data validation which checks for whole number values satisfying the given condition.
139
+ # @return [Symbol]
140
+ # default none
141
+ attr_reader :type
142
+
143
+ # Creates a new {DataValidation} object
144
+ # @option options [String] formula1
145
+ # @option options [String] formula2
146
+ # @option options [Boolean] allowBlank - A boolean value indicating whether the data validation allows the use of empty or blank entries.
147
+ # @option options [String] error - Message text of error alert.
148
+ # @option options [Symbol] errorStyle - The style of error alert used for this data validation.
149
+ # @option options [String] errorTitle - itle bar text of error alert.
150
+ # @option options [Symbol] operator - The relational operator used with this data validation.
151
+ # @option options [String] prompt - Message text of input prompt.
152
+ # @option options [String] promptTitle - Title bar text of input prompt.
153
+ # @option options [Boolean] showDropDown - A boolean value indicating whether to display a dropdown combo box for a list type data validation
154
+ # @option options [Boolean] showErrorMessage - A boolean value indicating whether to display the error alert message when an invalid value has been entered, according to the criteria specified.
155
+ # @option options [Boolean] showInputMessage - A boolean value indicating whether to display the input prompt message.
156
+ # @option options [String] sqref - Range over which data validation is applied, in "A1:B2" format.
157
+ # @option options [Symbol] type - The type of data validation.
158
+ def initialize(options={})
159
+ # defaults
160
+ @formula1 = @formula2 = @error = @errorTitle = @operator = @prompt = @promptTitle = @sqref = nil
161
+ @allowBlank = @showErrorMessage = true
162
+ @showDropDown = @showInputMessage = false
163
+ @type = :none
164
+ @errorStyle = :stop
165
+
166
+ options.each do |o|
167
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
168
+ end
169
+ end
170
+
171
+ # @see formula1
172
+ def formula1=(v); Axlsx::validate_string(v); @formula1 = v end
173
+
174
+ # @see formula2
175
+ def formula2=(v); Axlsx::validate_string(v); @formula2 = v end
176
+
177
+ # @see allowBlank
178
+ def allowBlank=(v); Axlsx::validate_boolean(v); @allowBlank = v end
179
+
180
+ # @see error
181
+ def error=(v); Axlsx::validate_string(v); @error = v end
182
+
183
+ # @see errorStyle
184
+ def errorStyle=(v); Axlsx::validate_data_validation_error_style(v); @errorStyle = v end
185
+
186
+ # @see errorTitle
187
+ def errorTitle=(v); Axlsx::validate_string(v); @errorTitle = v end
188
+
189
+ # @see operator
190
+ def operator=(v); Axlsx::validate_data_validation_operator(v); @operator = v end
191
+
192
+ # @see prompt
193
+ def prompt=(v); Axlsx::validate_string(v); @prompt = v end
194
+
195
+ # @see promptTitle
196
+ def promptTitle=(v); Axlsx::validate_string(v); @promptTitle = v end
197
+
198
+ # @see showDropDown
199
+ def showDropDown=(v); Axlsx::validate_boolean(v); @showDropDown = v end
200
+
201
+ # @see showErrorMessage
202
+ def showErrorMessage=(v); Axlsx::validate_boolean(v); @showErrorMessage = v end
203
+
204
+ # @see showInputMessage
205
+ def showInputMessage=(v); Axlsx::validate_boolean(v); @showInputMessage = v end
206
+
207
+ # @see sqref
208
+ def sqref=(v); Axlsx::validate_string(v); @sqref = v end
209
+
210
+ # @see type
211
+ def type=(v); Axlsx::validate_data_validation_type(v); @type = v end
212
+
213
+ # Serializes the data validation
214
+ # @param [String] str
215
+ # @return [String]
216
+ def to_xml_string(str = '')
217
+ valid_attributes = get_valid_attributes
218
+
219
+ str << '<dataValidation '
220
+ str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' if (valid_attributes.include?(key.to_sym) and not CHILD_ELEMENTS.include?(key.to_sym)) }.join(' ')
221
+ str << '>'
222
+ str << '<formula1>' << self.formula1 << '</formula1>' if @formula1 and valid_attributes.include?(:formula1)
223
+ str << '<formula2>' << self.formula2 << '</formula2>' if @formula2 and valid_attributes.include?(:formula2)
224
+ str << '</dataValidation>'
225
+ end
226
+
227
+ private
228
+ def get_valid_attributes
229
+ attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type ]
230
+
231
+ if [:whole, :decimal, :data, :time, :textLength].include?(@type)
232
+ attributes << [:operator, :formula1]
233
+ attributes << [:formula2] if [:between, :notBetween].include?(@operator)
234
+ elsif @type == :list
235
+ attributes << [:showDropDown, :formula1]
236
+ elsif @type == :custom
237
+ attributes << [:formula1]
238
+ else
239
+ attributes = []
240
+ end
241
+
242
+ attributes.flatten!
243
+ end
244
+ end
245
+ end
@@ -0,0 +1,28 @@
1
+ module Axlsx
2
+
3
+ # A simple, self serializing class for storing conditional formattings
4
+ class DataValidations < SimpleTypedList
5
+
6
+ # creates a new Tables object
7
+ def initialize(worksheet)
8
+ raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
9
+ super DataValidation
10
+ @worksheet = worksheet
11
+ end
12
+
13
+ # The worksheet that owns this collection of tables
14
+ # @return [Worksheet]
15
+ attr_reader :worksheet
16
+
17
+ # serialize the conditional formattings
18
+ def to_xml_string(str = "")
19
+ return if empty?
20
+ str << "<dataValidations count='#{size}'>"
21
+ each { |item| item.to_xml_string(str) }
22
+ str << '</dataValidations>'
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+
@@ -10,7 +10,7 @@ module Axlsx
10
10
  # @return [Numeric]
11
11
  def self.date_to_serial(date)
12
12
  epoch = Axlsx::Workbook::date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
13
- (date-epoch).to_f
13
+ (date - epoch).to_f
14
14
  end
15
15
 
16
16
  # The time_to_serial methond converts a Time object its excel serialized form.
@@ -0,0 +1,65 @@
1
+ module Axlsx
2
+
3
+ # This class manages the dimensions for a worksheet.
4
+ # While this node is optional in the specification some readers like
5
+ # LibraOffice require this node to render the sheet
6
+ class Dimension
7
+
8
+ # the default value for the first cell in the dimension
9
+ # @return [String]
10
+ def self.default_first
11
+ @@default_first ||= 'A1'
12
+ end
13
+
14
+ # the default value for the last cell in the dimension
15
+ # @return [String]
16
+ def self.default_last
17
+ @@default_last ||= 'AA200'
18
+ end
19
+
20
+
21
+ # Creates a new dimension object
22
+ # @param[Worksheet] worksheet - the worksheet this dimension applies
23
+ # to.
24
+ def initialize(worksheet)
25
+ raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
26
+ @worksheet = worksheet
27
+ end
28
+
29
+ attr_reader :worksheet
30
+
31
+ # the full refernece for this dimension
32
+ # @return [String]
33
+ def sqref
34
+ "#{first_cell_reference}:#{last_cell_reference}"
35
+ end
36
+
37
+ # serialize the object
38
+ # @return [String]
39
+ def to_xml_string(str = '')
40
+ return if worksheet.rows.empty?
41
+ str << "<dimension ref=\"%s\"></dimension>" % sqref
42
+ end
43
+
44
+ # The first cell in the dimension
45
+ # @return [String]
46
+ def first_cell_reference
47
+ dimension_reference(worksheet.rows.first.cells.first, Dimension.default_first)
48
+ end
49
+
50
+ # the last cell in the dimension
51
+ # @return [String]
52
+ def last_cell_reference
53
+ dimension_reference(worksheet.rows.last.cells.last, Dimension.default_last)
54
+ end
55
+
56
+ private
57
+
58
+ # Returns the reference of a cell or the default specified
59
+ # @return [String]
60
+ def dimension_reference(cell, default)
61
+ return default unless cell.respond_to?(:r)
62
+ cell.r
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,35 @@
1
+ module Axlsx
2
+
3
+ # A simple list of merged cells
4
+ class MergedCells < SimpleTypedList
5
+
6
+ # creates a new MergedCells object
7
+ # @param [Worksheet] worksheet
8
+ def initialize(worksheet)
9
+ raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
10
+ super String
11
+ end
12
+
13
+ # adds cells to the merged cells collection
14
+ # @param [Array||String] cells The cells to add to the merged cells
15
+ # collection. This can be an array of actual cells or a string style
16
+ # range like 'A1:C1'
17
+ def add(cells)
18
+ @list << if cells.is_a?(String)
19
+ cells
20
+ elsif cells.is_a?(Array)
21
+ Axlsx::cell_range(cells, false)
22
+ end
23
+ end
24
+
25
+ # serialize the object
26
+ # @param [String] str
27
+ # @return [String]
28
+ def to_xml_string(str = '')
29
+ return if @list.empty?
30
+ str << "<mergeCells count='#{size}'>"
31
+ each { |merged_cell| str << "<mergeCell ref='#{merged_cell}'></mergeCell>" }
32
+ str << '</mergeCells>'
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,47 @@
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
+ # creates a new page setup properties object
8
+ # @param [Hash] options
9
+ # @option [Boolean] auto_page_breaks Flag indicating whether the sheet displays Automatic Page Breaks.
10
+ # @option [Boolean] fit_to_page Flag indicating whether the Fit to Page print option is enabled.
11
+ def initialize(options = {})
12
+ options.each do |key, value|
13
+ self.send("#{key}=",value) if self.respond_to?("#{key}=")
14
+ end
15
+ end
16
+
17
+ attr_reader :auto_page_breaks
18
+ attr_reader :fit_to_page
19
+
20
+ # Flag indicating whether the Fit to Page print option is enabled.
21
+ # @param [Boolean] value
22
+ # @return [Boolean]
23
+ def fit_to_page=(value)
24
+ Axlsx.validate_boolean value
25
+ @fit_to_page = value
26
+ end
27
+
28
+ # Flag indicating whether the sheet displays Automatic Page Breaks.
29
+ # @param [Boolean] value
30
+ # @return [Boolean]
31
+ def auto_page_breaks=(value)
32
+ Axlsx.validate_boolean value
33
+ @auto_page_breaks = value
34
+ end
35
+
36
+ # serialize to xml
37
+ def to_xml_string(str='')
38
+ str << '<pageSetUpPr ' << serialized_attributes << '/>'
39
+ end
40
+
41
+ private
42
+
43
+ def serialized_attributes
44
+ instance_values.map { |key, value| "#{Axlsx.camel(key, false)}='#{value}'" }.join(' ')
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,241 @@
1
+ module Axlsx
2
+ # Page setup settings for printing a worksheet. All settings are optional.
3
+ #
4
+ # @note The recommended way to manage print options is via Worksheet#page_setup
5
+ # @see Worksheet#print_options
6
+ # @see Worksheet#initialize
7
+ class PageSetup
8
+
9
+ # TODO: Attributes defined by Open XML spec that are not implemented yet:
10
+ #
11
+ # * blackAndWhite
12
+ # * cellComments
13
+ # * copies
14
+ # * draft
15
+ # * errors
16
+ # * firstPageNumber
17
+ # * horizontalDpi
18
+ # * pageOrder
19
+ # * paperSize
20
+ # * useFirstPageNumber
21
+ # * usePrinterDefaults
22
+ # * verticalDpi
23
+
24
+ # Number of vertical pages to fit on.
25
+ # @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
+ # being set to 1.
27
+ # @return [Integer]
28
+ attr_reader :fit_to_height
29
+
30
+ # Number of horizontal pages to fit on.
31
+ # @note PageSetup#fit_to is the recomended way to manage page fitting as only specifying one of width/height will result in the counterpart
32
+ # being set to 1.
33
+ # @return [Integer]
34
+ attr_reader :fit_to_width
35
+
36
+ # Orientation of the page (:default, :landscape, :portrait)
37
+ # @return [Symbol]
38
+ attr_reader :orientation
39
+
40
+ # Height of paper (string containing a number followed by a unit identifier: "297mm", "11in")
41
+ # @return [String]
42
+ attr_reader :paper_height
43
+
44
+ # Width of paper (string containing a number followed by a unit identifier: "210mm", "8.5in")
45
+ # @return [String]
46
+ attr_reader :paper_width
47
+
48
+ # Print scaling (percent value, given as integer ranging from 10 to 400)
49
+ # @return [Integer]
50
+ attr_reader :scale
51
+
52
+ # The paper size to use in printing
53
+ #1 = Letter paper (8.5 in. by 11 in.)
54
+ #2 = Letter small paper (8.5 in. by 11 in.)
55
+ #3 = Tabloid paper (11 in. by 17 in.)
56
+ #4 = Ledger paper (17 in. by 11 in.)
57
+ #5 = Legal paper (8.5 in. by 14 in.)
58
+ #6 = Statement paper (5.5 in. by 8.5 in.)
59
+ #7 = Executive paper (7.25 in. by 10.5 in.)
60
+ #8 = A3 paper (297 mm by 420 mm)
61
+ #9 = A4 paper (210 mm by 297 mm)
62
+ #10 = A4 small paper (210 mm by 297 mm)
63
+ #11 = A5 paper (148 mm by 210 mm)
64
+ #12 = B4 paper (250 mm by 353 mm)
65
+ #13 = B5 paper (176 mm by 250 mm)
66
+ #14 = Folio paper (8.5 in. by 13 in.)
67
+ #15 = Quarto paper (215 mm by 275 mm)
68
+ #16 = Standard paper (10 in. by 14 in.)
69
+ #17 = Standard paper (11 in. by 17 in.)
70
+ #18 = Note paper (8.5 in. by 11 in.)
71
+ #19 = #9 envelope (3.875 in. by 8.875 in.)
72
+ #20 = #10 envelope (4.125 in. by 9.5 in.)
73
+ #21 = #11 envelope (4.5 in. by 10.375 in.)
74
+ #22 = #12 envelope (4.75 in. by 11 in.)
75
+ #23 = #14 envelope (5 in. by 11.5 in.) 24 = C paper (17 in. by 22 in.)
76
+ #25 = D paper (22 in. by 34 in.)
77
+ #26 = E paper (34 in. by 44 in.)
78
+ #27 = DL envelope (110 mm by 220 mm)
79
+ #28 = C5 envelope (162 mm by 229 mm)
80
+ #29 = C3 envelope (324 mm by 458 mm)
81
+ #30 = C4 envelope (229 mm by 324 mm)
82
+ #31 = C6 envelope (114 mm by 162 mm)
83
+ #32 = C65 envelope (114 mm by 229 mm)
84
+ #33 = B4 envelope (250 mm by 353 mm)
85
+ #34 = B5 envelope (176 mm by 250 mm)
86
+ #35 = B6 envelope (176 mm by 125 mm)
87
+ #36 = Italy envelope (110 mm by 230 mm)
88
+ #37 = Monarch envelope (3.875 in. by 7.5 in.). 38 = 6 3/4 envelope (3.625 in. by 6.5 in.)
89
+ #39 = US standard fanfold (14.875 in. by 11 in.)
90
+ #40 = German standard fanfold (8.5 in. by 12 in.)
91
+ #41 = German legal fanfold (8.5 in. by 13 in.)
92
+ #42 = ISO B4 (250 mm by 353 mm)
93
+ #43 = Japanese double postcard (200 mm by 148 mm)
94
+ #44 = Standard paper (9 in. by 11 in.)
95
+ #45 = Standard paper (10 in. by 11 in.)
96
+ #46 = Standard paper (15 in. by 11 in.)
97
+ #47 = Invite envelope (220 mm by 220 mm)
98
+ #50 = Letter extra paper (9.275 in. by 12 in.)
99
+ #51 = Legal extra paper (9.275 in. by 15 in.)
100
+ #52 = Tabloid extra paper (11.69 in. by 18 in.)
101
+ #53 = A4 extra paper (236 mm by 322 mm)
102
+ #54 = Letter transverse paper (8.275 in. by 11 in.)
103
+ #55 = A4 transverse paper (210 mm by 297 mm)
104
+ #56 = Letter extra transverse paper (9.275 in. by 12 in.)
105
+ #57 = SuperA/SuperA/A4 paper (227 mm by 356 mm)
106
+ #58 = SuperB/SuperB/A3 paper (305 mm by 487 mm)
107
+ #59 = Letter plus paper (8.5 in. by 12.69 in.)
108
+ #60 = A4 plus paper (210 mm by 330 mm)
109
+ #61 = A5 transverse paper (148 mm by 210 mm)
110
+ #62 = JIS B5 transverse paper (182 mm by 257 mm)
111
+ #63 = A3 extra paper (322 mm by 445 mm)
112
+ #64 = A5 extra paper (174 mm by 235 mm)
113
+ #65 = ISO B5 extra paper (201 mm by 276 mm)
114
+ #66 = A2 paper (420 mm by 594 mm)
115
+ #67 = A3 transverse paper (297 mm by 420 mm)
116
+ #68 = A3 extra transverse paper (322 mm by 445 mm)
117
+ #69 = Japanese Double Postcard (200 mm x 148 mm)
118
+ #70 = A6 (105 mm x 148 mm
119
+ #71 = Japanese Envelope Kaku #2
120
+ #72 = Japanese Envelope Kaku #3
121
+ #73 = Japanese Envelope Chou #3
122
+ #74 = Japanese Envelope Chou #4
123
+ #75 = Letter Rotated (11in x 8 1/2 11 in)
124
+ #76 = A3 Rotated (420 mm x 297 mm)
125
+ #77 = A4 Rotated (297 mm x 210 mm)
126
+ #78 = A5 Rotated (210 mm x 148 mm)
127
+ #79 = B4 (JIS) Rotated (364 mm x 257 mm)
128
+ #80 = B5 (JIS) Rotated (257 mm x 182 mm)
129
+ #81 = Japanese Postcard Rotated (148 mm x 100 mm)
130
+ #82 = Double Japanese Postcard Rotated (148 mm x 200 mm)
131
+ #83 = A6 Rotated (148 mm x 105 mm)
132
+ #84 = Japanese Envelope Kaku #2 Rotated
133
+ #85 = Japanese Envelope Kaku #3 Rotated
134
+ #86 = Japanese Envelope Chou #3 Rotated
135
+ #87 = Japanese Envelope Chou #4 Rotated
136
+ #88 = B6 (JIS) (128 mm x 182 mm)
137
+ #89 = B6 (JIS) Rotated (182 mm x 128 mm)
138
+ #90 = (12 in x 11 in)
139
+ #91 = Japanese Envelope You #4
140
+ #92 = Japanese Envelope You #4 Rotated
141
+ #93 = PRC 16K (146 mm x 215 mm)
142
+ #94 = PRC 32K (97 mm x 151 mm)
143
+ #95 = PRC 32K(Big) (97 mm x 151 mm)
144
+ #96 = PRC Envelope #1 (102 mm x 165 mm)
145
+ #97 = PRC Envelope #2 (102 mm x 176 mm)
146
+ #98 = PRC Envelope #3 (125 mm x 176 mm)
147
+ #99 = PRC Envelope #4 (110 mm x 208 mm)
148
+ #100 = PRC Envelope #5 (110 mm x 220 mm)
149
+ #101 = PRC Envelope #6 (120 mm x 230 mm)
150
+ #102 = PRC Envelope #7 (160 mm x 230 mm)
151
+ #103 = PRC Envelope #8 (120 mm x 309 mm)
152
+ #104 = PRC Envelope #9 (229 mm x 324 mm)
153
+ #105 = PRC Envelope #10 (324 mm x 458 mm)
154
+ #106 = PRC 16K Rotated
155
+ #107 = PRC 32K Rotated
156
+ #108 = PRC 32K(Big) Rotated
157
+ #109 = PRC Envelope #1 Rotated (165 mm x 102 mm)
158
+ #110 = PRC Envelope #2 Rotated (176 mm x 102 mm)
159
+ #111 = PRC Envelope #3 Rotated (176 mm x 125 mm)
160
+ #112 = PRC Envelope #4 Rotated (208 mm x 110 mm)
161
+ #113 = PRC Envelope #5 Rotated (220 mm x 110 mm)
162
+ #114 = PRC Envelope #6 Rotated (230 mm x 120 mm)
163
+ #115 = PRC Envelope #7 Rotated (230 mm x 160 mm)
164
+ #116 = PRC Envelope #8 Rotated (309 mm x 120 mm)
165
+ #117 = PRC Envelope #9 Rotated (324 mm x 229 mm)
166
+ #118 = PRC Envelope #10 Rotated (458 mm x 324 mm)
167
+ # @return [Integer]
168
+ attr_reader :paper_size
169
+
170
+
171
+ # Sets the paper size for printing.
172
+ # @see PageSetup#paper_size
173
+ # @return integer
174
+ def paper_size=(size)
175
+ RestrictionValidator.validate 'paper_size', (1..118), size
176
+ @paper_size = size
177
+ end
178
+
179
+ # Creates a new PageSetup object
180
+ # @option options [Integer] fit_to_height Number of vertical pages to fit on
181
+ # @option options [Integer] fit_to_width Number of horizontal pages to fit on
182
+ # @option options [Symbol] orientation Orientation of the page (:default, :landscape, :portrait)
183
+ # @option options [String] paper_height Height of paper (number followed by unit identifier: "297mm", "11in")
184
+ # @option options [String] paper_width Width of paper (number followed by unit identifier: "210mm", "8.5in")
185
+ # @option options [Integer] scale Print scaling (percent value, integer ranging from 10 to 400)
186
+ # @option options [Integer] paper_size - the size of paper to use
187
+ def initialize(options = {})
188
+ set(options)
189
+ end
190
+
191
+ # Set some or all page settings at once.
192
+ # @param [Hash] options The page settings to set (possible keys are :fit_to_height, :fit_to_width, :orientation, :paper_height, :paper_width, and :scale).
193
+ def set(options)
194
+ options.each do |k, v|
195
+ send("#{k}=", v) if respond_to? "#{k}="
196
+ end
197
+ end
198
+
199
+ # @see fit_to_height
200
+ def fit_to_height=(v); Axlsx::validate_unsigned_int(v); @fit_to_height = v; end
201
+ # @see fit_to_width
202
+ def fit_to_width=(v); Axlsx::validate_unsigned_int(v); @fit_to_width = v; end
203
+ # @see orientation
204
+ def orientation=(v); Axlsx::validate_page_orientation(v); @orientation = v; end
205
+ # @see paper_height
206
+ def paper_height=(v); Axlsx::validate_number_with_unit(v); @paper_height = v; end
207
+ # @see paper_width
208
+ def paper_width=(v); Axlsx::validate_number_with_unit(v); @paper_width = v; end
209
+ # @see scale
210
+ def scale=(v); Axlsx::validate_scale_10_400(v); @scale = v; end
211
+
212
+ # convenience method to achieve sanity when setting fit_to_width and fit_to_height
213
+ # as they both default to 1 if only their counterpart is specified.
214
+ # @note This method will overwrite any value you explicitly set via the fit_to_height or fit_to_width methods.
215
+ # @option options [Integer] width The number of pages to fit this worksheet on horizontally. Default 9999
216
+ # @option options [Integer] height The number of pages to fit this worksheet on vertically. Default 9999
217
+ def fit_to(options={})
218
+ self.fit_to_width = options[:width] || 9999
219
+ self.fit_to_height = options[:height] || 9999
220
+ [@fit_to_width, @fit_to_height]
221
+ end
222
+
223
+
224
+ # helper method for worksheet to determine if the page setup is configured for fit to page printing
225
+ # We treat any page set up that has a value set for fit_to_width or fit_to_height value as fit_to_page.
226
+ # @return [Boolean]
227
+ def fit_to_page?
228
+ # is there some better what to express this?
229
+ (fit_to_width != nil || fit_to_height != nil)
230
+ end
231
+
232
+ # Serializes the page settings element.
233
+ # @param [String] str
234
+ # @return [String]
235
+ def to_xml_string(str = '')
236
+ str << '<pageSetup '
237
+ str << instance_values.reject{ |k, v| k == 'worksheet' }.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v}"} }.join(' ')
238
+ str << '/>'
239
+ end
240
+ end
241
+ end