caxlsx 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +24 -5
  4. data/Rakefile +0 -1
  5. data/lib/axlsx/content_type/abstract_content_type.rb +2 -5
  6. data/lib/axlsx/content_type/content_type.rb +0 -4
  7. data/lib/axlsx/content_type/default.rb +1 -5
  8. data/lib/axlsx/content_type/override.rb +0 -4
  9. data/lib/axlsx/doc_props/app.rb +1 -6
  10. data/lib/axlsx/doc_props/core.rb +1 -6
  11. data/lib/axlsx/drawing/area_chart.rb +3 -6
  12. data/lib/axlsx/drawing/area_series.rb +1 -4
  13. data/lib/axlsx/drawing/ax_data_source.rb +1 -6
  14. data/lib/axlsx/drawing/axes.rb +5 -6
  15. data/lib/axlsx/drawing/axis.rb +7 -12
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +7 -10
  17. data/lib/axlsx/drawing/bar_chart.rb +6 -9
  18. data/lib/axlsx/drawing/bar_series.rb +2 -8
  19. data/lib/axlsx/drawing/bubble_chart.rb +2 -5
  20. data/lib/axlsx/drawing/bubble_series.rb +3 -6
  21. data/lib/axlsx/drawing/cat_axis.rb +2 -7
  22. data/lib/axlsx/drawing/chart.rb +7 -12
  23. data/lib/axlsx/drawing/d_lbls.rb +23 -22
  24. data/lib/axlsx/drawing/drawing.rb +4 -8
  25. data/lib/axlsx/drawing/graphic_frame.rb +0 -3
  26. data/lib/axlsx/drawing/hyperlink.rb +4 -7
  27. data/lib/axlsx/drawing/line_3D_chart.rb +10 -14
  28. data/lib/axlsx/drawing/line_chart.rb +3 -6
  29. data/lib/axlsx/drawing/line_series.rb +1 -4
  30. data/lib/axlsx/drawing/marker.rb +5 -9
  31. data/lib/axlsx/drawing/num_data.rb +4 -9
  32. data/lib/axlsx/drawing/num_data_source.rb +3 -7
  33. data/lib/axlsx/drawing/num_val.rb +2 -5
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +4 -6
  35. data/lib/axlsx/drawing/pic.rb +46 -13
  36. data/lib/axlsx/drawing/picture_locking.rb +3 -6
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -7
  38. data/lib/axlsx/drawing/pie_series.rb +1 -6
  39. data/lib/axlsx/drawing/scaling.rb +2 -5
  40. data/lib/axlsx/drawing/scatter_chart.rb +2 -5
  41. data/lib/axlsx/drawing/scatter_series.rb +2 -5
  42. data/lib/axlsx/drawing/ser_axis.rb +2 -6
  43. data/lib/axlsx/drawing/series.rb +3 -5
  44. data/lib/axlsx/drawing/series_title.rb +0 -2
  45. data/lib/axlsx/drawing/str_data.rb +3 -8
  46. data/lib/axlsx/drawing/str_val.rb +2 -5
  47. data/lib/axlsx/drawing/title.rb +12 -15
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +5 -7
  49. data/lib/axlsx/drawing/val_axis.rb +1 -4
  50. data/lib/axlsx/drawing/view_3D.rb +24 -24
  51. data/lib/axlsx/drawing/vml_drawing.rb +2 -5
  52. data/lib/axlsx/drawing/vml_shape.rb +4 -7
  53. data/lib/axlsx/package.rb +35 -36
  54. data/lib/axlsx/rels/relationship.rb +21 -24
  55. data/lib/axlsx/rels/relationships.rb +3 -6
  56. data/lib/axlsx/stylesheet/border.rb +1 -4
  57. data/lib/axlsx/stylesheet/border_pr.rb +3 -5
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +2 -10
  59. data/lib/axlsx/stylesheet/cell_protection.rb +1 -4
  60. data/lib/axlsx/stylesheet/cell_style.rb +3 -7
  61. data/lib/axlsx/stylesheet/color.rb +6 -5
  62. data/lib/axlsx/stylesheet/dxf.rb +2 -6
  63. data/lib/axlsx/stylesheet/fill.rb +0 -4
  64. data/lib/axlsx/stylesheet/font.rb +7 -6
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +4 -6
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +2 -3
  67. data/lib/axlsx/stylesheet/num_fmt.rb +1 -4
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +3 -5
  69. data/lib/axlsx/stylesheet/styles.rb +53 -45
  70. data/lib/axlsx/stylesheet/table_style.rb +5 -8
  71. data/lib/axlsx/stylesheet/table_style_element.rb +1 -4
  72. data/lib/axlsx/stylesheet/table_styles.rb +3 -7
  73. data/lib/axlsx/stylesheet/xf.rb +3 -6
  74. data/lib/axlsx/util/accessors.rb +2 -4
  75. data/lib/axlsx/util/constants.rb +3 -5
  76. data/lib/axlsx/util/mime_type_utils.rb +13 -0
  77. data/lib/axlsx/util/options_parser.rb +1 -2
  78. data/lib/axlsx/util/serialized_attributes.rb +4 -5
  79. data/lib/axlsx/util/simple_typed_list.rb +18 -17
  80. data/lib/axlsx/util/storage.rb +32 -36
  81. data/lib/axlsx/util/validators.rb +7 -4
  82. data/lib/axlsx/util/zip_command.rb +0 -2
  83. data/lib/axlsx/version.rb +1 -2
  84. data/lib/axlsx/workbook/defined_name.rb +6 -5
  85. data/lib/axlsx/workbook/defined_names.rb +1 -2
  86. data/lib/axlsx/workbook/shared_strings_table.rb +3 -6
  87. data/lib/axlsx/workbook/workbook.rb +96 -91
  88. data/lib/axlsx/workbook/workbook_view.rb +5 -10
  89. data/lib/axlsx/workbook/workbook_views.rb +1 -3
  90. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +9 -8
  91. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +6 -6
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +13 -14
  93. data/lib/axlsx/workbook/worksheet/border_creator.rb +29 -26
  94. data/lib/axlsx/workbook/worksheet/break.rb +2 -5
  95. data/lib/axlsx/workbook/worksheet/cell.rb +46 -26
  96. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +11 -11
  97. data/lib/axlsx/workbook/worksheet/cfvo.rb +2 -2
  98. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -5
  99. data/lib/axlsx/workbook/worksheet/col.rb +4 -7
  100. data/lib/axlsx/workbook/worksheet/col_breaks.rb +4 -5
  101. data/lib/axlsx/workbook/worksheet/color_scale.rb +10 -12
  102. data/lib/axlsx/workbook/worksheet/cols.rb +6 -6
  103. data/lib/axlsx/workbook/worksheet/comment.rb +4 -5
  104. data/lib/axlsx/workbook/worksheet/comments.rb +6 -10
  105. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +4 -5
  106. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +2 -6
  107. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +2 -4
  108. data/lib/axlsx/workbook/worksheet/data_bar.rb +20 -22
  109. data/lib/axlsx/workbook/worksheet/data_validation.rb +4 -5
  110. data/lib/axlsx/workbook/worksheet/data_validations.rb +2 -5
  111. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -3
  112. data/lib/axlsx/workbook/worksheet/dimension.rb +5 -4
  113. data/lib/axlsx/workbook/worksheet/header_footer.rb +0 -1
  114. data/lib/axlsx/workbook/worksheet/icon_set.rb +2 -3
  115. data/lib/axlsx/workbook/worksheet/merged_cells.rb +8 -8
  116. data/lib/axlsx/workbook/worksheet/outline_pr.rb +0 -1
  117. data/lib/axlsx/workbook/worksheet/page_margins.rb +2 -2
  118. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -3
  119. data/lib/axlsx/workbook/worksheet/page_setup.rb +117 -120
  120. data/lib/axlsx/workbook/worksheet/pane.rb +16 -17
  121. data/lib/axlsx/workbook/worksheet/pivot_table.rb +8 -11
  122. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -11
  123. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -4
  124. data/lib/axlsx/workbook/worksheet/print_options.rb +0 -1
  125. data/lib/axlsx/workbook/worksheet/protected_range.rb +4 -5
  126. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +9 -9
  127. data/lib/axlsx/workbook/worksheet/rich_text.rb +4 -6
  128. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +21 -5
  129. data/lib/axlsx/workbook/worksheet/row.rb +24 -15
  130. data/lib/axlsx/workbook/worksheet/row_breaks.rb +3 -4
  131. data/lib/axlsx/workbook/worksheet/selection.rb +7 -9
  132. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +5 -6
  133. data/lib/axlsx/workbook/worksheet/sheet_data.rb +4 -6
  134. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +18 -18
  135. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +4 -4
  136. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +12 -13
  137. data/lib/axlsx/workbook/worksheet/sheet_view.rb +35 -42
  138. data/lib/axlsx/workbook/worksheet/table.rb +7 -9
  139. data/lib/axlsx/workbook/worksheet/table_style_info.rb +2 -3
  140. data/lib/axlsx/workbook/worksheet/tables.rb +4 -4
  141. data/lib/axlsx/workbook/worksheet/worksheet.rb +63 -35
  142. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -6
  143. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +3 -2
  144. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +5 -6
  145. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +4 -4
  146. data/lib/axlsx.rb +23 -9
  147. data/lib/caxlsx.rb +0 -1
  148. metadata +3 -3
@@ -14,7 +14,6 @@ module Axlsx
14
14
 
15
15
  # Defines the class level xxx_attr_accessor methods
16
16
  module ClassMethods
17
-
18
17
  # Creates one or more string validated attr_accessors
19
18
  # @param [Array] symbols An array of symbols representing the
20
19
  # names of the attributes you will add to your class.
@@ -22,7 +21,6 @@ module Axlsx
22
21
  validated_attr_accessor(symbols, :validate_string)
23
22
  end
24
23
 
25
-
26
24
  # Creates one or more usigned integer attr_accessors
27
25
  # @param [Array] symbols An array of symbols representing the
28
26
  # names of the attributes you will add to your class
@@ -51,14 +49,14 @@ module Axlsx
51
49
  # @param [Array] symbols The names of the attributes to create
52
50
  # @param [String] validator The axlsx validation method to use when
53
51
  # validating assignation.
54
- # @see lib/axlsx/util/validators.rb
52
+ # @see lib/axlsx/util/validators.rb
55
53
  def validated_attr_accessor(symbols, validator)
56
54
  symbols.each do |symbol|
57
55
  attr_reader symbol
56
+
58
57
  module_eval(SETTER % [symbol, validator, symbol], __FILE__, __LINE__)
59
58
  end
60
59
  end
61
60
  end
62
61
  end
63
62
  end
64
-
@@ -1,5 +1,4 @@
1
1
  module Axlsx
2
-
3
2
  # XML Encoding
4
3
  ENCODING = "UTF-8".freeze
5
4
 
@@ -96,7 +95,7 @@ module Axlsx
96
95
  # comment relation for nil target
97
96
  COMMENT_R_NULL = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments".freeze
98
97
 
99
- #vml drawing relation namespace
98
+ # vml drawing relation namespace
100
99
  VML_DRAWING_R = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing'
101
100
 
102
101
  # VML Drawing content type
@@ -159,10 +158,9 @@ module Axlsx
159
158
  # png content type
160
159
  PNG_CT = "image/png".freeze
161
160
 
162
- #drawing content type
161
+ # drawing content type
163
162
  DRAWING_CT = "application/vnd.openxmlformats-officedocument.drawing+xml".freeze
164
163
 
165
-
166
164
  # xml content type extensions
167
165
  XML_EX = "xml".freeze
168
166
 
@@ -239,7 +237,7 @@ module Axlsx
239
237
  COMMENT_PN = "comments%d.xml".freeze
240
238
 
241
239
  # location of schema files for validation
242
- SCHEMA_BASE = (File.dirname(__FILE__)+'/../../schema/').freeze
240
+ SCHEMA_BASE = (File.dirname(__FILE__) + '/../../schema/').freeze
243
241
 
244
242
  # App validation schema
245
243
  APP_XSD = (SCHEMA_BASE + "shared-documentPropertiesExtended.xsd").freeze
@@ -1,3 +1,5 @@
1
+ require 'open-uri'
2
+
1
3
  module Axlsx
2
4
  # This module defines some utils related with mime type detection
3
5
  module MimeTypeUtils
@@ -7,5 +9,16 @@ module Axlsx
7
9
  def self.get_mime_type(v)
8
10
  Marcel::MimeType.for(Pathname.new(v))
9
11
  end
12
+
13
+ # Detect a file mime type from URI
14
+ # @param [String] v URI
15
+ # @return [String] File mime type
16
+ def self.get_mime_type_from_uri(v)
17
+ if URI.respond_to?(:open)
18
+ Marcel::MimeType.for(URI.open(v))
19
+ else
20
+ Marcel::MimeType.for(URI.parse(v).open)
21
+ end
22
+ end
10
23
  end
11
24
  end
@@ -2,11 +2,10 @@ module Axlsx
2
2
  # This module defines a single method for parsing options in class
3
3
  # initializers.
4
4
  module OptionsParser
5
-
6
5
  # Parses an options hash by calling any defined method by the same
7
6
  # name of the key postfixed with an '='
8
7
  # @param [Hash] options Options to parse.
9
- def parse_options(options={})
8
+ def parse_options(options = {})
10
9
  options.each do |key, value|
11
10
  key = :"#{key}="
12
11
  self.send(key, value) if !value.nil? && self.respond_to?(key)
@@ -2,7 +2,6 @@ module Axlsx
2
2
  # This module allows us to define a list of symbols defining which
3
3
  # attributes will be serialized for a class.
4
4
  module SerializedAttributes
5
-
6
5
  # Extend with class methods
7
6
  def self.included(base)
8
7
  base.send :extend, ClassMethods
@@ -10,8 +9,7 @@ module Axlsx
10
9
 
11
10
  # class methods applied to all includers
12
11
  module ClassMethods
13
-
14
- # This is the method to be used in inheriting classes to specify
12
+ # This is the method to be used in inheriting classes to specify
15
13
  # which of the instance values are serializable
16
14
  def serializable_attributes(*symbols)
17
15
  @xml_attributes = symbols
@@ -43,7 +41,7 @@ module Axlsx
43
41
  end
44
42
  end
45
43
 
46
- # serializes the instance values of the defining object based on the
44
+ # serializes the instance values of the defining object based on the
47
45
  # list of serializable attributes.
48
46
  # @param [String] str The string instance to append this
49
47
  # serialization to.
@@ -73,12 +71,13 @@ module Axlsx
73
71
  # @param [String] str The string instance to which serialized data is appended
74
72
  # @param [Array] additional_attributes An array of additional attribute names.
75
73
  # @return [String] The serialized output.
76
- def serialized_element_attributes(str='', additional_attributes=[], &block)
74
+ def serialized_element_attributes(str = '', additional_attributes = [], &block)
77
75
  attrs = self.class.xml_element_attributes + additional_attributes
78
76
  values = Axlsx.instance_values_for(self)
79
77
  attrs.each do |attribute_name|
80
78
  value = values[attribute_name.to_s]
81
79
  next if value.nil?
80
+
82
81
  value = yield value if block_given?
83
82
  element_name = Axlsx.camel(attribute_name, false)
84
83
  str << "<#{element_name}>#{value}</#{element_name}>"
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
-
4
2
  # A SimpleTypedList is a type restrictive collection that allows some of the methods from Array and supports basic xml serialization.
5
3
  # @private
6
4
  class SimpleTypedList
@@ -8,12 +6,13 @@ module Axlsx
8
6
  # @param [Array, Class] type An array of Class objects or a single Class object
9
7
  # @param [String] serialize_as The tag name to use in serialization
10
8
  # @raise [ArgumentError] if all members of type are not Class objects
11
- def initialize type, serialize_as=nil, start_size = 0
9
+ def initialize type, serialize_as = nil, start_size = 0
12
10
  if type.is_a? Array
13
11
  type.each { |item| raise ArgumentError, "All members of type must be Class objects" unless item.is_a? Class }
14
12
  @allowed_types = type
15
13
  else
16
14
  raise ArgumentError, "Type must be a Class object or array of Class objects" unless type.is_a? Class
15
+
17
16
  @allowed_types = [type]
18
17
  end
19
18
  @serialize_as = serialize_as unless serialize_as.nil?
@@ -39,12 +38,13 @@ module Axlsx
39
38
  # any non populated cell in the matrix will be a nil value
40
39
  def transpose
41
40
  return @list.clone if @list.size == 0
41
+
42
42
  row_count = @list.size
43
- max_column_count = @list.map{|row| row.cells.size}.max
43
+ max_column_count = @list.map { |row| row.cells.size }.max
44
44
  result = Array.new(max_column_count) { Array.new(row_count) }
45
45
  # yes, I know it is silly, but that warning is really annoying
46
46
  row_count.times do |row_index|
47
- max_column_count.times do |column_index|
47
+ max_column_count.times do |column_index|
48
48
  datum = if @list[row_index].cells.size >= max_column_count
49
49
  @list[row_index].cells[column_index]
50
50
  elsif block_given?
@@ -55,7 +55,7 @@ module Axlsx
55
55
  end
56
56
  result
57
57
  end
58
-
58
+
59
59
  # Lock this list at the current size
60
60
  # @return [self]
61
61
  def lock
@@ -69,7 +69,7 @@ module Axlsx
69
69
  @locked_at = nil
70
70
  self
71
71
  end
72
-
72
+
73
73
  def to_ary
74
74
  @list
75
75
  end
@@ -82,9 +82,9 @@ module Axlsx
82
82
  # one of the allowed types
83
83
  # @return [SimpleTypedList]
84
84
  def +(v)
85
- v.each do |item|
85
+ v.each do |item|
86
86
  DataTypeValidator.validate :SimpleTypedList_plus, @allowed_types, item
87
- @list << item
87
+ @list << item
88
88
  end
89
89
  end
90
90
 
@@ -96,10 +96,9 @@ module Axlsx
96
96
  DataTypeValidator.validate :SimpleTypedList_push, @allowed_types, v
97
97
  @list << v
98
98
  @list.size - 1
99
- end
100
-
99
+ end
100
+
101
101
  alias :push :<<
102
-
103
102
 
104
103
  # delete the item from the list
105
104
  # @param [Any] v The item to be deleted.
@@ -108,6 +107,7 @@ module Axlsx
108
107
  def delete(v)
109
108
  return unless include? v
110
109
  raise ArgumentError, "Item is protected and cannot be deleted" if protected? index(v)
110
+
111
111
  @list.delete v
112
112
  end
113
113
 
@@ -117,6 +117,7 @@ module Axlsx
117
117
  def delete_at(index)
118
118
  @list[index]
119
119
  raise ArgumentError, "Item is protected and cannot be deleted" if protected? index
120
+
120
121
  @list.delete_at index
121
122
  end
122
123
 
@@ -128,6 +129,7 @@ module Axlsx
128
129
  def []=(index, v)
129
130
  DataTypeValidator.validate :SimpleTypedList_insert, @allowed_types, v
130
131
  raise ArgumentError, "Item is protected and cannot be changed" if protected? index
132
+
131
133
  @list[index] = v
132
134
  v
133
135
  end
@@ -140,6 +142,7 @@ module Axlsx
140
142
  def insert(index, v)
141
143
  DataTypeValidator.validate :SimpleTypedList_insert, @allowed_types, v
142
144
  raise ArgumentError, "Item is protected and cannot be changed" if protected? index
145
+
143
146
  @list.insert(index, v)
144
147
  v
145
148
  end
@@ -148,6 +151,7 @@ module Axlsx
148
151
  # @param [Integer] index
149
152
  def protected? index
150
153
  return false unless locked_at.is_a? Integer
154
+
151
155
  index < locked_at
152
156
  end
153
157
 
@@ -164,16 +168,13 @@ module Axlsx
164
168
  end
165
169
  }
166
170
  end
167
-
171
+
168
172
  def to_xml_string(str = '')
169
173
  classname = @allowed_types[0].name.split('::').last
170
- el_name = serialize_as.to_s || (classname[0,1].downcase + classname[1..-1])
174
+ el_name = serialize_as.to_s || (classname[0, 1].downcase + classname[1..-1])
171
175
  str << ('<' << el_name << ' count="' << size.to_s << '">')
172
176
  each { |item| item.to_xml_string(str) }
173
177
  str << ('</' << el_name << '>')
174
178
  end
175
-
176
179
  end
177
-
178
-
179
180
  end
@@ -1,61 +1,58 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
-
4
2
  # The Storage class represents a storage object or stream in a compound file.
5
3
  class Storage
6
-
7
4
  # Packing for the Storage when pushing an array of items into a byte stream
8
5
  # Name, name length, type, color, left sibling, right sibling, child, classid, state, created, modified, sector, size
9
6
  PACKING = "s32 s1 c2 l3 x16 x4 q2 l q".freeze
10
7
 
11
8
  # storage types
12
9
  TYPES = {
13
- :root=>5,
14
- :stream=>2,
15
- :storage=>1
10
+ :root => 5,
11
+ :stream => 2,
12
+ :storage => 1
16
13
  }.freeze
17
14
 
18
15
  # Creates a byte string for this storage
19
- # @return [String]
16
+ # @return [String]
20
17
  def to_s
21
- data = [@name.concat(Array.new(32-@name.size, 0)),
22
- @name_size,
23
- @type,
24
- @color,
25
- @left,
26
- @right,
27
- @child,
28
- @created,
29
- @modified,
30
- @sector,
31
- @size].flatten
18
+ data = [@name.concat(Array.new(32 - @name.size, 0)),
19
+ @name_size,
20
+ @type,
21
+ @color,
22
+ @left,
23
+ @right,
24
+ @child,
25
+ @created,
26
+ @modified,
27
+ @sector,
28
+ @size].flatten
32
29
  data.pack(PACKING)
33
30
  end
34
31
 
35
32
  # storage colors
36
33
  COLORS = {
37
- :red=>0,
38
- :black=>1
34
+ :red => 0,
35
+ :black => 1
39
36
  }
40
37
 
41
38
  # The color of this node in the directory tree. Defaults to black if not specified
42
39
  # @return [Integer] color
43
40
  attr_reader :color
44
-
41
+
45
42
  # Sets the color for this storage
46
43
  # @param [Integer] v Must be one of the COLORS constant hash values
47
44
  def color=(v)
48
- RestrictionValidator.validate :storage_color, COLORS.values, v
45
+ RestrictionValidator.validate :storage_color, COLORS.values, v
49
46
  @color = v
50
47
  end
51
48
 
52
49
  # The size of the name for this node.
53
- # interesting to see that office actually uses 'R' for the root directory and lists the size as 2 bytes - thus is it *NOT* null
50
+ # interesting to see that office actually uses 'R' for the root directory and lists the size as 2 bytes - thus is it *NOT* null
54
51
  # terminated. I am making this r/w so that I can override the size
55
52
  # @return [Integer] color
56
53
  attr_reader :name_size
57
54
 
58
- # the name of the stream
55
+ # the name of the stream
59
56
  attr_reader :name
60
57
 
61
58
  # sets the name of the stream.
@@ -87,16 +84,16 @@ module Axlsx
87
84
  # @return [Integer] sector
88
85
  attr_accessor :sector
89
86
 
90
- # The 0 based index in the directoies chain for this the left sibling of this storage.
91
-
87
+ # The 0 based index in the directoies chain for this the left sibling of this storage.
88
+
92
89
  # @return [Integer] left
93
- attr_accessor :left
90
+ attr_accessor :left
94
91
 
95
- # The 0 based index in the directoies chain for this the right sibling of this storage.
92
+ # The 0 based index in the directoies chain for this the right sibling of this storage.
96
93
  # @return [Integer] right
97
- attr_accessor :right
94
+ attr_accessor :right
98
95
 
99
- # The 0 based index in the directoies chain for the child of this storage.
96
+ # The 0 based index in the directoies chain for the child of this storage.
100
97
  # @return [Integer] child
101
98
  attr_accessor :child
102
99
 
@@ -113,14 +110,14 @@ module Axlsx
113
110
  # @return [Integer] type
114
111
  attr_reader :type
115
112
 
116
- # Sets the type for this storage.
117
- # @param [Integer] v the type to specify must be one of the TYPES constant hash values.
113
+ # Sets the type for this storage.
114
+ # @param [Integer] v the type to specify must be one of the TYPES constant hash values.
118
115
  def type=(v)
119
- RestrictionValidator.validate :storage_type, TYPES.values, v
116
+ RestrictionValidator.validate :storage_type, TYPES.values, v
120
117
  @type = v
121
118
  end
122
119
 
123
- # Creates a new storage object.
120
+ # Creates a new storage object.
124
121
  # @param [String] name the name of the storage
125
122
  # @option options [Integer] color (black)
126
123
  # @option options [Integer] type (storage)
@@ -131,7 +128,7 @@ module Axlsx
131
128
  # @option options [Integer] created (0)
132
129
  # @option options [Integer] modified (0)
133
130
  # @option options [Integer] sector (0)
134
- def initialize(name, options= {})
131
+ def initialize(name, options = {})
135
132
  @left = @right = @child = -1
136
133
  @sector = @size = @created = @modified = 0
137
134
  options.each do |o|
@@ -141,6 +138,5 @@ module Axlsx
141
138
  @type ||= (data.nil? ? TYPES[:storage] : TYPES[:stream])
142
139
  self.name = name
143
140
  end
144
-
145
141
  end
146
142
  end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # Validate a value against a specific list of allowed values.
4
3
  class RestrictionValidator
@@ -10,6 +9,7 @@ module Axlsx
10
9
  # @return [Boolean] true if validation succeeds.
11
10
  def self.validate(name, choices, v)
12
11
  raise ArgumentError, (ERR_RESTRICTION % [v.to_s, name, choices.inspect]) unless choices.include?(v)
12
+
13
13
  true
14
14
  end
15
15
  end
@@ -32,6 +32,7 @@ module Axlsx
32
32
  raise ArgumentError, (ERR_RANGE % [value.inspect, min.to_s, max.to_s, inclusive]) unless passes
33
33
  end
34
34
  end
35
+
35
36
  # Validates the value against the regular expression provided.
36
37
  class RegexValidator
37
38
  # @param [String] name The name of what is being validated. This is included in the output when the value is invalid
@@ -51,9 +52,9 @@ module Axlsx
51
52
  # @raise [ArugumentError] Raised if the class of the value provided is not in the specified array of types or the block passed returns false
52
53
  # @return [Boolean] true if validation succeeds.
53
54
  # @see validate_boolean
54
- def self.validate(name, types, v, other=false)
55
+ def self.validate(name, types, v, other = false)
55
56
  if other.is_a?(Proc)
56
- raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v)
57
+ raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v)
57
58
  end
58
59
  v_class = v.is_a?(Class) ? v : v.class
59
60
  Array(types).each do |t|
@@ -63,7 +64,6 @@ module Axlsx
63
64
  end
64
65
  end
65
66
 
66
-
67
67
  # Requires that the value can be converted to an integer
68
68
  # @para, [Any] v the value to validate
69
69
  # @raise [ArgumentError] raised if the value cannot be converted to an integer
@@ -144,6 +144,7 @@ module Axlsx
144
144
  def self.validate_page_orientation(v)
145
145
  RestrictionValidator.validate "page_orientation", [:default, :landscape, :portrait], v
146
146
  end
147
+
147
148
  # Requires that the value is one of :none, :single, :double, :singleAccounting, :doubleAccounting
148
149
  def self.validate_cell_u(v)
149
150
  RestrictionValidator.validate "cell run style u", [:none, :single, :double, :singleAccounting, :doubleAccounting], v
@@ -153,6 +154,7 @@ module Axlsx
153
154
  def self.validate_family(v)
154
155
  RestrictionValidator.validate "cell run style family", 1..5, v
155
156
  end
157
+
156
158
  # Requires that the value is valid pattern type.
157
159
  # valid pattern types must be one of :none, :solid, :mediumGray, :darkGray, :lightGray, :darkHorizontal, :darkVertical, :darkDown,
158
160
  # :darkUp, :darkGrid, :darkTrellis, :lightHorizontal, :lightVertical, :lightDown, :lightUp, :lightGrid, :lightTrellis, :gray125, or :gray0625.
@@ -215,6 +217,7 @@ module Axlsx
215
217
  def self.validate_scatter_style(v)
216
218
  Axlsx::RestrictionValidator.validate "ScatterChart.scatterStyle", [:none, :line, :lineMarker, :marker, :smooth, :smoothMarker], v.to_sym
217
219
  end
220
+
218
221
  # Requires that the value is a valid horizontal_alignment
219
222
  # :general, :left, :center, :right, :fill, :justify, :centerContinuous, :distributed are allowed
220
223
  # @param [Any] v The value validated
@@ -1,9 +1,7 @@
1
- # encoding: UTF-8
2
1
  require 'open3'
3
2
  require 'shellwords'
4
3
 
5
4
  module Axlsx
6
-
7
5
  # The ZipCommand class supports zipping the Excel file contents using
8
6
  # a binary zip program instead of RubyZip's `Zip::OutputStream`.
9
7
  #
data/lib/axlsx/version.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Axlsx
2
-
3
2
  # The current version
4
- VERSION = "3.3.0"
3
+ VERSION = "3.4.0"
5
4
  end
@@ -2,9 +2,9 @@
2
2
  # <definedName name="_xlnm.Print_Titles" localSheetId="0">Sheet1!$1:$1</definedName>
3
3
  # </definedNames>
4
4
 
5
- #<xsd:complexType name="CT_DefinedName">
5
+ # <xsd:complexType name="CT_DefinedName">
6
6
  # <xsd:simpleContent>
7
- # <xsd:extension base="ST_Formula">
7
+ #  <xsd:extension base="ST_Formula">
8
8
  # <xsd:attribute name="name" type="s:ST_Xstring" use="required"/>
9
9
  # <xsd:attribute name="comment" type="s:ST_Xstring" use="optional"/>
10
10
  # <xsd:attribute name="customMenu" type="s:ST_Xstring" use="optional"/>
@@ -97,7 +97,7 @@ module Axlsx
97
97
  # version of the workbook that is published to or rendered on a Web or application server.
98
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
- def initialize(formula, options={})
100
+ def initialize(formula, options = {})
101
101
  @formula = formula
102
102
  parse_options options
103
103
  end
@@ -116,10 +116,11 @@ 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, :local_sheet_id
119
+ :workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden, :local_sheet_id
120
120
 
121
- def to_xml_string(str='')
121
+ def to_xml_string(str = '')
122
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
+
123
124
  str << ('<definedName ' << 'name="' << name << '" ')
124
125
  serialized_attributes str
125
126
  str << ('>' << @formula << '</definedName>')
@@ -1,7 +1,6 @@
1
1
  module Axlsx
2
2
  # a simple types list of DefinedName objects
3
3
  class DefinedNames < SimpleTypedList
4
-
5
4
  # creates the DefinedNames object
6
5
  def initialize
7
6
  super DefinedName
@@ -12,10 +11,10 @@ module Axlsx
12
11
  # @return [String]
13
12
  def to_xml_string(str = '')
14
13
  return if empty?
14
+
15
15
  str << '<definedNames>'
16
16
  each { |defined_name| defined_name.to_xml_string(str) }
17
17
  str << '</definedNames>'
18
18
  end
19
19
  end
20
20
  end
21
-
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
-
4
2
  # The Shared String Table class is responsible for managing and serializing common strings in a workbook.
5
3
  # While the ECMA-376 spec allows for both inline and shared strings it seems that at least some applications like iWorks Numbers
6
4
  # and Google Docs require that the shared string table is populated in order to interoperate properly.
@@ -9,7 +7,6 @@ module Axlsx
9
7
  # @note Serialization performance is affected by using this serialization method so if you do not need interoperability
10
8
  # it is recomended that you use the default inline string method of serialization.
11
9
  class SharedStringsTable
12
-
13
10
  # The total number of strings in the workbook including duplicates
14
11
  # Empty cells are treated as blank strings
15
12
  # @return [Integer]
@@ -33,12 +30,12 @@ module Axlsx
33
30
  # Creates a new Shared Strings Table agains an array of cells
34
31
  # @param [Array] cells This is an array of all of the cells in the workbook
35
32
  # @param [Symbol] xml_space The xml:space behavior for the shared string table.
36
- def initialize(cells, xml_space=:preserve)
33
+ def initialize(cells, xml_space = :preserve)
37
34
  @index = 0
38
35
  @xml_space = xml_space
39
36
  @unique_cells = {}
40
37
  @shared_xml_string = ""
41
- shareable_cells = cells.flatten.select{ |cell| cell.plain_string? || cell.contains_rich_text? }
38
+ shareable_cells = cells.flatten.select { |cell| cell.plain_string? || cell.contains_rich_text? }
42
39
  @count = shareable_cells.size
43
40
  resolve(shareable_cells)
44
41
  end
@@ -46,7 +43,7 @@ module Axlsx
46
43
  # Serializes the object
47
44
  # @param [String] str
48
45
  # @return [String]
49
- def to_xml_string(str='')
46
+ def to_xml_string(str = '')
50
47
  Axlsx::sanitize(@shared_xml_string)
51
48
  str << ('<?xml version="1.0" encoding="UTF-8"?><sst xmlns="' << XML_NS << '"')
52
49
  str << (' count="' << @count.to_s << '" uniqueCount="' << unique_count.to_s << '"')