axlsx 2.0.1 → 2.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -3
  3. data/Rakefile +9 -10
  4. data/examples/IMAGE1UP.JPEG +0 -0
  5. data/examples/auto_filter.rb +10 -1
  6. data/examples/conditional_formatting/example_conditional_formatting.rb +3 -3
  7. data/examples/example.rb +72 -4
  8. data/examples/merge_cells.rb +17 -0
  9. data/examples/no_grid_with_borders.rb +18 -0
  10. data/examples/pivot_test.rb +63 -0
  11. data/examples/split.rb +16 -0
  12. data/lib/axlsx.rb +30 -16
  13. data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
  14. data/lib/axlsx/content_type/content_type.rb +1 -1
  15. data/lib/axlsx/doc_props/app.rb +1 -1
  16. data/lib/axlsx/doc_props/core.rb +5 -5
  17. data/lib/axlsx/drawing/axes.rb +1 -1
  18. data/lib/axlsx/drawing/axis.rb +12 -9
  19. data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
  20. data/lib/axlsx/drawing/bar_series.rb +9 -9
  21. data/lib/axlsx/drawing/bubble_chart.rb +59 -0
  22. data/lib/axlsx/drawing/bubble_series.rb +63 -0
  23. data/lib/axlsx/drawing/cat_axis.rb +5 -5
  24. data/lib/axlsx/drawing/chart.rb +44 -7
  25. data/lib/axlsx/drawing/drawing.rb +3 -1
  26. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  27. data/lib/axlsx/drawing/hyperlink.rb +1 -3
  28. data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
  29. data/lib/axlsx/drawing/line_chart.rb +10 -10
  30. data/lib/axlsx/drawing/line_series.rb +14 -2
  31. data/lib/axlsx/drawing/marker.rb +1 -1
  32. data/lib/axlsx/drawing/num_data.rb +4 -4
  33. data/lib/axlsx/drawing/num_data_source.rb +6 -6
  34. data/lib/axlsx/drawing/num_val.rb +1 -1
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +1 -1
  36. data/lib/axlsx/drawing/pic.rb +2 -3
  37. data/lib/axlsx/drawing/picture_locking.rb +1 -3
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
  39. data/lib/axlsx/drawing/pie_series.rb +6 -6
  40. data/lib/axlsx/drawing/scaling.rb +4 -4
  41. data/lib/axlsx/drawing/scatter_chart.rb +10 -10
  42. data/lib/axlsx/drawing/scatter_series.rb +26 -7
  43. data/lib/axlsx/drawing/ser_axis.rb +2 -2
  44. data/lib/axlsx/drawing/series.rb +3 -3
  45. data/lib/axlsx/drawing/series_title.rb +2 -2
  46. data/lib/axlsx/drawing/str_data.rb +3 -3
  47. data/lib/axlsx/drawing/str_val.rb +1 -1
  48. data/lib/axlsx/drawing/title.rb +3 -3
  49. data/lib/axlsx/drawing/val_axis.rb +1 -1
  50. data/lib/axlsx/drawing/vml_drawing.rb +1 -1
  51. data/lib/axlsx/package.rb +39 -28
  52. data/lib/axlsx/rels/relationship.rb +1 -1
  53. data/lib/axlsx/rels/relationships.rb +2 -2
  54. data/lib/axlsx/stylesheet/border_pr.rb +2 -2
  55. data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
  56. data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
  57. data/lib/axlsx/stylesheet/cell_style.rb +1 -3
  58. data/lib/axlsx/stylesheet/color.rb +1 -3
  59. data/lib/axlsx/stylesheet/font.rb +1 -1
  60. data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
  61. data/lib/axlsx/stylesheet/num_fmt.rb +1 -3
  62. data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
  63. data/lib/axlsx/stylesheet/styles.rb +6 -6
  64. data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
  65. data/lib/axlsx/util/accessors.rb +6 -6
  66. data/lib/axlsx/util/constants.rb +106 -101
  67. data/lib/axlsx/util/options_parser.rb +2 -1
  68. data/lib/axlsx/util/parser.rb +4 -4
  69. data/lib/axlsx/util/serialized_attributes.rb +16 -6
  70. data/lib/axlsx/util/simple_typed_list.rb +28 -52
  71. data/lib/axlsx/util/storage.rb +4 -4
  72. data/lib/axlsx/util/string.rb +7 -0
  73. data/lib/axlsx/util/validators.rb +20 -13
  74. data/lib/axlsx/version.rb +1 -1
  75. data/lib/axlsx/workbook/defined_name.rb +11 -12
  76. data/lib/axlsx/workbook/defined_names.rb +2 -2
  77. data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
  78. data/lib/axlsx/workbook/workbook.rb +19 -12
  79. data/lib/axlsx/workbook/workbook_view.rb +78 -0
  80. data/lib/axlsx/workbook/workbook_views.rb +22 -0
  81. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
  82. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
  83. data/lib/axlsx/workbook/worksheet/break.rb +1 -3
  84. data/lib/axlsx/workbook/worksheet/cell.rb +128 -73
  85. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +50 -40
  86. data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
  87. data/lib/axlsx/workbook/worksheet/cfvos.rb +1 -1
  88. data/lib/axlsx/workbook/worksheet/col.rb +7 -10
  89. data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
  90. data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
  91. data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
  92. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
  93. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
  94. data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
  95. data/lib/axlsx/workbook/worksheet/data_validation.rb +6 -4
  96. data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
  97. data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
  98. data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
  99. data/lib/axlsx/workbook/worksheet/merged_cells.rb +2 -2
  100. data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
  101. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
  102. data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
  103. data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
  104. data/lib/axlsx/workbook/worksheet/pivot_table.rb +17 -24
  105. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
  106. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
  107. data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
  108. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +1 -1
  109. data/lib/axlsx/workbook/worksheet/rich_text.rb +35 -0
  110. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +254 -0
  111. data/lib/axlsx/workbook/worksheet/row.rb +33 -51
  112. data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
  113. data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
  114. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  115. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
  116. data/lib/axlsx/workbook/worksheet/table.rb +6 -6
  117. data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
  118. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  119. data/lib/axlsx/workbook/worksheet/worksheet.rb +59 -30
  120. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
  121. data/test/drawing/tc_axis.rb +27 -0
  122. data/test/drawing/tc_bubble_chart.rb +44 -0
  123. data/test/drawing/tc_bubble_series.rb +21 -0
  124. data/test/drawing/tc_data_source.rb +6 -0
  125. data/test/drawing/tc_line_chart.rb +5 -5
  126. data/test/drawing/tc_line_series.rb +10 -2
  127. data/test/drawing/tc_pic.rb +4 -0
  128. data/test/drawing/tc_scatter_series.rb +25 -1
  129. data/test/tc_helper.rb +1 -1
  130. data/test/tc_package.rb +7 -1
  131. data/test/util/tc_simple_typed_list.rb +1 -2
  132. data/test/workbook/tc_defined_name.rb +12 -4
  133. data/test/workbook/tc_workbook.rb +16 -2
  134. data/test/workbook/tc_workbook_view.rb +50 -0
  135. data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
  136. data/test/workbook/worksheet/tc_break.rb +1 -1
  137. data/test/workbook/worksheet/tc_cell.rb +30 -4
  138. data/test/workbook/worksheet/tc_col.rb +2 -2
  139. data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
  140. data/test/workbook/worksheet/tc_data_bar.rb +1 -1
  141. data/test/workbook/worksheet/tc_data_validation.rb +11 -11
  142. data/test/workbook/worksheet/tc_header_footer.rb +2 -2
  143. data/test/workbook/worksheet/tc_icon_set.rb +1 -1
  144. data/test/workbook/worksheet/tc_page_setup.rb +3 -3
  145. data/test/workbook/worksheet/tc_print_options.rb +1 -1
  146. data/test/workbook/worksheet/tc_rich_text.rb +44 -0
  147. data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
  148. data/test/workbook/worksheet/tc_row.rb +2 -2
  149. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
  150. data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
  151. data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
  152. data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
  153. data/test/workbook/worksheet/tc_worksheet.rb +49 -10
  154. metadata +81 -55
  155. data/test/axlsx.qcachegrind +0 -2226
@@ -8,7 +8,8 @@ module Axlsx
8
8
  # @param [Hash] options Options to parse.
9
9
  def parse_options(options={})
10
10
  options.each do |key, value|
11
- self.send("#{key}=", value) if self.respond_to?("#{key}=") && value != nil
11
+ key = :"#{key}="
12
+ self.send(key, value) if !value.nil? && self.respond_to?(key)
12
13
  end
13
14
  end
14
15
  end
@@ -9,28 +9,28 @@ module Axlsx
9
9
 
10
10
  # parse and assign string attribute
11
11
  def parse_string attr_name, xpath
12
- send("#{attr_name.to_s}=", parse_value(xpath))
12
+ send("#{attr_name}=", parse_value(xpath))
13
13
  end
14
14
 
15
15
  # parse convert and assign node text to symbol
16
16
  def parse_symbol attr_name, xpath
17
17
  v = parse_value xpath
18
18
  v = v.to_sym unless v.nil?
19
- send("#{attr_name.to_s}=", v)
19
+ send("#{attr_name}=", v)
20
20
  end
21
21
 
22
22
  # parse, convert and assign note text to integer
23
23
  def parse_integer attr_name, xpath
24
24
  v = parse_value xpath
25
25
  v = v.to_i if v.respond_to?(:to_i)
26
- send("#{attr_name.to_s}=", v)
26
+ send("#{attr_name}=", v)
27
27
  end
28
28
 
29
29
  # parse, convert and assign node text to float
30
30
  def parse_float attr_name, xpath
31
31
  v = parse_value xpath
32
32
  v = v.to_f if v.respond_to?(:to_f)
33
- send("#{attr_name.to_s}=", v)
33
+ send("#{attr_name}=", v)
34
34
  end
35
35
 
36
36
  # return node text based on xpath
@@ -18,9 +18,7 @@ module Axlsx
18
18
  end
19
19
 
20
20
  # a reader for those attributes
21
- def xml_attributes
22
- @xml_attributes
23
- end
21
+ attr_reader :xml_attributes
24
22
 
25
23
  # This helper registers the attributes that will be formatted as elements.
26
24
  def serializable_element_attributes(*symbols)
@@ -28,8 +26,20 @@ module Axlsx
28
26
  end
29
27
 
30
28
  # attr reader for element attributes
31
- def xml_element_attributes
32
- @xml_element_attributes
29
+ attr_reader :xml_element_attributes
30
+ end
31
+
32
+ # creates a XML tag with serialized attributes
33
+ # @see SerializedAttributes#serialized_attributes
34
+ def serialized_tag(tagname, str, additional_attributes = {}, &block)
35
+ str << "<#{tagname} "
36
+ serialized_attributes(str, additional_attributes)
37
+ if block_given?
38
+ str << '>'
39
+ yield
40
+ str << "</#{tagname}>"
41
+ else
42
+ str << '/>'
33
43
  end
34
44
  end
35
45
 
@@ -42,7 +52,7 @@ module Axlsx
42
52
  def serialized_attributes(str = '', additional_attributes = {})
43
53
  attributes = declared_attributes.merge! additional_attributes
44
54
  attributes.each do |key, value|
45
- str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.camel(value, false)}\" "
55
+ str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.camel(Axlsx.booleanize(value), false)}\" "
46
56
  end
47
57
  str
48
58
  end
@@ -8,7 +8,7 @@ module Axlsx
8
8
  # @param [Array, Class] type An array of Class objects or a single Class object
9
9
  # @param [String] serialize_as The tag name to use in serialization
10
10
  # @raise [ArgumentError] if all members of type are not Class objects
11
- def initialize type, serialize_as=nil
11
+ def initialize type, serialize_as=nil, start_size = 0
12
12
  if type.is_a? Array
13
13
  type.each { |item| raise ArgumentError, "All members of type must be Class objects" unless item.is_a? Class }
14
14
  @allowed_types = type
@@ -16,9 +16,8 @@ module Axlsx
16
16
  raise ArgumentError, "Type must be a Class object or array of Class objects" unless type.is_a? Class
17
17
  @allowed_types = [type]
18
18
  end
19
- @list = []
20
- @locked_at = nil
21
- @serialize_as = serialize_as
19
+ @serialize_as = serialize_as unless serialize_as.nil?
20
+ @list = Array.new(start_size)
22
21
  end
23
22
 
24
23
  # The class constants of allowed types
@@ -27,7 +26,9 @@ module Axlsx
27
26
 
28
27
  # The index below which items cannot be removed
29
28
  # @return [Integer]
30
- attr_reader :locked_at
29
+ def locked_at
30
+ defined?(@locked_at) ? @locked_at : nil
31
+ end
31
32
 
32
33
  # The tag name to use when serializing this object
33
34
  # by default the parent node for all items in the list is the classname of the first allowed type with the first letter in lowercase.
@@ -54,6 +55,7 @@ module Axlsx
54
55
  end
55
56
  result
56
57
  end
58
+
57
59
  # Lock this list at the current size
58
60
  # @return [self]
59
61
  def lock
@@ -61,18 +63,18 @@ module Axlsx
61
63
  self
62
64
  end
63
65
 
64
- def to_ary
65
- @list
66
- end
67
-
68
- alias :to_a :to_ary
69
-
70
66
  # Unlock the list
71
67
  # @return [self]
72
68
  def unlock
73
69
  @locked_at = nil
74
70
  self
75
71
  end
72
+
73
+ def to_ary
74
+ @list
75
+ end
76
+
77
+ alias :to_a :to_ary
76
78
 
77
79
  # join operator
78
80
  # @param [Array] v the array to join
@@ -81,7 +83,7 @@ module Axlsx
81
83
  # @return [SimpleTypedList]
82
84
  def +(v)
83
85
  v.each do |item|
84
- DataTypeValidator.validate "SimpleTypedList.+", @allowed_types, item
86
+ DataTypeValidator.validate :SimpleTypedList_plus, @allowed_types, item
85
87
  @list << item
86
88
  end
87
89
  end
@@ -91,19 +93,21 @@ module Axlsx
91
93
  # @raise [ArgumentError] if the value being added is not one fo the allowed types
92
94
  # @return [Integer] returns the index of the item added.
93
95
  def <<(v)
94
- DataTypeValidator.validate "SimpleTypedList.<<", @allowed_types, v
96
+ DataTypeValidator.validate :SimpleTypedList_push, @allowed_types, v
95
97
  @list << v
96
98
  @list.size - 1
97
- end
99
+ end
100
+
98
101
  alias :push :<<
102
+
99
103
 
100
104
  # delete the item from the list
101
105
  # @param [Any] v The item to be deleted.
102
106
  # @raise [ArgumentError] if the item's index is protected by locking
103
107
  # @return [Any] The item deleted
104
108
  def delete(v)
105
- return unless @list.include? v
106
- raise ArgumentError, "Item is protected and cannot be deleted" if protected? @list.index(v)
109
+ return unless include? v
110
+ raise ArgumentError, "Item is protected and cannot be deleted" if protected? index(v)
107
111
  @list.delete v
108
112
  end
109
113
 
@@ -122,7 +126,7 @@ module Axlsx
122
126
  # @raise [ArgumentError] if the index is protected by locking
123
127
  # @raise [ArgumentError] if the item is not one of the allowed types
124
128
  def []=(index, v)
125
- DataTypeValidator.validate "SimpleTypedList.<<", @allowed_types, v
129
+ DataTypeValidator.validate :SimpleTypedList_insert, @allowed_types, v
126
130
  raise ArgumentError, "Item is protected and cannot be changed" if protected? index
127
131
  @list[index] = v
128
132
  v
@@ -134,7 +138,7 @@ module Axlsx
134
138
  # @raise [ArgumentError] if the index is protected by locking
135
139
  # @raise [ArgumentError] if the index is not one of the allowed types
136
140
  def insert(index, v)
137
- DataTypeValidator.validate "SimpleTypedList.<<", @allowed_types, v
141
+ DataTypeValidator.validate :SimpleTypedList_insert, @allowed_types, v
138
142
  raise ArgumentError, "Item is protected and cannot be changed" if protected? index
139
143
  @list.insert(index, v)
140
144
  v
@@ -143,38 +147,10 @@ module Axlsx
143
147
  # determines if the index is protected
144
148
  # @param [Integer] index
145
149
  def protected? index
146
- return false unless @locked_at.is_a? Fixnum
147
- index < @locked_at
150
+ return false unless locked_at.is_a? Fixnum
151
+ index < locked_at
148
152
  end
149
153
 
150
- # override the equality method so that this object can be compared to a simple array.
151
- # if this object's list is equal to the specifiec array, we return true.
152
- def ==(v)
153
- v == @list
154
- end
155
- # method_mission override to pass allowed methods to the list.
156
- # @note
157
- # the following methods are not allowed
158
- # :replace
159
- # :insert
160
- # :collect!
161
- # :map!
162
- # :pop
163
- # :delete_if
164
- # :reverse!
165
- # :shift
166
- # :shuffle!
167
- # :slice!
168
- # :sort!
169
- # :uniq!
170
- # :unshift
171
- # :zip
172
- # :flatten!
173
- # :fill
174
- # :drop
175
- # :drop_while
176
- # :delete_if
177
- # :clear
178
154
  DESTRUCTIVE = ['replace', 'insert', 'collect!', 'map!', 'pop', 'delete_if',
179
155
  'reverse!', 'shift', 'shuffle!', 'slice!', 'sort!', 'uniq!',
180
156
  'unshift', 'zip', 'flatten!', 'fill', 'drop', 'drop_while',
@@ -188,13 +164,13 @@ module Axlsx
188
164
  end
189
165
  }
190
166
  end
191
-
167
+
192
168
  def to_xml_string(str = '')
193
169
  classname = @allowed_types[0].name.split('::').last
194
170
  el_name = serialize_as.to_s || (classname[0,1].downcase + classname[1..-1])
195
- str << '<' << el_name << ' count="' << @list.size.to_s << '">'
196
- @list.each { |item| item.to_xml_string(str) }
197
- str << '</' << el_name << '>'
171
+ str << ('<' << el_name << ' count="' << size.to_s << '">')
172
+ each { |item| item.to_xml_string(str) }
173
+ str << ('</' << el_name << '>')
198
174
  end
199
175
 
200
176
  end
@@ -6,14 +6,14 @@ module Axlsx
6
6
 
7
7
  # Packing for the Storage when pushing an array of items into a byte stream
8
8
  # Name, name length, type, color, left sibling, right sibling, child, classid, state, created, modified, sector, size
9
- PACKING = "s32 s1 c2 l3 x16 x4 q2 l q"
9
+ PACKING = "s32 s1 c2 l3 x16 x4 q2 l q".freeze
10
10
 
11
11
  # storage types
12
12
  TYPES = {
13
13
  :root=>5,
14
14
  :stream=>2,
15
15
  :storage=>1
16
- }
16
+ }.freeze
17
17
 
18
18
  # Creates a byte string for this storage
19
19
  # @return [String]
@@ -45,7 +45,7 @@ module Axlsx
45
45
  # Sets the color for this storage
46
46
  # @param [Integer] v Must be one of the COLORS constant hash values
47
47
  def color=(v)
48
- RestrictionValidator.validate "Storage.color", COLORS.values, v
48
+ RestrictionValidator.validate :storage_color, COLORS.values, v
49
49
  @color = v
50
50
  end
51
51
 
@@ -116,7 +116,7 @@ module Axlsx
116
116
  # Sets the type for this storage.
117
117
  # @param [Integer] v the type to specify must be one of the TYPES constant hash values.
118
118
  def type=(v)
119
- RestrictionValidator.validate "Storage.type", TYPES.values, v
119
+ RestrictionValidator.validate :storage_type, TYPES.values, v
120
120
  @type = v
121
121
  end
122
122
 
@@ -0,0 +1,7 @@
1
+ unless String.method_defined? :prepend
2
+ class String
3
+ def prepend(other_str)
4
+ insert(0, other_str)
5
+ end
6
+ end
7
+ end
@@ -52,19 +52,17 @@ module Axlsx
52
52
  # @return [Boolean] true if validation succeeds.
53
53
  # @see validate_boolean
54
54
  def self.validate(name, types, v, other=false)
55
- types = [types] unless types.is_a? Array
56
55
  if other.is_a?(Proc)
57
56
  raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v)
58
57
  end
59
- if v.class == Class
60
- types.each { |t| return if v.ancestors.include?(t) }
61
- else
62
- types.each { |t| return if v.is_a?(t) }
58
+ v_class = v.is_a?(Class) ? v : v.class
59
+ Array(types).each do |t|
60
+ return if v_class <= t
63
61
  end
64
62
  raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect])
65
63
  end
66
64
  end
67
-
65
+
68
66
 
69
67
  # Requires that the value can be converted to an integer
70
68
  # @para, [Any] v the value to validate
@@ -80,12 +78,15 @@ module Axlsx
80
78
  def self.validate_angle(v)
81
79
  raise ArgumentError, (ERR_ANGLE % v.inspect) unless (v.to_i >= -5400000 && v.to_i <= 5400000)
82
80
  end
81
+
82
+ UINT_VALIDATOR = lambda { |arg| arg.respond_to?(:>=) && arg >= 0 }
83
+
83
84
  # Requires that the value is a Fixnum or Integer and is greater or equal to 0
84
85
  # @param [Any] v The value validated
85
86
  # @raise [ArgumentError] raised if the value is not a Fixnum or Integer value greater or equal to 0
86
87
  # @return [Boolean] true if the data is valid
87
88
  def self.validate_unsigned_int(v)
88
- DataTypeValidator.validate(:unsigned_int, [Fixnum, Integer], v, lambda { |arg| arg.respond_to?(:>=) && arg >= 0 })
89
+ DataTypeValidator.validate(:unsigned_int, Integer, v, UINT_VALIDATOR)
89
90
  end
90
91
 
91
92
  # Requires that the value is a Fixnum Integer or Float and is greater or equal to 0
@@ -93,13 +94,13 @@ module Axlsx
93
94
  # @raise [ArgumentError] raised if the value is not a Fixnun, Integer, Float value greater or equal to 0
94
95
  # @return [Boolean] true if the data is valid
95
96
  def self.validate_unsigned_numeric(v)
96
- DataTypeValidator.validate("Invalid column width", [Fixnum, Integer, Float], v, lambda { |arg| arg.respond_to?(:>=) && arg.to_i >= 0 })
97
+ DataTypeValidator.validate(:unsigned_numeric, Numeric, v, UINT_VALIDATOR)
97
98
  end
98
99
 
99
- # Requires that the value is a Fixnum or Integer
100
+ # Requires that the value is a Integer
100
101
  # @param [Any] v The value validated
101
102
  def self.validate_int(v)
102
- DataTypeValidator.validate :unsigned_int, [Fixnum, Integer], v
103
+ DataTypeValidator.validate :signed_int, Integer, v
103
104
  end
104
105
 
105
106
  # Requires that the value is a form that can be evaluated as a boolean in an xml document.
@@ -107,7 +108,7 @@ module Axlsx
107
108
  # it must be one of 0, 1, "true", "false", :true, :false, true, false, "0", or "1"
108
109
  # @param [Any] v The value validated
109
110
  def self.validate_boolean(v)
110
- DataTypeValidator.validate(:boolean, [Fixnum, String, Integer, Symbol, TrueClass, FalseClass], v, lambda { |arg| [0, 1, "true", "false", :true, :false, true, false, "0", "1"].include?(arg) })
111
+ DataTypeValidator.validate(:boolean, [String, Integer, Symbol, TrueClass, FalseClass], v, lambda { |arg| [0, 1, "true", "false", :true, :false, true, false, "0", "1"].include?(arg) })
111
112
  end
112
113
 
113
114
  # Requires that the value is a String
@@ -130,12 +131,12 @@ module Axlsx
130
131
 
131
132
  # Requires that the value is an integer ranging from 10 to 400.
132
133
  def self.validate_scale_10_400(v)
133
- DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg >= 10 && arg <= 400 }
134
+ DataTypeValidator.validate "page_scale", Integer, v, lambda { |arg| arg >= 10 && arg <= 400 }
134
135
  end
135
136
 
136
137
  # Requires that the value is an integer ranging from 10 to 400 or 0.
137
138
  def self.validate_scale_0_10_400(v)
138
- DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg == 0 || (arg >= 10 && arg <= 400) }
139
+ DataTypeValidator.validate "page_scale", Integer, v, lambda { |arg| arg == 0 || (arg >= 10 && arg <= 400) }
139
140
  end
140
141
 
141
142
  # Requires that the value is one of :default, :landscape, or :portrait.
@@ -297,4 +298,10 @@ module Axlsx
297
298
  def self.validate_display_blanks_as(v)
298
299
  RestrictionValidator.validate :display_blanks_as, [:gap, :span, :zero], v
299
300
  end
301
+
302
+ # Requires that the value is one of :visible, :hidden, :very_hidden
303
+ def self.validate_view_visibility(v)
304
+ RestrictionValidator.validate :visibility, [:visible, :hidden, :very_hidden], v
305
+ end
306
+
300
307
  end
@@ -1,5 +1,5 @@
1
1
  module Axlsx
2
2
 
3
3
  # The current version
4
- VERSION = "2.0.1"
4
+ VERSION = "2.1.0.pre"
5
5
  end
@@ -24,16 +24,16 @@
24
24
  # </xsd:simpleContent>
25
25
 
26
26
  module Axlsx
27
- # This element defines the defined names that are defined within this workbook.
27
+ # This element defines the defined names that are defined within this workbook.
28
28
  # Defined names are descriptive text that is used to represents a cell, range of cells, formula, or constant value.
29
29
  # Use easy-to-understand names, such as Products, to refer to hard to understand ranges, such as Sales!C20:C30.
30
- # A defined name in a formula can make it easier to understand the purpose of the formula.
30
+ # A defined name in a formula can make it easier to understand the purpose of the formula.
31
31
  # @example
32
32
  # The formula =SUM(FirstQuarterSales) might be easier to identify than =SUM(C20:C30
33
33
  #
34
34
  # Names are available to any sheet.
35
35
  # @example
36
- # If the name ProjectedSales refers to the range A20:A30 on the first worksheet in a workbook,
36
+ # If the name ProjectedSales refers to the range A20:A30 on the first worksheet in a workbook,
37
37
  # you can use the name ProjectedSales on any other sheet in the same workbook to refer to range A20:A30 on the first worksheet.
38
38
  # Names can also be used to represent formulas or values that do not change (constants).
39
39
  #
@@ -71,7 +71,7 @@ module Axlsx
71
71
  # applied. This represents the source data range, unfiltered.
72
72
  # b. This defined name refers to a range to which an AutoFilter has been
73
73
  # applied.
74
- # _xlnm.Extract: this defined name refers to the range containing the filtered output
74
+ # _xlnm.Extract: this defined name refers to the range containing the filtered output
75
75
  # values resulting from applying an advanced filter criteria to a source range.
76
76
  # Miscellaneous
77
77
  # _xlnm.Consolidate_Area: the defined name refers to a consolidation area.
@@ -88,14 +88,14 @@ module Axlsx
88
88
  # This attribute is used when there is an add-in or other code project associated with the file.
89
89
  # @option [Boolean] vb_proceedure - Specifies a boolean value that indicates whether the defined name is related to an external function, command, or other executable code.
90
90
  # @option [Boolean] xlm - Specifies a boolean value that indicates whether the defined name is related to an external function, command, or other executable code.
91
- # @option [Integer] function_group_id - Specifies the function group index if the defined name refers to a function.
91
+ # @option [Integer] function_group_id - Specifies the function group index if the defined name refers to a function.
92
92
  # The function group defines the general category for the function.
93
93
  # This attribute is used when there is an add-in or other code project associated with the file.
94
94
  # See Open Office XML Part 1 for more info.
95
95
  # @option [String] short_cut_key - Specifies the keyboard shortcut for the defined name.
96
- # @option [Boolean] publish_to_server - Specifies a boolean value that indicates whether the defined name is included in the
96
+ # @option [Boolean] publish_to_server - Specifies a boolean value that indicates whether the defined name is included in the
97
97
  # version of the workbook that is published to or rendered on a Web or application server.
98
- # @option [Boolean] workbook_parameter - Specifies a boolean value that indicates that the name is used as a workbook parameter on a
98
+ # @option [Boolean] workbook_parameter - Specifies a boolean value that indicates that the name is used as a workbook parameter on a
99
99
  # version of the workbook that is published to or rendered on a Web or application server.
100
100
  def initialize(formula, options={})
101
101
  @formula = formula
@@ -116,14 +116,13 @@ module Axlsx
116
116
  boolean_attr_accessor :workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden
117
117
 
118
118
  serializable_attributes :short_cut_key, :status_bar, :help, :description, :custom_menu, :comment,
119
- :workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden, :name, :local_sheet_id
119
+ :workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden, :local_sheet_id
120
120
 
121
121
  def to_xml_string(str='')
122
- raise ArgumentError, 'you must specify the name for this defined name. Please read the documentation for Axlsx::DefinedName for more details' unless name
123
- str << '<definedName '
122
+ raise ArgumentError, 'you must specify the name for this defined name. Please read the documentation for Axlsx::DefinedName for more details' unless name
123
+ str << ('<definedName ' << 'name="' << name << '" ')
124
124
  serialized_attributes str
125
- str << '>' << @formula
126
- str << '</definedName>'
125
+ str << ('>' << @formula << '</definedName>')
127
126
  end
128
127
  end
129
128
  end