caxlsx 2.0.2 → 3.0.4

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 (210) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +125 -30
  3. data/README.md +65 -151
  4. data/Rakefile +9 -11
  5. data/examples/{image1.jpeg → assets/image1.jpeg} +0 -0
  6. data/examples/generate.rb +15 -0
  7. data/lib/axlsx.rb +35 -17
  8. data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
  9. data/lib/axlsx/content_type/content_type.rb +1 -1
  10. data/lib/axlsx/doc_props/app.rb +1 -1
  11. data/lib/axlsx/doc_props/core.rb +5 -5
  12. data/lib/axlsx/drawing/area_chart.rb +99 -0
  13. data/lib/axlsx/drawing/area_series.rb +110 -0
  14. data/lib/axlsx/drawing/axes.rb +1 -1
  15. data/lib/axlsx/drawing/axis.rb +12 -9
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
  17. data/lib/axlsx/drawing/bar_chart.rb +143 -0
  18. data/lib/axlsx/drawing/bar_series.rb +12 -14
  19. data/lib/axlsx/drawing/bubble_chart.rb +59 -0
  20. data/lib/axlsx/drawing/bubble_series.rb +63 -0
  21. data/lib/axlsx/drawing/cat_axis.rb +5 -5
  22. data/lib/axlsx/drawing/chart.rb +52 -8
  23. data/lib/axlsx/drawing/d_lbls.rb +4 -4
  24. data/lib/axlsx/drawing/drawing.rb +6 -1
  25. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  26. data/lib/axlsx/drawing/hyperlink.rb +1 -3
  27. data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
  28. data/lib/axlsx/drawing/line_chart.rb +10 -10
  29. data/lib/axlsx/drawing/line_series.rb +32 -3
  30. data/lib/axlsx/drawing/marker.rb +1 -1
  31. data/lib/axlsx/drawing/num_data.rb +4 -4
  32. data/lib/axlsx/drawing/num_data_source.rb +6 -6
  33. data/lib/axlsx/drawing/num_val.rb +3 -1
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +3 -2
  35. data/lib/axlsx/drawing/pic.rb +25 -19
  36. data/lib/axlsx/drawing/picture_locking.rb +1 -3
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
  38. data/lib/axlsx/drawing/pie_series.rb +6 -6
  39. data/lib/axlsx/drawing/scaling.rb +6 -6
  40. data/lib/axlsx/drawing/scatter_chart.rb +10 -10
  41. data/lib/axlsx/drawing/scatter_series.rb +40 -7
  42. data/lib/axlsx/drawing/ser_axis.rb +2 -2
  43. data/lib/axlsx/drawing/series.rb +3 -3
  44. data/lib/axlsx/drawing/series_title.rb +4 -2
  45. data/lib/axlsx/drawing/str_data.rb +3 -3
  46. data/lib/axlsx/drawing/str_val.rb +3 -1
  47. data/lib/axlsx/drawing/title.rb +23 -4
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
  49. data/lib/axlsx/drawing/val_axis.rb +1 -1
  50. data/lib/axlsx/drawing/view_3D.rb +2 -2
  51. data/lib/axlsx/drawing/vml_drawing.rb +1 -1
  52. data/lib/axlsx/package.rb +58 -47
  53. data/lib/axlsx/rels/relationship.rb +27 -26
  54. data/lib/axlsx/rels/relationships.rb +7 -4
  55. data/lib/axlsx/stylesheet/border_pr.rb +2 -2
  56. data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
  57. data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
  58. data/lib/axlsx/stylesheet/cell_style.rb +1 -3
  59. data/lib/axlsx/stylesheet/color.rb +1 -3
  60. data/lib/axlsx/stylesheet/font.rb +11 -3
  61. data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
  62. data/lib/axlsx/stylesheet/num_fmt.rb +10 -3
  63. data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
  64. data/lib/axlsx/stylesheet/styles.rb +7 -7
  65. data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
  66. data/lib/axlsx/util/accessors.rb +6 -6
  67. data/lib/axlsx/util/constants.rb +108 -99
  68. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  69. data/lib/axlsx/util/options_parser.rb +2 -1
  70. data/lib/axlsx/util/serialized_attributes.rb +16 -6
  71. data/lib/axlsx/util/simple_typed_list.rb +28 -52
  72. data/lib/axlsx/util/storage.rb +4 -4
  73. data/lib/axlsx/util/validators.rb +31 -19
  74. data/lib/axlsx/util/zip_command.rb +73 -0
  75. data/lib/axlsx/version.rb +1 -1
  76. data/lib/axlsx/workbook/defined_name.rb +11 -12
  77. data/lib/axlsx/workbook/defined_names.rb +2 -2
  78. data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
  79. data/lib/axlsx/workbook/workbook.rb +36 -20
  80. data/lib/axlsx/workbook/workbook_view.rb +80 -0
  81. data/lib/axlsx/workbook/workbook_views.rb +22 -0
  82. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
  83. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
  84. data/lib/axlsx/workbook/worksheet/break.rb +1 -3
  85. data/lib/axlsx/workbook/worksheet/cell.rb +164 -75
  86. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +63 -43
  87. data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
  88. data/lib/axlsx/workbook/worksheet/cfvos.rb +4 -1
  89. data/lib/axlsx/workbook/worksheet/col.rb +14 -13
  90. data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
  91. data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
  92. data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
  93. data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
  94. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
  95. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
  96. data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
  97. data/lib/axlsx/workbook/worksheet/data_validation.rb +8 -6
  98. data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
  99. data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
  100. data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
  101. data/lib/axlsx/workbook/worksheet/merged_cells.rb +4 -2
  102. data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
  103. data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
  104. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
  105. data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
  106. data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
  107. data/lib/axlsx/workbook/worksheet/pivot_table.rb +44 -28
  108. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
  109. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
  110. data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
  111. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -2
  112. data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -0
  113. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -0
  114. data/lib/axlsx/workbook/worksheet/row.rb +42 -52
  115. data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
  116. data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
  117. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  118. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
  119. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
  120. data/lib/axlsx/workbook/worksheet/table.rb +6 -6
  121. data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
  122. data/lib/axlsx/workbook/worksheet/tables.rb +4 -1
  123. data/lib/axlsx/workbook/worksheet/worksheet.rb +76 -81
  124. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
  125. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
  126. data/lib/caxlsx.rb +2 -0
  127. data/test/drawing/tc_area_chart.rb +39 -0
  128. data/test/drawing/tc_area_series.rb +71 -0
  129. data/test/drawing/tc_axis.rb +27 -0
  130. data/test/drawing/tc_bar_chart.rb +71 -0
  131. data/test/drawing/tc_bubble_chart.rb +44 -0
  132. data/test/drawing/tc_bubble_series.rb +21 -0
  133. data/test/drawing/tc_chart.rb +23 -10
  134. data/test/drawing/tc_data_source.rb +6 -0
  135. data/test/drawing/tc_drawing.rb +4 -4
  136. data/test/drawing/tc_hyperlink.rb +1 -1
  137. data/test/drawing/tc_line_chart.rb +5 -5
  138. data/test/drawing/tc_line_series.rb +47 -6
  139. data/test/drawing/tc_one_cell_anchor.rb +1 -1
  140. data/test/drawing/tc_pic.rb +11 -15
  141. data/test/drawing/tc_pie_series.rb +2 -1
  142. data/test/drawing/tc_scatter_series.rb +36 -1
  143. data/test/drawing/tc_series_title.rb +21 -0
  144. data/test/drawing/tc_str_val.rb +9 -0
  145. data/test/drawing/tc_title.rb +21 -0
  146. data/test/fixtures/image1.gif +0 -0
  147. data/test/fixtures/image1.jpeg +0 -0
  148. data/test/fixtures/image1.jpg +0 -0
  149. data/test/fixtures/image1.png +0 -0
  150. data/test/fixtures/image1_fake.jpg +0 -0
  151. data/test/rels/tc_relationship.rb +8 -0
  152. data/test/stylesheet/tc_font.rb +14 -2
  153. data/test/stylesheet/tc_styles.rb +29 -3
  154. data/test/tc_axlsx.rb +37 -0
  155. data/test/tc_helper.rb +2 -0
  156. data/test/tc_package.rb +50 -13
  157. data/test/util/tc_mime_type_utils.rb +13 -0
  158. data/test/util/tc_simple_typed_list.rb +2 -3
  159. data/test/util/tc_validators.rb +35 -11
  160. data/test/workbook/tc_defined_name.rb +12 -4
  161. data/test/workbook/tc_shared_strings_table.rb +16 -1
  162. data/test/workbook/tc_workbook.rb +38 -3
  163. data/test/workbook/tc_workbook_view.rb +50 -0
  164. data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
  165. data/test/workbook/worksheet/tc_break.rb +1 -1
  166. data/test/workbook/worksheet/tc_cell.rb +143 -9
  167. data/test/workbook/worksheet/tc_col.rb +18 -3
  168. data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
  169. data/test/workbook/worksheet/tc_data_bar.rb +1 -1
  170. data/test/workbook/worksheet/tc_data_validation.rb +11 -11
  171. data/test/workbook/worksheet/tc_header_footer.rb +2 -2
  172. data/test/workbook/worksheet/tc_icon_set.rb +1 -1
  173. data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
  174. data/test/workbook/worksheet/tc_page_setup.rb +3 -3
  175. data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
  176. data/test/workbook/worksheet/tc_print_options.rb +1 -1
  177. data/test/workbook/worksheet/tc_rich_text.rb +44 -0
  178. data/test/workbook/worksheet/tc_rich_text_run.rb +173 -0
  179. data/test/workbook/worksheet/tc_row.rb +24 -2
  180. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
  181. data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
  182. data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
  183. data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
  184. data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
  185. data/test/workbook/worksheet/tc_table.rb +2 -3
  186. data/test/workbook/worksheet/tc_worksheet.rb +123 -60
  187. metadata +180 -128
  188. data/examples/2010_comments.rb +0 -17
  189. data/examples/anchor_swapping.rb +0 -28
  190. data/examples/auto_filter.rb +0 -16
  191. data/examples/basic_charts.rb +0 -58
  192. data/examples/chart_colors.rb +0 -88
  193. data/examples/colored_links.rb +0 -59
  194. data/examples/conditional_formatting/example_conditional_formatting.rb +0 -74
  195. data/examples/conditional_formatting/getting_barred.rb +0 -37
  196. data/examples/conditional_formatting/hitting_the_high_notes.rb +0 -37
  197. data/examples/conditional_formatting/scaled_colors.rb +0 -39
  198. data/examples/conditional_formatting/stop_and_go.rb +0 -37
  199. data/examples/data_validation.rb +0 -50
  200. data/examples/example.rb +0 -777
  201. data/examples/extractive.rb +0 -45
  202. data/examples/ios_preview.rb +0 -14
  203. data/examples/page_setup.rb +0 -11
  204. data/examples/pivot_table.rb +0 -39
  205. data/examples/sheet_protection.rb +0 -10
  206. data/examples/skydrive/real_example.rb +0 -63
  207. data/examples/styles.rb +0 -66
  208. data/examples/underline.rb +0 -13
  209. data/examples/wrap_text.rb +0 -21
  210. data/lib/axlsx/util/parser.rb +0 -44
@@ -5,32 +5,40 @@ module Axlsx
5
5
  class Relationship
6
6
 
7
7
  class << self
8
- # Keeps track of all instances of this class.
8
+ # Keeps track of relationship ids in use.
9
9
  # @return [Array]
10
- def instances
11
- @instances ||= []
10
+ def ids_cache
11
+ Thread.current[:axlsx_relationship_ids_cache] ||= {}
12
12
  end
13
-
14
- # Clear cached instances.
13
+
14
+ # Initialize cached ids.
15
15
  #
16
16
  # This should be called before serializing a package (see {Package#serialize} and
17
17
  # {Package#to_stream}) to make sure that serialization is idempotent (i.e.
18
18
  # Relationship instances are generated with the same IDs everytime the package
19
19
  # is serialized).
20
+ def initialize_ids_cache
21
+ Thread.current[:axlsx_relationship_ids_cache] = {}
22
+ end
23
+
24
+ # Clear cached ids.
20
25
  #
21
- # Also, calling this avoids memory leaks (cached instances lingering around
26
+ # This should be called after serializing a package (see {Package#serialize} and
27
+ # {Package#to_stream}) to free the memory allocated for cache.
28
+ #
29
+ # Also, calling this avoids memory leaks (cached ids lingering around
22
30
  # forever).
23
- def clear_cached_instances
24
- @instances = []
31
+ def clear_ids_cache
32
+ Thread.current[:axlsx_relationship_ids_cache] = nil
25
33
  end
26
34
 
27
35
  # Generate and return a unique id (eg. `rId123`) Used for setting {#Id}.
28
36
  #
29
- # The generated id depends on the number of cached instances, so using
30
- # {clear_cached_instances} will automatically reset the generated ids, too.
37
+ # The generated id depends on the number of previously cached ids, so using
38
+ # {clear_ids_cache} will automatically reset the generated ids, too.
31
39
  # @return [String]
32
40
  def next_free_id
33
- "rId#{@instances.size + 1}"
41
+ "rId#{ids_cache.size + 1}"
34
42
  end
35
43
  end
36
44
 
@@ -80,12 +88,7 @@ module Axlsx
80
88
  self.Target=target
81
89
  self.Type=type
82
90
  self.TargetMode = options[:target_mode] if options[:target_mode]
83
- @Id = if (existing = self.class.instances.find{ |i| should_use_same_id_as?(i) })
84
- existing.Id
85
- else
86
- self.class.next_free_id
87
- end
88
- self.class.instances << self
91
+ @Id = (self.class.ids_cache[ids_cache_key] ||= self.class.next_free_id)
89
92
  end
90
93
 
91
94
  # @see Target
@@ -102,11 +105,11 @@ module Axlsx
102
105
  def to_xml_string(str = '')
103
106
  h = self.instance_values.reject{|k, _| k == "source_obj"}
104
107
  str << '<Relationship '
105
- str << h.map { |key, value| '' << key.to_s << '="' << Axlsx::coder.encode(value.to_s) << '"'}.join(' ')
108
+ str << (h.map { |key, value| '' << key.to_s << '="' << Axlsx::coder.encode(value.to_s) << '"'}.join(' '))
106
109
  str << '/>'
107
110
  end
108
111
 
109
- # Whether this relationship should use the same id as `other`.
112
+ # A key that determines whether this relationship should use already generated id.
110
113
  #
111
114
  # Instances designating the same relationship need to use the same id. We can not simply
112
115
  # compare the {#Target} attribute, though: `foo/bar.xml`, `../foo/bar.xml`,
@@ -116,13 +119,11 @@ module Axlsx
116
119
  # then {#Target} will be an absolute URL and thus can safely be compared).
117
120
  #
118
121
  # @todo Implement comparison of {#Target} based on normalized path names.
119
- # @param other [Relationship]
120
- def should_use_same_id_as?(other)
121
- result = self.source_obj == other.source_obj && self.Type == other.Type && self.TargetMode == other.TargetMode
122
- if self.TargetMode == :External
123
- result &&= self.Target == other.Target
124
- end
125
- result
122
+ # @return [Array]
123
+ def ids_cache_key
124
+ key = [source_obj, self.Type, self.TargetMode]
125
+ key << self.Target if self.TargetMode == :External
126
+ key
126
127
  end
127
128
 
128
129
  end
@@ -10,17 +10,20 @@ require 'axlsx/rels/relationship.rb'
10
10
  def initialize
11
11
  super Relationship
12
12
  end
13
-
13
+
14
14
  # The relationship instance for the given source object, or nil if none exists.
15
15
  # @see Relationship#source_obj
16
16
  # @return [Relationship]
17
17
  def for(source_obj)
18
- @list.find{ |rel| rel.source_obj == source_obj }
18
+ find{ |rel| rel.source_obj == source_obj }
19
19
  end
20
-
20
+
21
+ # serialize relationships
22
+ # @param [String] str
23
+ # @return [String]
21
24
  def to_xml_string(str = '')
22
25
  str << '<?xml version="1.0" encoding="UTF-8"?>'
23
- str << '<Relationships xmlns="' << RELS_R << '">'
26
+ str << ('<Relationships xmlns="' << RELS_R << '">')
24
27
  each{ |rel| rel.to_xml_string(str) }
25
28
  str << '</Relationships>'
26
29
  end
@@ -62,9 +62,9 @@ module Axlsx
62
62
  # @param [String] str
63
63
  # @return [String]
64
64
  def to_xml_string(str = '')
65
- str << '<' << @name.to_s << ' style="' << @style.to_s << '">'
65
+ str << ('<' << @name.to_s << ' style="' << @style.to_s << '">')
66
66
  @color.to_xml_string(str) if @color.is_a?(Color)
67
- str << '</' << @name.to_s << '>'
67
+ str << ('</' << @name.to_s << '>')
68
68
  end
69
69
 
70
70
  end
@@ -125,9 +125,7 @@ module Axlsx
125
125
  # @param [String] str
126
126
  # @return [String]
127
127
  def to_xml_string(str = '')
128
- str << '<alignment '
129
- serialized_attributes str
130
- str << '/>'
128
+ serialized_tag('alignment', str)
131
129
  end
132
130
 
133
131
  end
@@ -34,9 +34,7 @@ module Axlsx
34
34
  # @param [String] str
35
35
  # @return [String]
36
36
  def to_xml_string(str = '')
37
- str << '<protection '
38
- serialized_attributes str
39
- str << '/>'
37
+ serialized_tag('protection', str)
40
38
  end
41
39
 
42
40
  end
@@ -64,9 +64,7 @@ module Axlsx
64
64
  # @param [String] str
65
65
  # @return [String]
66
66
  def to_xml_string(str = '')
67
- str << '<cellStyle '
68
- serialized_attributes str
69
- str << '/>'
67
+ serialized_tag('cellStyle', str)
70
68
  end
71
69
 
72
70
  end
@@ -70,9 +70,7 @@ module Axlsx
70
70
  # @param [String] str
71
71
  # @return [String]
72
72
  def to_xml_string(str = '', tag_name = 'color')
73
- str << "<" << tag_name << " "
74
- serialized_attributes str
75
- str << "/>"
73
+ serialized_tag('' + tag_name + '', str)
76
74
  end
77
75
  end
78
76
  end
@@ -76,7 +76,10 @@ module Axlsx
76
76
  attr_reader :i
77
77
 
78
78
  # Indicates if the font should be rendered underlined
79
- # @return [Boolean]
79
+ # It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true, false
80
+ # @return [String]
81
+ # @note
82
+ # true or false is for backwards compatibility and is reassigned to :single or :none respectively
80
83
  attr_reader :u
81
84
 
82
85
  # Indicates if the font should be rendered with a strikthrough
@@ -118,7 +121,12 @@ module Axlsx
118
121
  # @see i
119
122
  def i=(v) Axlsx::validate_boolean v; @i = v end
120
123
  # @see u
121
- def u=(v) Axlsx::validate_boolean v; @u = v end
124
+ def u=(v)
125
+ v = :single if (v == true || v == 1 || v == :true || v == 'true')
126
+ v = :none if (v == false || v == 0 || v == :false || v == 'false')
127
+ Axlsx::validate_cell_u v
128
+ @u = v
129
+ end
122
130
  # @see strike
123
131
  def strike=(v) Axlsx::validate_boolean v; @strike = v end
124
132
  # @see outline
@@ -140,7 +148,7 @@ module Axlsx
140
148
  def to_xml_string(str = '')
141
149
  str << '<font>'
142
150
  instance_values.each do |k, v|
143
- v.is_a?(Color) ? v.to_xml_string(str) : (str << '<' << k.to_s << ' val="' << v.to_s << '"/>')
151
+ v.is_a?(Color) ? v.to_xml_string(str) : (str << ('<' << k.to_s << ' val="' << Axlsx.booleanize(v).to_s << '"/>'))
144
152
  end
145
153
  str << '</font>'
146
154
  end
@@ -29,7 +29,7 @@ module Axlsx
29
29
  # @param [String] str
30
30
  # @return [String]
31
31
  def to_xml_string(str = '')
32
- str << '<stop position="' << position.to_s << '">'
32
+ str << ('<stop position="' << position.to_s << '">')
33
33
  self.color.to_xml_string(str)
34
34
  str << '</stop>'
35
35
  end
@@ -70,9 +70,16 @@ module Axlsx
70
70
  # @param [String] str
71
71
  # @return [String]
72
72
  def to_xml_string(str = '')
73
- str << '<numFmt '
74
- serialized_attributes str
75
- str << '/>'
73
+ serialized_tag('numFmt', str)
74
+ end
75
+
76
+ # Override to avoid removing underscores
77
+ def serialized_attributes(str = '', additional_attributes = {})
78
+ attributes = declared_attributes.merge! additional_attributes
79
+ attributes.each do |key, value|
80
+ str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.booleanize(value)}\" "
81
+ end
82
+ str
76
83
  end
77
84
 
78
85
  end
@@ -59,7 +59,7 @@ module Axlsx
59
59
  # @param [String] str
60
60
  # @return [String]
61
61
  def to_xml_string(str = '')
62
- str << '<patternFill patternType="' << patternType.to_s << '">'
62
+ str << ('<patternFill patternType="' << patternType.to_s << '">')
63
63
  if fgColor.is_a?(Color)
64
64
  fgColor.to_xml_string str, "fgColor"
65
65
  end
@@ -128,7 +128,7 @@ module Axlsx
128
128
  # @option options [Boolean] i Indicates if the text should be italicised
129
129
  # @option options [Boolean] u Indicates if the text should be underlined
130
130
  # @option options [Boolean] strike Indicates if the text should be rendered with a strikethrough
131
- # @option options [Boolean] strike Indicates if the text should be rendered with a shadow
131
+ # @option options [Boolean] shadow Indicates if the text should be rendered with a shadow
132
132
  # @option options [Integer] charset The character set to use.
133
133
  # @option options [Integer] family The font family to use.
134
134
  # @option options [String] font_name The name of the font to use
@@ -151,7 +151,7 @@ module Axlsx
151
151
  # ws = p.workbook.add_worksheet
152
152
  #
153
153
  # # black text on a white background at 14pt with thin borders!
154
- # title = ws.style.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
154
+ # title = ws.styles.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
155
155
  #
156
156
  # ws.add_row ["Least Popular Pets"]
157
157
  # ws.add_row ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
@@ -168,18 +168,18 @@ module Axlsx
168
168
  # ws = p.workbook.add_worksheet
169
169
  #
170
170
  # # define your styles
171
- # title = ws.style.add_style(:bg_color => "FFFF0000",
171
+ # title = ws.styles.add_style(:bg_color => "FFFF0000",
172
172
  # :fg_color=>"#FF000000",
173
173
  # :border=>Axlsx::STYLE_THIN_BORDER,
174
174
  # :alignment=>{:horizontal => :center})
175
175
  #
176
- # date_time = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS,
176
+ # date_time = ws.styles.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS,
177
177
  # :border=>Axlsx::STYLE_THIN_BORDER)
178
178
  #
179
- # percent = ws.style.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
179
+ # percent = ws.styles.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
180
180
  # :border=>Axlsx::STYLE_THIN_BORDER)
181
181
  #
182
- # currency = ws.style.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
182
+ # currency = ws.styles.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
183
183
  # :border=>Axlsx::STYLE_THIN_BORDER)
184
184
  #
185
185
  # # build your rows
@@ -362,7 +362,7 @@ module Axlsx
362
362
  # @param [String] str
363
363
  # @return [String]
364
364
  def to_xml_string(str = '')
365
- str << '<styleSheet xmlns="' << XML_NS << '">'
365
+ str << ('<styleSheet xmlns="' << XML_NS << '">')
366
366
  [:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
367
367
  self.instance_values[key.to_s].to_xml_string(str) unless self.instance_values[key.to_s].nil?
368
368
  end
@@ -70,9 +70,7 @@ module Axlsx
70
70
  # @param [String] str
71
71
  # @return [String]
72
72
  def to_xml_string(str = '')
73
- str << '<tableStyleElement '
74
- serialized_attributes str
75
- str << '/>'
73
+ serialized_tag('tableStyleElement', str)
76
74
  end
77
75
 
78
76
  end
@@ -19,7 +19,7 @@ module Axlsx
19
19
  # @param [Array] symbols An array of symbols representing the
20
20
  # names of the attributes you will add to your class.
21
21
  def string_attr_accessor(*symbols)
22
- validated_attr_accessor(symbols, 'validate_string')
22
+ validated_attr_accessor(symbols, :validate_string)
23
23
  end
24
24
 
25
25
 
@@ -27,25 +27,25 @@ module Axlsx
27
27
  # @param [Array] symbols An array of symbols representing the
28
28
  # names of the attributes you will add to your class
29
29
  def unsigned_int_attr_accessor(*symbols)
30
- validated_attr_accessor(symbols, 'validate_unsigned_int')
30
+ validated_attr_accessor(symbols, :validate_unsigned_int)
31
31
  end
32
32
 
33
33
  # Creates one or more float (double?) attr_accessors
34
34
  # @param [Array] symbols An array of symbols representing the
35
35
  # names of the attributes you will add to your class
36
36
  def float_attr_accessor(*symbols)
37
- validated_attr_accessor(symbols, 'validate_float')
37
+ validated_attr_accessor(symbols, :validate_float)
38
38
  end
39
39
 
40
40
  # Creates on or more boolean validated attr_accessors
41
41
  # @param [Array] symbols An array of symbols representing the
42
42
  # names of the attributes you will add to your class.
43
43
  def boolean_attr_accessor(*symbols)
44
- validated_attr_accessor(symbols, 'validate_boolean')
44
+ validated_attr_accessor(symbols, :validate_boolean)
45
45
  end
46
46
 
47
47
  # Template for defining validated write accessors
48
- SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end"
48
+ SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end".freeze
49
49
 
50
50
  # Creates the reader and writer access methods
51
51
  # @param [Array] symbols The names of the attributes to create
@@ -55,7 +55,7 @@ module Axlsx
55
55
  def validated_attr_accessor(symbols, validator)
56
56
  symbols.each do |symbol|
57
57
  attr_reader symbol
58
- module_eval(SETTER % [symbol.to_s, validator, symbol.to_s], __FILE__, __LINE__)
58
+ module_eval(SETTER % [symbol, validator, symbol], __FILE__, __LINE__)
59
59
  end
60
60
  end
61
61
  end
@@ -1,263 +1,263 @@
1
1
  module Axlsx
2
2
 
3
3
  # XML Encoding
4
- ENCODING = "UTF-8"
4
+ ENCODING = "UTF-8".freeze
5
5
 
6
6
  # spreadsheetML namespace
7
- XML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
7
+ XML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main".freeze
8
8
 
9
9
  # content-types namespace
10
- XML_NS_T = "http://schemas.openxmlformats.org/package/2006/content-types"
10
+ XML_NS_T = "http://schemas.openxmlformats.org/package/2006/content-types".freeze
11
11
 
12
12
  # extended-properties namespace
13
- APP_NS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
13
+ APP_NS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties".freeze
14
14
 
15
15
  # doc props namespace
16
- APP_NS_VT = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"
16
+ APP_NS_VT = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes".freeze
17
17
 
18
18
  # core properties namespace
19
- CORE_NS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
19
+ CORE_NS = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties".freeze
20
20
 
21
21
  # dc elements (core) namespace
22
- CORE_NS_DC = "http://purl.org/dc/elements/1.1/"
22
+ CORE_NS_DC = "http://purl.org/dc/elements/1.1/".freeze
23
23
 
24
24
  # dcmit (core) namespcace
25
- CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/"
25
+ CORE_NS_DCMIT = "http://purl.org/dc/dcmitype/".freeze
26
26
 
27
27
  # dc terms namespace
28
- CORE_NS_DCT = "http://purl.org/dc/terms/"
28
+ CORE_NS_DCT = "http://purl.org/dc/terms/".freeze
29
29
 
30
30
  # xml schema namespace
31
- CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
31
+ CORE_NS_XSI = "http://www.w3.org/2001/XMLSchema-instance".freeze
32
32
 
33
33
  # Digital signature namespace
34
- DIGITAL_SIGNATURE_NS = "http://schemas.openxmlformats.org/package/2006/digital-signature"
34
+ DIGITAL_SIGNATURE_NS = "http://schemas.openxmlformats.org/package/2006/digital-signature".freeze
35
35
 
36
36
  # spreadsheet drawing namespace
37
- XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
37
+ XML_NS_XDR = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing".freeze
38
38
 
39
39
  # drawing namespace
40
- XML_NS_A = "http://schemas.openxmlformats.org/drawingml/2006/main"
40
+ XML_NS_A = "http://schemas.openxmlformats.org/drawingml/2006/main".freeze
41
41
 
42
42
  # chart namespace
43
- XML_NS_C = "http://schemas.openxmlformats.org/drawingml/2006/chart"
43
+ XML_NS_C = "http://schemas.openxmlformats.org/drawingml/2006/chart".freeze
44
44
 
45
45
  # relationships namespace
46
- XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
46
+ XML_NS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships".freeze
47
47
 
48
48
  # relationships name space
49
- RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships"
49
+ RELS_R = "http://schemas.openxmlformats.org/package/2006/relationships".freeze
50
50
 
51
51
  # table rels namespace
52
- TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table"
52
+ TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table".freeze
53
53
 
54
54
  # pivot table rels namespace
55
- PIVOT_TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable"
55
+ PIVOT_TABLE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable".freeze
56
56
 
57
57
  # pivot table cache definition namespace
58
- PIVOT_TABLE_CACHE_DEFINITION_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"
58
+ PIVOT_TABLE_CACHE_DEFINITION_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition".freeze
59
59
 
60
60
  # workbook rels namespace
61
- WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
61
+ WORKBOOK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument".freeze
62
62
 
63
63
  # worksheet rels namespace
64
- WORKSHEET_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
64
+ WORKSHEET_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet".freeze
65
65
 
66
66
  # app rels namespace
67
- APP_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
67
+ APP_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties".freeze
68
68
 
69
69
  # core rels namespace
70
- CORE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/metadata/core-properties"
70
+ CORE_R = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties".freeze
71
71
 
72
72
  # digital signature rels namespace
73
- DIGITAL_SIGNATURE_R = "http://schemas.openxmlformats.org/package/2006/relationships/digital- signature/signature"
73
+ DIGITAL_SIGNATURE_R = "http://schemas.openxmlformats.org/package/2006/relationships/digital- signature/signature".freeze
74
74
 
75
75
  # styles rels namespace
76
- STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
76
+ STYLES_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles".freeze
77
77
 
78
78
  # shared strings namespace
79
- SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
79
+ SHARED_STRINGS_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings".freeze
80
80
 
81
81
  # drawing rels namespace
82
- DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"
82
+ DRAWING_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing".freeze
83
83
 
84
84
  # chart rels namespace
85
- CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"
85
+ CHART_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart".freeze
86
86
 
87
87
  # image rels namespace
88
- IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
88
+ IMAGE_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image".freeze
89
89
 
90
90
  # hyperlink rels namespace
91
- HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
91
+ HYPERLINK_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink".freeze
92
92
 
93
93
  # comment rels namespace
94
- COMMENT_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
94
+ COMMENT_R = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments".freeze
95
95
 
96
96
  # comment relation for nil target
97
- COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments"
97
+ COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments".freeze
98
98
 
99
99
  #vml drawing relation namespace
100
100
  VML_DRAWING_R = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing'
101
101
 
102
102
  # VML Drawing content type
103
- VML_DRAWING_CT = "application/vnd.openxmlformats-officedocument.vmlDrawing"
103
+ VML_DRAWING_CT = "application/vnd.openxmlformats-officedocument.vmlDrawing".freeze
104
104
 
105
105
  # table content type
106
- TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml"
106
+ TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml".freeze
107
107
 
108
108
  # pivot table content type
109
- PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
109
+ PIVOT_TABLE_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml".freeze
110
110
 
111
111
  # pivot table cache definition content type
112
- PIVOT_TABLE_CACHE_DEFINITION_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"
112
+ PIVOT_TABLE_CACHE_DEFINITION_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml".freeze
113
113
 
114
114
  # workbook content type
115
- WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
115
+ WORKBOOK_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml".freeze
116
116
 
117
117
  # app content type
118
- APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml"
118
+ APP_CT = "application/vnd.openxmlformats-officedocument.extended-properties+xml".freeze
119
119
 
120
120
  # rels content type
121
- RELS_CT = "application/vnd.openxmlformats-package.relationships+xml"
121
+ RELS_CT = "application/vnd.openxmlformats-package.relationships+xml".freeze
122
122
 
123
123
  # styles content type
124
- STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
124
+ STYLES_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml".freeze
125
125
 
126
126
  # xml content type
127
- XML_CT = "application/xml"
127
+ XML_CT = "application/xml".freeze
128
128
 
129
129
  # worksheet content type
130
- WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
130
+ WORKSHEET_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml".freeze
131
131
 
132
132
  # shared strings content type
133
- SHARED_STRINGS_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"
133
+ SHARED_STRINGS_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml".freeze
134
134
 
135
135
  # core content type
136
- CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml"
136
+ CORE_CT = "application/vnd.openxmlformats-package.core-properties+xml".freeze
137
137
 
138
138
  # digital signature xml content type
139
- DIGITAL_SIGNATURE_XML_CT = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"
139
+ DIGITAL_SIGNATURE_XML_CT = "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml".freeze
140
140
 
141
141
  # digital signature origin content type
142
- DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin"
142
+ DIGITAL_SIGNATURE_ORIGIN_CT = "application/vnd.openxmlformats-package.digital-signature-origin".freeze
143
143
 
144
144
  # digital signature certificate content type
145
- DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate"
145
+ DIGITAL_SIGNATURE_CERTIFICATE_CT = "application/vnd.openxmlformats-package.digital-signature-certificate".freeze
146
146
 
147
147
  # chart content type
148
- CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
148
+ CHART_CT = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml".freeze
149
149
 
150
150
  # comments content type
151
- COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"
151
+ COMMENT_CT = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml".freeze
152
152
 
153
153
  # jpeg content type
154
- JPEG_CT = "image/jpeg"
154
+ JPEG_CT = "image/jpeg".freeze
155
155
 
156
156
  # gif content type
157
- GIF_CT = "image/gif"
157
+ GIF_CT = "image/gif".freeze
158
158
 
159
159
  # png content type
160
- PNG_CT = "image/png"
160
+ PNG_CT = "image/png".freeze
161
161
 
162
162
  #drawing content type
163
- DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml"
163
+ DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml".freeze
164
164
 
165
165
 
166
166
  # xml content type extensions
167
- XML_EX = "xml"
167
+ XML_EX = "xml".freeze
168
168
 
169
169
  # jpeg extension
170
- JPEG_EX = "jpeg"
170
+ JPEG_EX = "jpeg".freeze
171
171
 
172
172
  # gif extension
173
- GIF_EX = "gif"
173
+ GIF_EX = "gif".freeze
174
174
 
175
175
  # png extension
176
- PNG_EX = "png"
176
+ PNG_EX = "png".freeze
177
177
 
178
178
  # rels content type extension
179
- RELS_EX = "rels"
179
+ RELS_EX = "rels".freeze
180
180
 
181
181
  # workbook part
182
- WORKBOOK_PN = "xl/workbook.xml"
182
+ WORKBOOK_PN = "xl/workbook.xml".freeze
183
183
 
184
184
  # styles part
185
- STYLES_PN = "styles.xml"
185
+ STYLES_PN = "styles.xml".freeze
186
186
 
187
187
  # shared_strings part
188
- SHARED_STRINGS_PN = "sharedStrings.xml"
188
+ SHARED_STRINGS_PN = "sharedStrings.xml".freeze
189
189
 
190
190
  # app part
191
- APP_PN = "docProps/app.xml"
191
+ APP_PN = "docProps/app.xml".freeze
192
192
 
193
193
  # core part
194
- CORE_PN = "docProps/core.xml"
194
+ CORE_PN = "docProps/core.xml".freeze
195
195
 
196
196
  # content types part
197
- CONTENT_TYPES_PN = "[Content_Types].xml"
197
+ CONTENT_TYPES_PN = "[Content_Types].xml".freeze
198
198
 
199
199
  # rels part
200
- RELS_PN = "_rels/.rels"
200
+ RELS_PN = "_rels/.rels".freeze
201
201
 
202
202
  # workbook rels part
203
- WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels"
203
+ WORKBOOK_RELS_PN = "xl/_rels/workbook.xml.rels".freeze
204
204
 
205
205
  # worksheet part
206
- WORKSHEET_PN = "worksheets/sheet%d.xml"
206
+ WORKSHEET_PN = "worksheets/sheet%d.xml".freeze
207
207
 
208
208
  # worksheet rels part
209
- WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels"
209
+ WORKSHEET_RELS_PN = "worksheets/_rels/sheet%d.xml.rels".freeze
210
210
 
211
211
  # drawing part
212
- DRAWING_PN = "drawings/drawing%d.xml"
212
+ DRAWING_PN = "drawings/drawing%d.xml".freeze
213
213
 
214
214
  # drawing rels part
215
- DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels"
215
+ DRAWING_RELS_PN = "drawings/_rels/drawing%d.xml.rels".freeze
216
216
 
217
217
  # vml drawing part
218
- VML_DRAWING_PN = "drawings/vmlDrawing%d.vml"
218
+ VML_DRAWING_PN = "drawings/vmlDrawing%d.vml".freeze
219
219
 
220
220
  # drawing part
221
- TABLE_PN = "tables/table%d.xml"
221
+ TABLE_PN = "tables/table%d.xml".freeze
222
222
 
223
223
  # pivot table parts
224
- PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml"
224
+ PIVOT_TABLE_PN = "pivotTables/pivotTable%d.xml".freeze
225
225
 
226
226
  # pivot table cache definition part name
227
- PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml"
227
+ PIVOT_TABLE_CACHE_DEFINITION_PN = "pivotCache/pivotCacheDefinition%d.xml".freeze
228
228
 
229
229
  # pivot table rels parts
230
- PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels"
230
+ PIVOT_TABLE_RELS_PN = "pivotTables/_rels/pivotTable%d.xml.rels".freeze
231
231
 
232
232
  # chart part
233
- CHART_PN = "charts/chart%d.xml"
233
+ CHART_PN = "charts/chart%d.xml".freeze
234
234
 
235
235
  # chart part
236
- IMAGE_PN = "media/image%d.%s"
236
+ IMAGE_PN = "media/image%d.%s".freeze
237
237
 
238
238
  # comment part
239
- COMMENT_PN = "comments%d.xml"
239
+ COMMENT_PN = "comments%d.xml".freeze
240
240
 
241
241
  # location of schema files for validation
242
- SCHEMA_BASE = File.dirname(__FILE__)+'/../../schema/'
242
+ SCHEMA_BASE = (File.dirname(__FILE__)+'/../../schema/').freeze
243
243
 
244
244
  # App validation schema
245
- APP_XSD = SCHEMA_BASE + "shared-documentPropertiesExtended.xsd"
245
+ APP_XSD = (SCHEMA_BASE + "shared-documentPropertiesExtended.xsd").freeze
246
246
 
247
247
  # core validation schema
248
- CORE_XSD = SCHEMA_BASE + "opc-coreProperties.xsd"
248
+ CORE_XSD = (SCHEMA_BASE + "opc-coreProperties.xsd").freeze
249
249
 
250
250
  # content types validation schema
251
- CONTENT_TYPES_XSD = SCHEMA_BASE + "opc-contentTypes.xsd"
251
+ CONTENT_TYPES_XSD = (SCHEMA_BASE + "opc-contentTypes.xsd").freeze
252
252
 
253
253
  # rels validation schema
254
- RELS_XSD = SCHEMA_BASE + "opc-relationships.xsd"
254
+ RELS_XSD = (SCHEMA_BASE + "opc-relationships.xsd").freeze
255
255
 
256
256
  # spreadsheetML validation schema
257
- SML_XSD = SCHEMA_BASE + "sml.xsd"
257
+ SML_XSD = (SCHEMA_BASE + "sml.xsd").freeze
258
258
 
259
259
  # drawing validation schema
260
- DRAWING_XSD = SCHEMA_BASE + "dml-spreadsheetDrawing.xsd"
260
+ DRAWING_XSD = (SCHEMA_BASE + "dml-spreadsheetDrawing.xsd").freeze
261
261
 
262
262
  # number format id for pecentage formatting using the default formatting id.
263
263
  NUM_FMT_PERCENT = 9
@@ -275,37 +275,37 @@ module Axlsx
275
275
  STYLE_DATE = 2
276
276
 
277
277
  # error messages RestrictionValidor
278
- ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s."
278
+ ERR_RESTRICTION = "Invalid Data: %s. %s must be one of %s.".freeze
279
279
 
280
280
  # error message DataTypeValidator
281
- ERR_TYPE = "Invalid Data %s for %s. must be %s."
281
+ ERR_TYPE = "Invalid Data %s for %s. must be %s.".freeze
282
282
 
283
283
  # error message for RegexValidator
284
- ERR_REGEX = "Invalid Data. %s does not match %s."
284
+ ERR_REGEX = "Invalid Data. %s does not match %s.".freeze
285
285
 
286
286
  # error message for RangeValidator
287
- ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s"
287
+ ERR_RANGE = "Invalid Data. %s must be between %s and %s, (inclusive:%s) you gave: %s".freeze
288
288
 
289
289
  # error message for sheets that use a name which is longer than 31 bytes
290
- ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be 31 characters (bytes) or less"
290
+ ERR_SHEET_NAME_TOO_LONG = "Your worksheet name '%s' is too long. Worksheet names must be 31 characters (bytes) or less".freeze
291
291
 
292
292
  # error message for sheets that use a name which include invalid characters
293
- ERR_SHEET_NAME_CHARACTER_FORBIDDEN = "Your worksheet name '%s' contains a character which is not allowed by MS Excel and will cause repair warnings. Please change the name of your sheet."
293
+ ERR_SHEET_NAME_CHARACTER_FORBIDDEN = "Your worksheet name '%s' contains a character which is not allowed by MS Excel and will cause repair warnings. Please change the name of your sheet.".freeze
294
294
 
295
295
  # error message for duplicate sheet names
296
- ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name"
296
+ ERR_DUPLICATE_SHEET_NAME = "There is already a worksheet in this workbook named '%s'. Please use a unique name".freeze
297
297
 
298
298
  # error message when user does not provide color and or style options for border in Style#add_sytle
299
- ERR_INVALID_BORDER_OPTIONS = "border hash must include both style and color. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s"
299
+ ERR_INVALID_BORDER_OPTIONS = "border hash must include both style and color. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s".freeze
300
300
 
301
301
  # error message for invalid border id reference
302
- ERR_INVALID_BORDER_ID = "The border id you specified (%s) does not exist. Please add a border with Style#add_style before referencing its index."
302
+ ERR_INVALID_BORDER_ID = "The border id you specified (%s) does not exist. Please add a border with Style#add_style before referencing its index.".freeze
303
303
 
304
304
  # error message for invalid angles
305
- ERR_ANGLE = "Angles must be a value between -90 and 90. You provided: %s"
305
+ ERR_ANGLE = "Angles must be a value between -90 and 90. You provided: %s".freeze
306
306
 
307
307
  # error message for non 'integerish' value
308
- ERR_INTEGERISH = "You value must be, or be castable via to_i, an Integer. You provided %s"
308
+ ERR_INTEGERISH = "You value must be, or be castable via to_i, an Integer. You provided %s".freeze
309
309
 
310
310
  # Regex to match forbidden control characters
311
311
  # The following will be automatically stripped from worksheets.
@@ -383,10 +383,19 @@ module Axlsx
383
383
  # x0D Carriage Return (Cr)
384
384
  # x09 Character Tabulation
385
385
  # @see http://www.codetable.net/asciikeycodes
386
- pattern = "[\x0-\x08\x0B\x0C\x0E-\x1F]"
387
- pattern= pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern
386
+ pattern = "\x0-\x08\x0B\x0C\x0E-\x1F"
387
+ pattern = pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern
388
388
 
389
389
  # The regular expression used to remove control characters from worksheets
390
- CONTROL_CHAR_REGEX = Regexp.new(pattern, 'n')
390
+ CONTROL_CHARS = pattern.freeze
391
391
 
392
+ # ISO 8601 date recognition
393
+ ISO_8601_REGEX = /\A(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?\Z/.freeze
394
+
395
+ # FLOAT recognition
396
+ SAFE_FLOAT_REGEX = /\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]{1,2})?\Z/.freeze
397
+ MAYBE_FLOAT_REGEX = /\A[-+]?[0-9]*\.?[0-9]+[eE](?<exp>[-+]?[0-9]{3})\Z/.freeze
398
+
399
+ # Numeric recognition
400
+ NUMERIC_REGEX = /\A[+-]?\d+?\Z/.freeze
392
401
  end