axlsx 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -5
- data/examples/colored_links.rb +59 -0
- data/examples/example.rb +421 -266
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/finance.rb +82 -0
- data/examples/finance.xlsx +0 -0
- data/examples/financial.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/examples/where_is_my_color.xlsx +0 -0
- data/lib/axlsx.rb +11 -4
- data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
- data/lib/axlsx/content_type/content_type.rb +1 -1
- data/lib/axlsx/content_type/default.rb +6 -37
- data/lib/axlsx/content_type/override.rb +6 -38
- data/lib/axlsx/doc_props/app.rb +7 -4
- data/lib/axlsx/drawing/axis.rb +3 -3
- data/lib/axlsx/drawing/chart.rb +2 -3
- data/lib/axlsx/drawing/d_lbls.rb +21 -31
- data/lib/axlsx/drawing/drawing.rb +6 -0
- data/lib/axlsx/drawing/hyperlink.rb +40 -32
- data/lib/axlsx/drawing/marker.rb +13 -13
- data/lib/axlsx/drawing/num_data.rb +6 -6
- data/lib/axlsx/drawing/num_data_source.rb +17 -16
- data/lib/axlsx/drawing/one_cell_anchor.rb +20 -22
- data/lib/axlsx/drawing/pic.rb +25 -27
- data/lib/axlsx/drawing/picture_locking.rb +12 -44
- data/lib/axlsx/drawing/scaling.rb +13 -13
- data/lib/axlsx/drawing/scatter_chart.rb +3 -3
- data/lib/axlsx/drawing/series.rb +3 -6
- data/lib/axlsx/drawing/str_data.rb +3 -3
- data/lib/axlsx/drawing/str_val.rb +7 -8
- data/lib/axlsx/drawing/view_3D.rb +51 -37
- data/lib/axlsx/drawing/vml_shape.rb +23 -23
- data/lib/axlsx/package.rb +14 -16
- data/lib/axlsx/stylesheet/border.rb +29 -20
- data/lib/axlsx/stylesheet/border_pr.rb +5 -4
- data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
- data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
- data/lib/axlsx/stylesheet/cell_style.rb +19 -14
- data/lib/axlsx/stylesheet/color.rb +19 -16
- data/lib/axlsx/stylesheet/dxf.rb +4 -4
- data/lib/axlsx/stylesheet/font.rb +22 -22
- data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
- data/lib/axlsx/stylesheet/num_fmt.rb +22 -13
- data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
- data/lib/axlsx/stylesheet/styles.rb +1 -1
- data/lib/axlsx/stylesheet/table_style.rb +17 -16
- data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
- data/lib/axlsx/stylesheet/table_styles.rb +14 -11
- data/lib/axlsx/stylesheet/xf.rb +28 -26
- data/lib/axlsx/util/accessors.rb +49 -0
- data/lib/axlsx/util/options_parser.rb +15 -0
- data/lib/axlsx/util/serialized_attributes.rb +46 -0
- data/lib/axlsx/util/simple_typed_list.rb +16 -4
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/defined_name.rb +13 -58
- data/lib/axlsx/workbook/workbook.rb +27 -1
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -19
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +20 -27
- data/lib/axlsx/workbook/worksheet/cell.rb +38 -39
- data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
- data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -0
- data/lib/axlsx/workbook/worksheet/col.rb +34 -27
- data/lib/axlsx/workbook/worksheet/color_scale.rb +7 -13
- data/lib/axlsx/workbook/worksheet/comment.rb +14 -11
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +27 -25
- data/lib/axlsx/workbook/worksheet/data_bar.rb +44 -34
- data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
- data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
- data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
- data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -9
- data/lib/axlsx/workbook/worksheet/page_setup.rb +20 -19
- data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
- data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
- data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
- data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -26
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +19 -57
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
- data/lib/axlsx/workbook/worksheet/table.rb +16 -18
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +10 -27
- data/lib/axlsx/workbook/worksheet/worksheet.rb +6 -7
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +11 -33
- data/test/content_type/tc_default.rb +0 -11
- data/test/content_type/tc_override.rb +0 -13
- data/test/drawing/tc_d_lbls.rb +14 -4
- data/test/tc_axlsx.rb +20 -2
- data/test/workbook/tc_defined_name.rb +2 -2
- data/test/workbook/tc_workbook.rb +15 -0
- data/test/workbook/worksheet/tc_col.rb +11 -1
- data/test/workbook/worksheet/tc_pane.rb +5 -45
- data/test/workbook/worksheet/tc_selection.rb +9 -48
- metadata +13 -3
@@ -5,24 +5,50 @@ module Axlsx
|
|
5
5
|
# @note The recommended way to manage data validations is via Worksheet#add_data_validation
|
6
6
|
# @see Worksheet#add_data_validation
|
7
7
|
class DataValidation
|
8
|
-
|
8
|
+
include Axlsx::OptionsParser
|
9
|
+
|
10
|
+
# Creates a new {DataValidation} object
|
11
|
+
# @option options [String] formula1
|
12
|
+
# @option options [String] formula2
|
13
|
+
# @option options [Boolean] allowBlank - A boolean value indicating whether the data validation allows the use of empty or blank entries.
|
14
|
+
# @option options [String] error - Message text of error alert.
|
15
|
+
# @option options [Symbol] errorStyle - The style of error alert used for this data validation.
|
16
|
+
# @option options [String] errorTitle - itle bar text of error alert.
|
17
|
+
# @option options [Symbol] operator - The relational operator used with this data validation.
|
18
|
+
# @option options [String] prompt - Message text of input prompt.
|
19
|
+
# @option options [String] promptTitle - Title bar text of input prompt.
|
20
|
+
# @option options [Boolean] showDropDown - A boolean value indicating whether to display a dropdown combo box for a list type data validation
|
21
|
+
# @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.
|
22
|
+
# @option options [Boolean] showInputMessage - A boolean value indicating whether to display the input prompt message.
|
23
|
+
# @option options [String] sqref - Range over which data validation is applied, in "A1:B2" format.
|
24
|
+
# @option options [Symbol] type - The type of data validation.
|
25
|
+
def initialize(options={})
|
26
|
+
# defaults
|
27
|
+
@formula1 = @formula2 = @error = @errorTitle = @operator = @prompt = @promptTitle = @sqref = nil
|
28
|
+
@allowBlank = @showErrorMessage = true
|
29
|
+
@showDropDown = @showInputMessage = false
|
30
|
+
@type = :none
|
31
|
+
@errorStyle = :stop
|
32
|
+
parse_options options
|
33
|
+
end
|
34
|
+
|
9
35
|
# instance values that must be serialized as their own elements - e.g. not attributes.
|
10
36
|
CHILD_ELEMENTS = [:formula1, :formula2]
|
11
|
-
|
37
|
+
|
12
38
|
# Formula1
|
13
39
|
# Available for type whole, decimal, date, time, textLength, list, custom
|
14
40
|
# @see type
|
15
41
|
# @return [String]
|
16
42
|
# default nil
|
17
43
|
attr_reader :formula1
|
18
|
-
|
44
|
+
|
19
45
|
# Formula2
|
20
46
|
# Available for type whole, decimal, date, time, textLength
|
21
47
|
# @see type
|
22
48
|
# @return [String]
|
23
49
|
# default nil
|
24
50
|
attr_reader :formula2
|
25
|
-
|
51
|
+
|
26
52
|
# Allow Blank
|
27
53
|
# A boolean value indicating whether the data validation allows the use of empty or blank
|
28
54
|
# entries. 1 means empty entries are OK and do not violate the validation constraints.
|
@@ -31,7 +57,7 @@ module Axlsx
|
|
31
57
|
# @return [Boolean]
|
32
58
|
# default true
|
33
59
|
attr_reader :allowBlank
|
34
|
-
|
60
|
+
|
35
61
|
# Error Message
|
36
62
|
# Message text of error alert.
|
37
63
|
# Available for type whole, decimal, date, time, textLength, list, custom
|
@@ -39,7 +65,7 @@ module Axlsx
|
|
39
65
|
# @return [String]
|
40
66
|
# default nil
|
41
67
|
attr_reader :error
|
42
|
-
|
68
|
+
|
43
69
|
# Error Style (ST_DataValidationErrorStyle)
|
44
70
|
# The style of error alert used for this data validation.
|
45
71
|
# Options are:
|
@@ -51,7 +77,7 @@ module Axlsx
|
|
51
77
|
# @return [Symbol]
|
52
78
|
# default :stop
|
53
79
|
attr_reader :errorStyle
|
54
|
-
|
80
|
+
|
55
81
|
# Error Title
|
56
82
|
# Title bar text of error alert.
|
57
83
|
# Available for type whole, decimal, date, time, textLength, list, custom
|
@@ -59,7 +85,7 @@ module Axlsx
|
|
59
85
|
# @return [String]
|
60
86
|
# default nil
|
61
87
|
attr_reader :errorTitle
|
62
|
-
|
88
|
+
|
63
89
|
# Operator (ST_DataValidationOperator)
|
64
90
|
# The relational operator used with this data validation.
|
65
91
|
# Options are:
|
@@ -76,7 +102,7 @@ module Axlsx
|
|
76
102
|
# @return [Symbol]
|
77
103
|
# default nil
|
78
104
|
attr_reader :operator
|
79
|
-
|
105
|
+
|
80
106
|
# Input prompt
|
81
107
|
# Message text of input prompt.
|
82
108
|
# Available for type whole, decimal, date, time, textLength, list, custom
|
@@ -84,7 +110,7 @@ module Axlsx
|
|
84
110
|
# @return [String]
|
85
111
|
# default nil
|
86
112
|
attr_reader :prompt
|
87
|
-
|
113
|
+
|
88
114
|
# Prompt title
|
89
115
|
# Title bar text of input prompt.
|
90
116
|
# Available for type whole, decimal, date, time, textLength, list, custom
|
@@ -92,7 +118,7 @@ module Axlsx
|
|
92
118
|
# @return [String]
|
93
119
|
# default nil
|
94
120
|
attr_reader :promptTitle
|
95
|
-
|
121
|
+
|
96
122
|
# Show drop down
|
97
123
|
# A boolean value indicating whether to display a dropdown combo box for a list type data
|
98
124
|
# validation. Be careful: false shows the dropdown list!
|
@@ -101,7 +127,7 @@ module Axlsx
|
|
101
127
|
# @return [Boolean]
|
102
128
|
# default false
|
103
129
|
attr_reader :showDropDown
|
104
|
-
|
130
|
+
|
105
131
|
# Show error message
|
106
132
|
# A boolean value indicating whether to display the error alert message when an invalid
|
107
133
|
# value has been entered, according to the criteria specified.
|
@@ -110,7 +136,7 @@ module Axlsx
|
|
110
136
|
# @return [Boolean]
|
111
137
|
# default false
|
112
138
|
attr_reader :showErrorMessage
|
113
|
-
|
139
|
+
|
114
140
|
# Show input message
|
115
141
|
# A boolean value indicating whether to display the input prompt message.
|
116
142
|
# Available for type whole, decimal, date, time, textLength, list, custom
|
@@ -118,14 +144,14 @@ module Axlsx
|
|
118
144
|
# @return [Boolean]
|
119
145
|
# default false
|
120
146
|
attr_reader :showInputMessage
|
121
|
-
|
147
|
+
|
122
148
|
# Range over which data validation is applied, in "A1:B2" format
|
123
149
|
# Available for type whole, decimal, date, time, textLength, list, custom
|
124
150
|
# @see type
|
125
151
|
# @return [String]
|
126
152
|
# default nil
|
127
153
|
attr_reader :sqref
|
128
|
-
|
154
|
+
|
129
155
|
# The type (ST_DataValidationType) of data validation.
|
130
156
|
# Options are:
|
131
157
|
# * custom: Data validation which uses a custom formula to check the cell value.
|
@@ -139,83 +165,56 @@ module Axlsx
|
|
139
165
|
# @return [Symbol]
|
140
166
|
# default none
|
141
167
|
attr_reader :type
|
142
|
-
|
143
|
-
|
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
|
-
|
168
|
+
|
169
|
+
|
171
170
|
# @see formula1
|
172
171
|
def formula1=(v); Axlsx::validate_string(v); @formula1 = v end
|
173
|
-
|
172
|
+
|
174
173
|
# @see formula2
|
175
174
|
def formula2=(v); Axlsx::validate_string(v); @formula2 = v end
|
176
|
-
|
175
|
+
|
177
176
|
# @see allowBlank
|
178
177
|
def allowBlank=(v); Axlsx::validate_boolean(v); @allowBlank = v end
|
179
|
-
|
178
|
+
|
180
179
|
# @see error
|
181
180
|
def error=(v); Axlsx::validate_string(v); @error = v end
|
182
|
-
|
181
|
+
|
183
182
|
# @see errorStyle
|
184
183
|
def errorStyle=(v); Axlsx::validate_data_validation_error_style(v); @errorStyle = v end
|
185
|
-
|
184
|
+
|
186
185
|
# @see errorTitle
|
187
186
|
def errorTitle=(v); Axlsx::validate_string(v); @errorTitle = v end
|
188
|
-
|
187
|
+
|
189
188
|
# @see operator
|
190
189
|
def operator=(v); Axlsx::validate_data_validation_operator(v); @operator = v end
|
191
|
-
|
190
|
+
|
192
191
|
# @see prompt
|
193
192
|
def prompt=(v); Axlsx::validate_string(v); @prompt = v end
|
194
|
-
|
193
|
+
|
195
194
|
# @see promptTitle
|
196
195
|
def promptTitle=(v); Axlsx::validate_string(v); @promptTitle = v end
|
197
|
-
|
196
|
+
|
198
197
|
# @see showDropDown
|
199
198
|
def showDropDown=(v); Axlsx::validate_boolean(v); @showDropDown = v end
|
200
|
-
|
199
|
+
|
201
200
|
# @see showErrorMessage
|
202
201
|
def showErrorMessage=(v); Axlsx::validate_boolean(v); @showErrorMessage = v end
|
203
|
-
|
202
|
+
|
204
203
|
# @see showInputMessage
|
205
204
|
def showInputMessage=(v); Axlsx::validate_boolean(v); @showInputMessage = v end
|
206
|
-
|
205
|
+
|
207
206
|
# @see sqref
|
208
207
|
def sqref=(v); Axlsx::validate_string(v); @sqref = v end
|
209
|
-
|
208
|
+
|
210
209
|
# @see type
|
211
210
|
def type=(v); Axlsx::validate_data_validation_type(v); @type = v end
|
212
|
-
|
211
|
+
|
213
212
|
# Serializes the data validation
|
214
213
|
# @param [String] str
|
215
214
|
# @return [String]
|
216
215
|
def to_xml_string(str = '')
|
217
216
|
valid_attributes = get_valid_attributes
|
218
|
-
|
217
|
+
|
219
218
|
str << '<dataValidation '
|
220
219
|
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
220
|
str << '>'
|
@@ -223,11 +222,11 @@ module Axlsx
|
|
223
222
|
str << '<formula2>' << self.formula2 << '</formula2>' if @formula2 and valid_attributes.include?(:formula2)
|
224
223
|
str << '</dataValidation>'
|
225
224
|
end
|
226
|
-
|
225
|
+
|
227
226
|
private
|
228
227
|
def get_valid_attributes
|
229
228
|
attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type ]
|
230
|
-
|
229
|
+
|
231
230
|
if [:whole, :decimal, :data, :time, :textLength].include?(@type)
|
232
231
|
attributes << [:operator, :formula1]
|
233
232
|
attributes << [:formula2] if [:between, :notBetween].include?(@operator)
|
@@ -238,7 +237,7 @@ module Axlsx
|
|
238
237
|
else
|
239
238
|
attributes = []
|
240
239
|
end
|
241
|
-
|
240
|
+
|
242
241
|
attributes.flatten!
|
243
242
|
end
|
244
243
|
end
|
@@ -7,8 +7,24 @@ module Axlsx
|
|
7
7
|
# @see ConditionalFormattingRule#initialize
|
8
8
|
class IconSet
|
9
9
|
|
10
|
-
|
11
|
-
|
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
|
-
|
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
|
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
|
95
|
+
serialized_attributes str
|
94
96
|
str << '/>'
|
95
97
|
end
|
96
98
|
end
|
@@ -4,16 +4,19 @@ module Axlsx
|
|
4
4
|
# This class name is not a typo, its spec.
|
5
5
|
class PageSetUpPr
|
6
6
|
|
7
|
+
include Axlsx::OptionsParser
|
8
|
+
include Axlsx::SerializedAttributes
|
9
|
+
|
7
10
|
# creates a new page setup properties object
|
8
11
|
# @param [Hash] options
|
9
12
|
# @option [Boolean] auto_page_breaks Flag indicating whether the sheet displays Automatic Page Breaks.
|
10
13
|
# @option [Boolean] fit_to_page Flag indicating whether the Fit to Page print option is enabled.
|
11
14
|
def initialize(options = {})
|
12
|
-
options
|
13
|
-
self.send("#{key}=",value) if self.respond_to?("#{key}=")
|
14
|
-
end
|
15
|
+
parse_options options
|
15
16
|
end
|
16
17
|
|
18
|
+
serializable_attributes :auto_page_breaks, :fit_to_page
|
19
|
+
|
17
20
|
attr_reader :auto_page_breaks
|
18
21
|
attr_reader :fit_to_page
|
19
22
|
|
@@ -37,11 +40,5 @@ module Axlsx
|
|
37
40
|
def to_xml_string(str='')
|
38
41
|
str << '<pageSetUpPr ' << serialized_attributes << '/>'
|
39
42
|
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def serialized_attributes
|
44
|
-
instance_values.map { |key, value| "#{Axlsx.camel(key, false)}='#{value}'" }.join(' ')
|
45
|
-
end
|
46
43
|
end
|
47
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,7 +32,6 @@ module Axlsx
|
|
16
32
|
# * firstPageNumber
|
17
33
|
# * horizontalDpi
|
18
34
|
# * pageOrder
|
19
|
-
# * paperSize
|
20
35
|
# * useFirstPageNumber
|
21
36
|
# * usePrinterDefaults
|
22
37
|
# * verticalDpi
|
@@ -176,24 +191,10 @@ module Axlsx
|
|
176
191
|
@paper_size = size
|
177
192
|
end
|
178
193
|
|
179
|
-
|
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.
|
194
|
+
# Set some or all page settings at once.
|
192
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).
|
193
196
|
def set(options)
|
194
|
-
options
|
195
|
-
send("#{k}=", v) if respond_to? "#{k}="
|
196
|
-
end
|
197
|
+
parse_options options
|
197
198
|
end
|
198
199
|
|
199
200
|
# @see fit_to_height
|
@@ -234,7 +235,7 @@ module Axlsx
|
|
234
235
|
# @return [String]
|
235
236
|
def to_xml_string(str = '')
|
236
237
|
str << '<pageSetup '
|
237
|
-
str
|
238
|
+
serialized_attributes str
|
238
239
|
str << '/>'
|
239
240
|
end
|
240
241
|
end
|