caxlsx 4.1.0 → 4.3.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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -12
  3. data/README.md +7 -1
  4. data/Rakefile +2 -9
  5. data/lib/axlsx/content_type/abstract_content_type.rb +2 -2
  6. data/lib/axlsx/content_type/content_type.rb +3 -3
  7. data/lib/axlsx/drawing/area_chart.rb +3 -3
  8. data/lib/axlsx/drawing/area_series.rb +2 -2
  9. data/lib/axlsx/drawing/ax_data_source.rb +1 -1
  10. data/lib/axlsx/drawing/axes.rb +1 -1
  11. data/lib/axlsx/drawing/axis.rb +1 -1
  12. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -4
  13. data/lib/axlsx/drawing/bar_chart.rb +14 -4
  14. data/lib/axlsx/drawing/bar_series.rb +2 -2
  15. data/lib/axlsx/drawing/bubble_chart.rb +2 -2
  16. data/lib/axlsx/drawing/bubble_series.rb +2 -2
  17. data/lib/axlsx/drawing/cat_axis.rb +3 -3
  18. data/lib/axlsx/drawing/chart.rb +1 -0
  19. data/lib/axlsx/drawing/d_lbls.rb +5 -4
  20. data/lib/axlsx/drawing/drawing.rb +50 -50
  21. data/lib/axlsx/drawing/hyperlink.rb +1 -1
  22. data/lib/axlsx/drawing/line_3D_chart.rb +3 -3
  23. data/lib/axlsx/drawing/line_chart.rb +3 -3
  24. data/lib/axlsx/drawing/line_series.rb +2 -2
  25. data/lib/axlsx/drawing/num_val.rb +1 -1
  26. data/lib/axlsx/drawing/pic.rb +4 -4
  27. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -2
  28. data/lib/axlsx/drawing/pie_chart.rb +2 -2
  29. data/lib/axlsx/drawing/pie_series.rb +2 -2
  30. data/lib/axlsx/drawing/scatter_chart.rb +2 -2
  31. data/lib/axlsx/drawing/scatter_series.rb +2 -2
  32. data/lib/axlsx/drawing/ser_axis.rb +3 -3
  33. data/lib/axlsx/drawing/two_cell_anchor.rb +1 -1
  34. data/lib/axlsx/drawing/val_axis.rb +2 -2
  35. data/lib/axlsx/drawing/vml_shape.rb +1 -1
  36. data/lib/axlsx/package.rb +10 -12
  37. data/lib/axlsx/rels/relationship.rb +2 -2
  38. data/lib/axlsx/rels/relationships.rb +2 -2
  39. data/lib/axlsx/stylesheet/border_pr.rb +2 -1
  40. data/lib/axlsx/stylesheet/cell_alignment.rb +1 -1
  41. data/lib/axlsx/stylesheet/cell_style.rb +1 -1
  42. data/lib/axlsx/stylesheet/color.rb +2 -2
  43. data/lib/axlsx/stylesheet/font.rb +1 -1
  44. data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
  45. data/lib/axlsx/stylesheet/pattern_fill.rb +1 -0
  46. data/lib/axlsx/stylesheet/styles.rb +27 -31
  47. data/lib/axlsx/stylesheet/xf.rb +2 -1
  48. data/lib/axlsx/util/accessors.rb +1 -1
  49. data/lib/axlsx/util/buffered_zip_output_stream.rb +2 -2
  50. data/lib/axlsx/util/constants.rb +2 -2
  51. data/lib/axlsx/util/serialized_attributes.rb +2 -2
  52. data/lib/axlsx/util/simple_typed_list.rb +26 -14
  53. data/lib/axlsx/util/storage.rb +3 -3
  54. data/lib/axlsx/util/validators.rb +2 -2
  55. data/lib/axlsx/version.rb +1 -1
  56. data/lib/axlsx/workbook/defined_name.rb +2 -1
  57. data/lib/axlsx/workbook/shared_strings_table.rb +3 -3
  58. data/lib/axlsx/workbook/workbook.rb +61 -61
  59. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +4 -4
  60. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +1 -1
  61. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +4 -4
  62. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +1 -1
  63. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +2 -2
  64. data/lib/axlsx/workbook/worksheet/border_creator.rb +4 -4
  65. data/lib/axlsx/workbook/worksheet/cell.rb +10 -10
  66. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
  67. data/lib/axlsx/workbook/worksheet/col.rb +23 -9
  68. data/lib/axlsx/workbook/worksheet/comment.rb +2 -2
  69. data/lib/axlsx/workbook/worksheet/comments.rb +1 -1
  70. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
  71. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
  72. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +2 -2
  73. data/lib/axlsx/workbook/worksheet/data_validation.rb +1 -1
  74. data/lib/axlsx/workbook/worksheet/data_validations.rb +2 -2
  75. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +2 -2
  76. data/lib/axlsx/workbook/worksheet/dimension.rb +1 -1
  77. data/lib/axlsx/workbook/worksheet/header_footer.rb +1 -1
  78. data/lib/axlsx/workbook/worksheet/icon_set.rb +1 -1
  79. data/lib/axlsx/workbook/worksheet/outline_pr.rb +1 -1
  80. data/lib/axlsx/workbook/worksheet/page_setup.rb +2 -2
  81. data/lib/axlsx/workbook/worksheet/pane.rb +1 -0
  82. data/lib/axlsx/workbook/worksheet/pivot_table.rb +30 -6
  83. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -0
  84. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +1 -1
  85. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +1 -0
  86. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +1 -1
  87. data/lib/axlsx/workbook/worksheet/table_style_info.rb +2 -1
  88. data/lib/axlsx/workbook/worksheet/worksheet.rb +10 -12
  89. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -4
  90. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
  91. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +2 -1
  92. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +1 -1
  93. data/lib/axlsx.rb +44 -30
  94. data/lib/caxlsx.rb +1 -1
  95. metadata +7 -10
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
4
- # The LineChart is a two dimentional line chart (who would have guessed?) that you can add to your worksheet.
4
+ # The LineChart is a two dimensional line chart (who would have guessed?) that you can add to your worksheet.
5
5
  # @example Creating a chart
6
6
  # # This example creates a line in a single sheet.
7
7
  # require "rubygems" # if that is your preferred way to manage gems!
@@ -47,7 +47,7 @@ module Axlsx
47
47
  def initialize(frame, options = {})
48
48
  @vary_colors = false
49
49
  @grouping = :standard
50
- super(frame, options)
50
+ super
51
51
  @series_type = LineSeries
52
52
  @d_lbls = nil
53
53
  end
@@ -75,7 +75,7 @@ module Axlsx
75
75
  # @param [String] str
76
76
  # @return [String]
77
77
  def to_xml_string(str = +'')
78
- super(str) do
78
+ super do
79
79
  str << "<c:" << node_name << ">"
80
80
  str << '<c:grouping val="' << grouping.to_s << '"/>'
81
81
  str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
@@ -40,7 +40,7 @@ module Axlsx
40
40
  @marker_symbol = options[:marker_symbol] || :default
41
41
  @smooth = false
42
42
  @labels, @data = nil, nil
43
- super(chart, options)
43
+ super
44
44
  @labels = AxDataSource.new(data: options[:labels]) unless options[:labels].nil?
45
45
  @data = NumDataSource.new(options) unless options[:data].nil?
46
46
  end
@@ -72,7 +72,7 @@ module Axlsx
72
72
  # @param [String] str
73
73
  # @return [String]
74
74
  def to_xml_string(str = +'')
75
- super(str) do
75
+ super do
76
76
  if color
77
77
  str << '<c:spPr><a:solidFill>'
78
78
  str << '<a:srgbClr val="' << color << '"/>'
@@ -13,7 +13,7 @@ module Axlsx
13
13
  # @option options [Integer] v
14
14
  def initialize(options = {})
15
15
  @format_code = "General"
16
- super(options)
16
+ super
17
17
  end
18
18
 
19
19
  # @see format_code
@@ -80,7 +80,7 @@ module Axlsx
80
80
  def image_src=(v)
81
81
  Axlsx.validate_string(v)
82
82
  if remote?
83
- RegexValidator.validate('Pic.image_src', /\A#{URI::DEFAULT_PARSER.make_regexp}\z/, v)
83
+ RegexValidator.validate('Pic.image_src', /\A#{Axlsx.uri_parser.make_regexp}\z/, v)
84
84
  RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeTypeUtils.get_mime_type_from_uri(v)
85
85
  else
86
86
  RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeTypeUtils.get_mime_type(v)
@@ -118,7 +118,7 @@ module Axlsx
118
118
  File.basename(image_src) unless remote? || image_src.nil?
119
119
  end
120
120
 
121
- # returns the extension of image_src without the preceeding '.'
121
+ # returns the extension of image_src without the preceding '.'
122
122
  # @return [String]
123
123
  def extname
124
124
  File.extname(image_src).delete('.') unless image_src.nil?
@@ -222,9 +222,9 @@ module Axlsx
222
222
  # Return correct xml relationship string portion
223
223
  def relationship_xml_portion
224
224
  if remote?
225
- (+'<a:blip xmlns:r ="' << XML_NS_R << '" r:link="' << relationship.Id << '">')
225
+ (+'<a:blip xmlns:r="' << XML_NS_R << '" r:link="' << relationship.Id << '">')
226
226
  else
227
- (+'<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '">')
227
+ (+'<a:blip xmlns:r="' << XML_NS_R << '" r:embed="' << relationship.Id << '">')
228
228
  end
229
229
  end
230
230
 
@@ -22,7 +22,7 @@ module Axlsx
22
22
  # @see View3D
23
23
  def initialize(frame, options = {})
24
24
  @vary_colors = true
25
- super(frame, options)
25
+ super
26
26
  @series_type = PieSeries
27
27
  @view_3D = View3D.new({ rot_x: 30, perspective: 30 }.merge(options))
28
28
  @d_lbls = nil
@@ -32,7 +32,7 @@ module Axlsx
32
32
  # @param [String] str
33
33
  # @return [String]
34
34
  def to_xml_string(str = +'')
35
- super(str) do
35
+ super do
36
36
  str << '<c:pie3DChart>'
37
37
  str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
38
38
  @series.each { |ser| ser.to_xml_string(str) }
@@ -15,7 +15,7 @@ module Axlsx
15
15
  # @see Chart
16
16
  def initialize(frame, options = {})
17
17
  @vary_colors = true
18
- super(frame, options)
18
+ super
19
19
  @series_type = PieSeries
20
20
  @d_lbls = nil
21
21
  end
@@ -24,7 +24,7 @@ module Axlsx
24
24
  # @param [String] str
25
25
  # @return [String]
26
26
  def to_xml_string(str = +'')
27
- super(str) do
27
+ super do
28
28
  str << '<c:pieChart>'
29
29
  str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
30
30
  @series.each { |ser| ser.to_xml_string(str) }
@@ -30,7 +30,7 @@ module Axlsx
30
30
  def initialize(chart, options = {})
31
31
  @explosion = nil
32
32
  @colors = []
33
- super(chart, options)
33
+ super
34
34
  self.labels = AxDataSource.new(data: options[:labels]) unless options[:labels].nil?
35
35
  self.data = NumDataSource.new(options) unless options[:data].nil?
36
36
  end
@@ -51,7 +51,7 @@ module Axlsx
51
51
  # @param [String] str
52
52
  # @return [String]
53
53
  def to_xml_string(str = +'')
54
- super(str) do
54
+ super do
55
55
  str << '<c:explosion val="' << @explosion.to_s << '"/>' unless @explosion.nil?
56
56
  colors.each_with_index do |c, index|
57
57
  str << '<c:dPt>'
@@ -33,7 +33,7 @@ module Axlsx
33
33
  @vary_colors = 0
34
34
  @scatter_style = :lineMarker
35
35
 
36
- super(frame, options)
36
+ super
37
37
  @series_type = ScatterSeries
38
38
  @d_lbls = nil
39
39
  parse_options options
@@ -50,7 +50,7 @@ module Axlsx
50
50
  # @param [String] str
51
51
  # @return [String]
52
52
  def to_xml_string(str = +'')
53
- super(str) do
53
+ super do
54
54
  str << '<c:scatterChart>'
55
55
  str << '<c:scatterStyle val="' << scatter_style.to_s << '"/>'
56
56
  str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
@@ -50,7 +50,7 @@ module Axlsx
50
50
  @show_marker = [:lineMarker, :marker, :smoothMarker].include?(chart.scatter_style)
51
51
  @marker_symbol = :default
52
52
 
53
- super(chart, options)
53
+ super
54
54
  @xData = AxDataSource.new(tag_name: :xVal, data: options[:xData]) unless options[:xData].nil?
55
55
  @yData = NumDataSource.new({ tag_name: :yVal, data: options[:yData] }) unless options[:yData].nil?
56
56
  end
@@ -81,7 +81,7 @@ module Axlsx
81
81
  # @param [String] str
82
82
  # @return [String]
83
83
  def to_xml_string(str = +'')
84
- super(str) do
84
+ super do
85
85
  # needs to override the super color here to push in ln/and something else!
86
86
  if color
87
87
  str << '<c:spPr><a:solidFill>'
@@ -3,7 +3,7 @@
3
3
  module Axlsx
4
4
  # A SerAxis object defines a series axis
5
5
  class SerAxis < Axis
6
- # The number of tick lables to skip between labels
6
+ # The number of tick labels to skip between labels
7
7
  # @return [Integer]
8
8
  attr_reader :tick_lbl_skip
9
9
  alias :tickLblSkip :tick_lbl_skip
@@ -18,7 +18,7 @@ module Axlsx
18
18
  # @option options [Integer] tick_mark_skip
19
19
  def initialize(options = {})
20
20
  @tick_lbl_skip, @tick_mark_skip = 1, 1
21
- super(options)
21
+ super
22
22
  end
23
23
 
24
24
  # @see tickLblSkip
@@ -40,7 +40,7 @@ module Axlsx
40
40
  # @return [String]
41
41
  def to_xml_string(str = +'')
42
42
  str << '<c:serAx>'
43
- super(str)
43
+ super
44
44
  str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>' unless @tick_lbl_skip.nil?
45
45
  str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>' unless @tick_mark_skip.nil?
46
46
  str << '</c:serAx>'
@@ -39,7 +39,7 @@ module Axlsx
39
39
  parse_options options
40
40
 
41
41
  # bit of a hack to work around the fact that the coords for start at and end at
42
- # are passed in as an array when specified in intialization options - however
42
+ # are passed in as an array when specified in initialization options - however
43
43
  start_at(*options[:start_at]) if options[:start_at]
44
44
  end_at(*options[:end_at]) if options[:end_at]
45
45
  end
@@ -13,7 +13,7 @@ module Axlsx
13
13
  # @option options [Symbol] crosses_between
14
14
  def initialize(options = {})
15
15
  self.cross_between = :between
16
- super(options)
16
+ super
17
17
  end
18
18
 
19
19
  # @see cross_between
@@ -28,7 +28,7 @@ module Axlsx
28
28
  # @return [String]
29
29
  def to_xml_string(str = +'')
30
30
  str << '<c:valAx>'
31
- super(str)
31
+ super
32
32
  str << '<c:crossBetween val="' << @cross_between.to_s << '"/>'
33
33
  str << '</c:valAx>'
34
34
  end
@@ -56,7 +56,7 @@ module Axlsx
56
56
  <x:AutoFill>False</x:AutoFill>
57
57
  <x:Row>#{row}</x:Row>
58
58
  <x:Column>#{column}</x:Column>
59
- #{@visible ? '<x:Visible/>' : ''}
59
+ #{'<x:Visible/>' if @visible}
60
60
  </x:ClientData>
61
61
  </v:shape>
62
62
  XML
data/lib/axlsx/package.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
4
- # Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid
4
+ # Package is responsible for managing all the bits and pieces that Open Office XML requires to make a valid
5
5
  # xlsx document including validation and serialization.
6
6
  class Package
7
7
  include Axlsx::OptionsParser
@@ -55,11 +55,11 @@ module Axlsx
55
55
  # @raise ArgumentError if workbook parameter is not a Workbook instance.
56
56
  # @note As there are multiple ways to instantiate a workbook for the package,
57
57
  # here are a few examples:
58
- # # assign directly during package instanciation
58
+ # # assign directly during package instantiation
59
59
  # wb = Package.new(:workbook => Workbook.new).workbook
60
60
  #
61
61
  # # get a fresh workbook automatically from the package
62
- # wb = Pacakge.new().workbook
62
+ # wb = Package.new().workbook
63
63
  # # # set the workbook after creating the package
64
64
  # wb = Package.new().workbook = Workbook.new
65
65
  def workbook
@@ -147,7 +147,7 @@ module Axlsx
147
147
 
148
148
  # Encrypt the package into a CFB using the password provided
149
149
  # This is not ready yet
150
- def encrypt(file_name, password)
150
+ def encrypt(file_name, password) # rubocop:disable Naming/PredicateMethod
151
151
  false
152
152
  # moc = MsOffCrypto.new(file_name, password)
153
153
  # moc.save
@@ -207,11 +207,12 @@ module Axlsx
207
207
  # Note: {Core#created} also defaults to the current time – so to generate identical axlsx packages you have
208
208
  # to set this explicitly, too (eg. with `Package.new(created_at: Time.local(2013, 1, 1))`).
209
209
  #
210
- # @param part A hash describing a part of this pacakge (see {#parts})
210
+ # @param part A hash describing a part of this package (see {#parts})
211
211
  # @return [Zip::Entry]
212
212
  def zip_entry_for_part(part)
213
213
  timestamp = Zip::DOSTime.at(@core.created.to_i)
214
- Zip::Entry.new("", part[:entry], "", "", 0, 0, Zip::Entry::DEFLATED, 0, timestamp)
214
+
215
+ Zip::Entry.new("", part[:entry], time: timestamp)
215
216
  end
216
217
 
217
218
  # The parts of a package
@@ -273,7 +274,7 @@ module Axlsx
273
274
  ]
274
275
  end
275
276
 
276
- # Performs xsd validation for a signle document
277
+ # Performs xsd validation for a single document
277
278
  #
278
279
  # @param [String] schema path to the xsd schema to be used in validation.
279
280
  # @param [String] doc The xml text to be validated
@@ -282,11 +283,8 @@ module Axlsx
282
283
  def validate_single_doc(schema, doc)
283
284
  schema = Nokogiri::XML::Schema(File.open(schema))
284
285
  doc = Nokogiri::XML(doc)
285
- errors = []
286
- schema.validate(doc).each do |error|
287
- errors << error
288
- end
289
- errors
286
+
287
+ schema.validate(doc)
290
288
  end
291
289
 
292
290
  # Appends override objects for drawings, charts, and sheets as they exist in your workbook to the default content types.
@@ -15,7 +15,7 @@ module Axlsx
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
- # Relationship instances are generated with the same IDs everytime the package
18
+ # Relationship instances are generated with the same IDs every time the package
19
19
  # is serialized).
20
20
  def initialize_ids_cache
21
21
  Thread.current[:axlsx_relationship_ids_cache] = {}
@@ -116,7 +116,7 @@ module Axlsx
116
116
  h = Axlsx.instance_values_for(self).reject { |k, _| k == "source_obj" }
117
117
  str << '<Relationship '
118
118
  h.each_with_index do |key_value, index|
119
- str << ' ' unless index.zero?
119
+ str << ' ' unless index == 0
120
120
  str << key_value.first.to_s << '="' << Axlsx.coder.encode(key_value.last.to_s) << '"'
121
121
  end
122
122
  str << '/>'
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
4
- require 'axlsx/rels/relationship'
4
+ require_relative 'relationship'
5
5
 
6
6
  # Relationships are a collection of Relations that define how package parts are related.
7
- # @note The package automatically manages releationships.
7
+ # @note The package automatically manages relationships.
8
8
  class Relationships < SimpleTypedList
9
9
  # Creates a new Relationships collection based on SimpleTypedList
10
10
  def initialize
@@ -4,10 +4,11 @@ module Axlsx
4
4
  # A border part.
5
5
  class BorderPr
6
6
  include Axlsx::OptionsParser
7
+
7
8
  # @return [Color] The color of this border part.
8
9
  attr_reader :color
9
10
 
10
- # @return [Symbol] The syle of this border part.
11
+ # @return [Symbol] The style of this border part.
11
12
  # @note
12
13
  # The following are allowed
13
14
  # :none
@@ -25,7 +25,7 @@ module Axlsx
25
25
 
26
26
  # The horizontal alignment of the cell.
27
27
  # @note
28
- # The horizontal cell alignement style must be one of
28
+ # The horizontal cell alignment style must be one of
29
29
  # :general
30
30
  # :left
31
31
  # :center
@@ -8,7 +8,7 @@ module Axlsx
8
8
  include Axlsx::OptionsParser
9
9
  include Axlsx::SerializedAttributes
10
10
 
11
- # Creats a new CellStyle object
11
+ # Creates a new CellStyle object
12
12
  # @option options [String] name
13
13
  # @option options [Integer] xfId
14
14
  # @option options [Integer] buildinId
@@ -17,7 +17,7 @@ module Axlsx
17
17
 
18
18
  serializable_attributes :auto, :rgb, :tint
19
19
 
20
- # Determines if the color is system color dependant
20
+ # Determines if the color is system color dependent
21
21
  # @return [Boolean]
22
22
  attr_reader :auto
23
23
 
@@ -72,7 +72,7 @@ module Axlsx
72
72
  # This version does not support themes
73
73
  # def theme=(v) Axlsx::validate_unsigned_integer v; @theme = v end
74
74
 
75
- # Indexed colors are for backward compatability which I am choosing not to support
75
+ # Indexed colors are for backward compatibility which I am choosing not to support
76
76
  # def indexed=(v) Axlsx::validate_unsigned_integer v; @indexed = v end
77
77
 
78
78
  # Serializes the object
@@ -33,7 +33,7 @@ module Axlsx
33
33
  # The charset of the font
34
34
  # @return [Integer]
35
35
  # @note
36
- # The following values are defined in the OOXML specification and are OS dependant values
36
+ # The following values are defined in the OOXML specification and are OS dependent values
37
37
  # 0 ANSI_CHARSET
38
38
  # 1 DEFAULT_CHARSET
39
39
  # 2 SYMBOL_CHARSET
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
4
- # A GradientFill defines the color and positioning for gradiant cell fill.
4
+ # A GradientFill defines the color and positioning for gradient cell fill.
5
5
  # @see Open Office XML Part 1 §18.8.24
6
6
  class GradientFill
7
7
  include Axlsx::OptionsParser
@@ -6,6 +6,7 @@ module Axlsx
6
6
  # @see Style#add_style
7
7
  class PatternFill
8
8
  include Axlsx::OptionsParser
9
+
9
10
  # Creates a new PatternFill Object
10
11
  # @option options [Symbol] patternType
11
12
  # @option options [Color] fgColor
@@ -1,27 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
4
- require 'axlsx/stylesheet/border'
5
- require 'axlsx/stylesheet/border_pr'
6
- require 'axlsx/stylesheet/cell_alignment'
7
- require 'axlsx/stylesheet/cell_style'
8
- require 'axlsx/stylesheet/color'
9
- require 'axlsx/stylesheet/fill'
10
- require 'axlsx/stylesheet/font'
11
- require 'axlsx/stylesheet/gradient_fill'
12
- require 'axlsx/stylesheet/gradient_stop'
13
- require 'axlsx/stylesheet/num_fmt'
14
- require 'axlsx/stylesheet/pattern_fill'
15
- require 'axlsx/stylesheet/table_style'
16
- require 'axlsx/stylesheet/table_styles'
17
- require 'axlsx/stylesheet/table_style_element'
18
- require 'axlsx/stylesheet/dxf'
19
- require 'axlsx/stylesheet/xf'
20
- require 'axlsx/stylesheet/cell_protection'
4
+ require_relative 'border'
5
+ require_relative 'border_pr'
6
+ require_relative 'cell_alignment'
7
+ require_relative 'cell_style'
8
+ require_relative 'color'
9
+ require_relative 'fill'
10
+ require_relative 'font'
11
+ require_relative 'gradient_fill'
12
+ require_relative 'gradient_stop'
13
+ require_relative 'num_fmt'
14
+ require_relative 'pattern_fill'
15
+ require_relative 'table_style'
16
+ require_relative 'table_styles'
17
+ require_relative 'table_style_element'
18
+ require_relative 'dxf'
19
+ require_relative 'xf'
20
+ require_relative 'cell_protection'
21
21
 
22
22
  # The Styles class manages worksheet styles
23
23
  # In addition to creating the require style objects for a valid xlsx package, this class provides the key mechanism for adding styles to your workbook, and safely applying them to the cells of your worksheet.
24
- # All portions of the stylesheet are implemented here exception colors, which specify legacy and modified pallete colors, and exLst, whic is used as a future feature data storage area.
24
+ # All portions of the stylesheet are implemented here exception colors, which specify legacy and modified palette colors, and exLst, which is used as a future feature data storage area.
25
25
  # @see Office Open XML Part 1 18.8.11 for gory details on how this stuff gets put together
26
26
  # @see Styles#add_style
27
27
  # @note The recommended way to manage styles is with add_style
@@ -156,7 +156,7 @@ module Axlsx
156
156
  # ws = p.workbook.add_worksheet
157
157
  #
158
158
  # # black text on a white background at 14pt with thin borders!
159
- # title = ws.styles.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
159
+ # title = ws.styles.add_style(:bg_color => "FFFF0000", :fg_color=>"FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
160
160
  #
161
161
  # ws.add_row ["Least Popular Pets"]
162
162
  # ws.add_row ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
@@ -174,7 +174,7 @@ module Axlsx
174
174
  #
175
175
  # # define your styles
176
176
  # title = ws.styles.add_style(:bg_color => "FFFF0000",
177
- # :fg_color=>"#FF000000",
177
+ # :fg_color=>"FF000000",
178
178
  # :border=>Axlsx::STYLE_THIN_BORDER,
179
179
  # :alignment=>{:horizontal => :center})
180
180
  #
@@ -209,10 +209,10 @@ module Axlsx
209
209
  #
210
210
  # # define your styles
211
211
  # profitable = wb.styles.add_style(:bg_color => "FFFF0000",
212
- # :fg_color=>"#FF000000",
212
+ # :fg_color=>"FF000000",
213
213
  # :type => :dxf)
214
214
  #
215
- # ws.add_row ["Genreated At:", Time.now], :styles=>[nil, date_time]
215
+ # ws.add_row ["Generated At:", Time.now], :styles=>[nil, date_time]
216
216
  # ws.add_row ["Previous Year Quarterly Profits (JPY)"], :style=>title
217
217
  # ws.add_row ["Quarter", "Profit", "% of Total"], :style=>title
218
218
  # ws.add_row ["Q1", 4000, 40], :style=>[title, currency, percent]
@@ -245,7 +245,7 @@ module Axlsx
245
245
 
246
246
  font_defaults = { name: @fonts.first.name, sz: @fonts.first.sz, family: @fonts.first.family }
247
247
 
248
- raw_style = { type: :xf }.merge(font_defaults).merge(options)
248
+ raw_style = { type: :xf }.merge(font_defaults, options)
249
249
 
250
250
  if raw_style[:format_code]
251
251
  raw_style.delete(:num_fmt)
@@ -275,7 +275,7 @@ module Axlsx
275
275
  if options[:type] == :xf
276
276
  xf_index = (cellXfs << style)
277
277
 
278
- # Add styles to style_index cache for re-use
278
+ # Add styles to style_index cache for reuse
279
279
  style_index[xf_index] = raw_style
280
280
 
281
281
  xf_index
@@ -298,7 +298,7 @@ module Axlsx
298
298
 
299
299
  # parses add_style options for alignment
300
300
  # noop if options hash does not include :alignment key
301
- # @option options [Hash] alignment A hash of options to prive the CellAlignment intializer
301
+ # @option options [Hash] alignment A hash of options to prive the CellAlignment initializer
302
302
  # @return [CellAlignment]
303
303
  # @see CellAlignment
304
304
  def parse_alignment_options(options = {})
@@ -325,11 +325,7 @@ module Axlsx
325
325
  def parse_font_options(options = {})
326
326
  return if (options.keys & [:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name]).empty?
327
327
 
328
- Axlsx.instance_values_for(fonts.first).each do |key, value|
329
- # Thanks for that 1.8.7 - cant do a simple merge...
330
- options[key.to_sym] = value unless options.key?(key.to_sym)
331
- end
332
- font = Font.new(options)
328
+ font = Font.new(Axlsx.instance_values_for(fonts.first).merge(options))
333
329
  font.color = Color.new(rgb: options[:fg_color]) if options[:fg_color]
334
330
  font.name = options[:font_name] if options[:font_name]
335
331
  options[:type] == :dxf ? font : fonts << font
@@ -361,7 +357,7 @@ module Axlsx
361
357
 
362
358
  # Both bgColor and fgColor happens to configure the background of the cell.
363
359
  # One of them sets the "background" of the cell, while the other one is
364
- # responsibe for the "pattern" of the cell. When you pick "solid" pattern for
360
+ # responsible for the "pattern" of the cell. When you pick "solid" pattern for
365
361
  # a normal xf style, then it's a rectangle covering all bgColor with fgColor,
366
362
  # which means we need to to set the given background color to fgColor as well.
367
363
  # For some reason I wasn't able find, it works the opposite for dxf styles
@@ -8,6 +8,7 @@ module Axlsx
8
8
 
9
9
  include Axlsx::SerializedAttributes
10
10
  include Axlsx::OptionsParser
11
+
11
12
  # Creates a new Xf object
12
13
  # @option options [Integer] numFmtId
13
14
  # @option options [Integer] fontId
@@ -62,7 +63,7 @@ module Axlsx
62
63
  # @return [Integer]
63
64
  attr_reader :xfId
64
65
 
65
- # indecates if text should be prefixed by a single quote in the cell
66
+ # indicates if text should be prefixed by a single quote in the cell
66
67
  # @return [Boolean]
67
68
  attr_reader :quotePrefix
68
69
 
@@ -23,7 +23,7 @@ module Axlsx
23
23
  validated_attr_accessor(symbols, :validate_string)
24
24
  end
25
25
 
26
- # Creates one or more usigned integer attr_accessors
26
+ # Creates one or more unsigned integer attr_accessors
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)
@@ -19,7 +19,7 @@ module Axlsx
19
19
  #
20
20
  # The directory and its contents are removed at the end of the block.
21
21
  def self.open(file_name, encrypter = nil)
22
- Zip::OutputStream.open(file_name, encrypter) do |zos|
22
+ Zip::OutputStream.open(file_name, encrypter: encrypter) do |zos|
23
23
  bzos = new(zos)
24
24
  yield(bzos)
25
25
  ensure
@@ -28,7 +28,7 @@ module Axlsx
28
28
  end
29
29
 
30
30
  def self.write_buffer(io = ::StringIO.new, encrypter = nil)
31
- Zip::OutputStream.write_buffer(io, encrypter) do |zos|
31
+ Zip::OutputStream.write_buffer(io, encrypter: encrypter) do |zos|
32
32
  bzos = new(zos)
33
33
  yield(bzos)
34
34
  ensure
@@ -259,7 +259,7 @@ module Axlsx
259
259
  # drawing validation schema
260
260
  DRAWING_XSD = "#{SCHEMA_BASE}dml-spreadsheetDrawing.xsd"
261
261
 
262
- # number format id for pecentage formatting using the default formatting id.
262
+ # number format id for percentage formatting using the default formatting id.
263
263
  NUM_FMT_PERCENT = 9
264
264
 
265
265
  # number format id for date format like 2011/11/13
@@ -404,7 +404,7 @@ module Axlsx
404
404
  CONTROL_CHARS = pattern.freeze
405
405
 
406
406
  # ISO 8601 date recognition
407
- 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
407
+ 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/.freeze
408
408
 
409
409
  # FLOAT recognition
410
410
  SAFE_FLOAT_REGEX = /\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]{1,2})?\Z/.freeze
@@ -91,8 +91,8 @@ module Axlsx
91
91
 
92
92
  # serialized instance values at text nodes on a camelized element of the
93
93
  # attribute name. You may pass in a block for evaluation against non nil
94
- # values. We use an array for element attributes becuase misordering will
95
- # break the xml and 1.8.7 does not support ordered hashes.
94
+ # values. We use an array for element attributes because misordering will
95
+ # break the xml.
96
96
  # @param [String] str The string instance to which serialized data is appended
97
97
  # @param [Array] additional_attributes An array of additional attribute names.
98
98
  # @return [String] The serialized output.