caxlsx 3.3.0 → 4.5.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 (155) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -11
  3. data/README.md +43 -16
  4. data/Rakefile +5 -11
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +15 -10
  7. data/lib/axlsx/content_type/content_type.rb +8 -10
  8. data/lib/axlsx/content_type/default.rb +7 -6
  9. data/lib/axlsx/content_type/override.rb +6 -5
  10. data/lib/axlsx/doc_props/app.rb +96 -32
  11. data/lib/axlsx/doc_props/core.rb +9 -12
  12. data/lib/axlsx/drawing/area_chart.rb +16 -17
  13. data/lib/axlsx/drawing/area_series.rb +23 -18
  14. data/lib/axlsx/drawing/ax_data_source.rb +4 -7
  15. data/lib/axlsx/drawing/axes.rb +11 -10
  16. data/lib/axlsx/drawing/axis.rb +83 -36
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +30 -21
  18. data/lib/axlsx/drawing/bar_chart.rb +29 -20
  19. data/lib/axlsx/drawing/bar_series.rb +23 -18
  20. data/lib/axlsx/drawing/bubble_chart.rb +9 -10
  21. data/lib/axlsx/drawing/bubble_series.rb +11 -12
  22. data/lib/axlsx/drawing/cat_axis.rb +38 -28
  23. data/lib/axlsx/drawing/chart.rb +52 -30
  24. data/lib/axlsx/drawing/d_lbls.rb +36 -32
  25. data/lib/axlsx/drawing/drawing.rb +61 -62
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  27. data/lib/axlsx/drawing/hyperlink.rb +22 -14
  28. data/lib/axlsx/drawing/line_3D_chart.rb +15 -17
  29. data/lib/axlsx/drawing/line_chart.rb +16 -17
  30. data/lib/axlsx/drawing/line_series.rb +23 -18
  31. data/lib/axlsx/drawing/marker.rb +29 -16
  32. data/lib/axlsx/drawing/num_data.rb +13 -16
  33. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  34. data/lib/axlsx/drawing/num_val.rb +10 -11
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +16 -10
  36. data/lib/axlsx/drawing/pic.rb +68 -24
  37. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +9 -12
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +26 -17
  41. data/lib/axlsx/drawing/scaling.rb +26 -13
  42. data/lib/axlsx/drawing/scatter_chart.rb +10 -11
  43. data/lib/axlsx/drawing/scatter_series.rb +17 -18
  44. data/lib/axlsx/drawing/ser_axis.rb +22 -19
  45. data/lib/axlsx/drawing/series.rb +14 -8
  46. data/lib/axlsx/drawing/series_title.rb +6 -6
  47. data/lib/axlsx/drawing/str_data.rb +10 -13
  48. data/lib/axlsx/drawing/str_val.rb +8 -9
  49. data/lib/axlsx/drawing/title.rb +23 -27
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +9 -9
  51. data/lib/axlsx/drawing/val_axis.rb +7 -8
  52. data/lib/axlsx/drawing/view_3D.rb +38 -30
  53. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  54. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  55. data/lib/axlsx/package.rb +134 -99
  56. data/lib/axlsx/rels/relationship.rb +42 -30
  57. data/lib/axlsx/rels/relationships.rb +9 -10
  58. data/lib/axlsx/stylesheet/border.rb +16 -8
  59. data/lib/axlsx/stylesheet/border_pr.rb +24 -12
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +44 -21
  61. data/lib/axlsx/stylesheet/cell_protection.rb +13 -7
  62. data/lib/axlsx/stylesheet/cell_style.rb +36 -15
  63. data/lib/axlsx/stylesheet/color.rb +23 -14
  64. data/lib/axlsx/stylesheet/dxf.rb +36 -15
  65. data/lib/axlsx/stylesheet/fill.rb +7 -6
  66. data/lib/axlsx/stylesheet/font.rb +71 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +16 -10
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -6
  69. data/lib/axlsx/stylesheet/num_fmt.rb +15 -14
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +20 -8
  71. data/lib/axlsx/stylesheet/styles.rb +167 -118
  72. data/lib/axlsx/stylesheet/table_style.rb +20 -10
  73. data/lib/axlsx/stylesheet/table_style_element.rb +16 -8
  74. data/lib/axlsx/stylesheet/table_styles.rb +16 -11
  75. data/lib/axlsx/stylesheet/theme.rb +163 -0
  76. data/lib/axlsx/stylesheet/xf.rb +78 -25
  77. data/lib/axlsx/util/accessors.rb +13 -11
  78. data/lib/axlsx/util/buffered_zip_output_stream.rb +64 -0
  79. data/lib/axlsx/util/constants.rb +133 -110
  80. data/lib/axlsx/util/mime_type_utils.rb +75 -5
  81. data/lib/axlsx/util/options_parser.rb +4 -3
  82. data/lib/axlsx/util/serialized_attributes.rb +47 -23
  83. data/lib/axlsx/util/simple_typed_list.rb +77 -64
  84. data/lib/axlsx/util/storage.rb +38 -41
  85. data/lib/axlsx/util/uri_utils.rb +70 -0
  86. data/lib/axlsx/util/validators.rb +111 -48
  87. data/lib/axlsx/util/zip_command.rb +10 -12
  88. data/lib/axlsx/version.rb +3 -2
  89. data/lib/axlsx/workbook/defined_name.rb +13 -9
  90. data/lib/axlsx/workbook/defined_names.rb +5 -4
  91. data/lib/axlsx/workbook/shared_strings_table.rb +13 -14
  92. data/lib/axlsx/workbook/workbook.rb +152 -120
  93. data/lib/axlsx/workbook/workbook_view.rb +9 -12
  94. data/lib/axlsx/workbook/workbook_views.rb +5 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +87 -15
  96. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +16 -10
  97. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +28 -25
  98. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  99. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +54 -0
  100. data/lib/axlsx/workbook/worksheet/border_creator.rb +34 -29
  101. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  102. data/lib/axlsx/workbook/worksheet/cell.rb +125 -78
  103. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +33 -29
  104. data/lib/axlsx/workbook/worksheet/cfvo.rb +13 -5
  105. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  106. data/lib/axlsx/workbook/worksheet/col.rb +32 -19
  107. data/lib/axlsx/workbook/worksheet/col_breaks.rb +9 -8
  108. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  109. data/lib/axlsx/workbook/worksheet/cols.rb +10 -8
  110. data/lib/axlsx/workbook/worksheet/comment.rb +14 -13
  111. data/lib/axlsx/workbook/worksheet/comments.rb +11 -13
  112. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +19 -9
  113. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +75 -22
  114. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  116. data/lib/axlsx/workbook/worksheet/data_validation.rb +73 -33
  117. data/lib/axlsx/workbook/worksheet/data_validations.rb +8 -9
  118. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  119. data/lib/axlsx/workbook/worksheet/dimension.rb +10 -7
  120. data/lib/axlsx/workbook/worksheet/header_footer.rb +5 -4
  121. data/lib/axlsx/workbook/worksheet/icon_set.rb +40 -12
  122. data/lib/axlsx/workbook/worksheet/merged_cells.rb +11 -11
  123. data/lib/axlsx/workbook/worksheet/outline_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_margins.rb +41 -13
  125. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -6
  126. data/lib/axlsx/workbook/worksheet/page_setup.rb +153 -131
  127. data/lib/axlsx/workbook/worksheet/pane.rb +34 -26
  128. data/lib/axlsx/workbook/worksheet/pivot_table.rb +78 -29
  129. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  130. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +6 -5
  131. data/lib/axlsx/workbook/worksheet/print_options.rb +4 -2
  132. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  133. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +13 -11
  134. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  135. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +66 -28
  136. data/lib/axlsx/workbook/worksheet/row.rb +34 -23
  137. data/lib/axlsx/workbook/worksheet/row_breaks.rb +9 -8
  138. data/lib/axlsx/workbook/worksheet/selection.rb +22 -16
  139. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +11 -7
  140. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  141. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  142. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +12 -8
  143. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +22 -21
  144. data/lib/axlsx/workbook/worksheet/sheet_view.rb +71 -55
  145. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  146. data/lib/axlsx/workbook/worksheet/table_style_info.rb +8 -6
  147. data/lib/axlsx/workbook/worksheet/tables.rb +8 -6
  148. data/lib/axlsx/workbook/worksheet/worksheet.rb +120 -79
  149. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +13 -11
  150. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  151. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +12 -10
  152. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +9 -7
  153. data/lib/axlsx.rb +120 -60
  154. data/lib/caxlsx.rb +3 -2
  155. metadata +42 -75
@@ -1,11 +1,12 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A worksheet hyperlink object. Note that this is not the same as a drawing hyperlink object.
4
5
  class WorksheetHyperlink
5
-
6
6
  include Axlsx::OptionsParser
7
7
  include Axlsx::Accessors
8
8
  include Axlsx::SerializedAttributes
9
+
9
10
  # Creates a new hyperlink object.
10
11
  # @note the preferred way to add hyperlinks to your worksheet is the Worksheet#add_hyperlink method
11
12
  # @param [Worksheet] worksheet the Worksheet that owns this hyperlink
@@ -15,7 +16,7 @@ module Axlsx
15
16
  # @option [String] tooltip The tip to display when the user positions the mouse cursor over this hyperlink
16
17
  # @option [Symbol] target This is :external by default. If you set it to anything else, the location is interpreted to be the current workbook.
17
18
  # @option [String|Cell] ref The location of this hyperlink in the worksheet
18
- def initialize(worksheet, options={})
19
+ def initialize(worksheet, options = {})
19
20
  DataTypeValidator.validate "Hyperlink.worksheet", [Worksheet], worksheet
20
21
  @worksheet = worksheet
21
22
  @target = :external
@@ -27,7 +28,7 @@ module Axlsx
27
28
 
28
29
  serializable_attributes :display, :tooltip, :ref
29
30
 
30
- #Cell location of hyperlink on worksheet.
31
+ # Cell location of hyperlink on worksheet.
31
32
  # @return [String]
32
33
  attr_reader :ref
33
34
 
@@ -41,7 +42,7 @@ module Axlsx
41
42
  # @param [String|Cell] cell_reference The string reference or cell that defines where this hyperlink shows in the worksheet.
42
43
  def ref=(cell_reference)
43
44
  cell_reference = cell_reference.r if cell_reference.is_a?(Cell)
44
- Axlsx::validate_string cell_reference
45
+ Axlsx.validate_string cell_reference
45
46
  @ref = cell_reference
46
47
  end
47
48
 
@@ -51,15 +52,16 @@ module Axlsx
51
52
  # @return [Relationship]
52
53
  def relationship
53
54
  return unless @target == :external
54
- Relationship.new(self, HYPERLINK_R, location, :target_mode => :External)
55
+
56
+ Relationship.new(self, HYPERLINK_R, location, target_mode: :External)
55
57
  end
56
58
 
57
- # Seralize the object
59
+ # Serialize the object
58
60
  # @param [String] str
59
61
  # @return [String]
60
- def to_xml_string(str='')
62
+ def to_xml_string(str = +'')
61
63
  str << '<hyperlink '
62
- serialized_attributes str, location_or_id
64
+ serialized_attributes str, location_or_id, false
63
65
  str << '/>'
64
66
  end
65
67
 
@@ -68,7 +70,7 @@ module Axlsx
68
70
  # r:id should only be specified for external targets.
69
71
  # @return [Hash]
70
72
  def location_or_id
71
- @target == :external ? { :"r:id" => relationship.Id } : { :location => Axlsx::coder.encode(location) }
73
+ @target == :external ? { "r:id": relationship.Id } : { location: Axlsx.coder.encode(location) }
72
74
  end
73
75
  end
74
76
  end
@@ -1,14 +1,14 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
- #A collection of hyperlink objects for a worksheet
3
+ module Axlsx
4
+ # A collection of hyperlink objects for a worksheet
4
5
  class WorksheetHyperlinks < SimpleTypedList
5
-
6
6
  # Creates a new Hyperlinks collection
7
7
  # @param [Worksheet] worksheet the worksheet that owns these hyperlinks
8
8
  def initialize(worksheet)
9
9
  DataTypeValidator.validate "Hyperlinks.worksheet", [Worksheet], worksheet
10
10
  @worksheet = worksheet
11
- super WorksheetHyperlink
11
+ super(WorksheetHyperlink)
12
12
  end
13
13
 
14
14
  # Creates and adds a new hyperlink based on the options provided
@@ -23,13 +23,15 @@ module Axlsx
23
23
  # @return Array
24
24
  def relationships
25
25
  return [] if empty?
26
- map { |hyperlink| hyperlink.relationship }
26
+
27
+ map(&:relationship)
27
28
  end
28
29
 
29
- # seralize the collection of hyperlinks
30
+ # serialize the collection of hyperlinks
30
31
  # @return [String]
31
- def to_xml_string(str='')
32
+ def to_xml_string(str = +'')
32
33
  return if empty?
34
+
33
35
  str << '<hyperlinks>'
34
36
  each { |hyperlink| hyperlink.to_xml_string(str) }
35
37
  str << '</hyperlinks>'
data/lib/axlsx.rb CHANGED
@@ -1,42 +1,44 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'axlsx/version'
4
+
5
+ # gemspec dependencies
2
6
  require 'htmlentities'
3
- require 'axlsx/version.rb'
4
7
  require 'marcel'
5
-
6
- require 'axlsx/util/simple_typed_list.rb'
7
- require 'axlsx/util/constants.rb'
8
- require 'axlsx/util/validators.rb'
9
- require 'axlsx/util/accessors.rb'
10
- require 'axlsx/util/serialized_attributes'
11
- require 'axlsx/util/options_parser'
12
- require 'axlsx/util/mime_type_utils'
13
- require 'axlsx/util/zip_command'
14
-
15
- require 'axlsx/stylesheet/styles.rb'
16
-
17
- require 'axlsx/doc_props/app.rb'
18
- require 'axlsx/doc_props/core.rb'
19
- require 'axlsx/content_type/content_type.rb'
20
- require 'axlsx/rels/relationships.rb'
21
-
22
- require 'axlsx/drawing/drawing.rb'
23
- require 'axlsx/workbook/workbook.rb'
24
- require 'axlsx/package.rb'
25
- #required gems
26
8
  require 'nokogiri'
27
9
  require 'zip'
28
10
 
29
- #core dependencies
30
- require 'bigdecimal'
11
+ # Ruby core dependencies
12
+ require 'cgi/escape'
31
13
  require 'set'
32
14
  require 'time'
15
+ require 'uri'
16
+ require 'net/http'
33
17
 
34
- begin
35
- if Gem.loaded_specs.has_key?("axlsx_styler")
36
- raise StandardError.new("Please remove `axlsx_styler` from your Gemfile, the associated functionality is now built-in to `caxlsx` directly.")
37
- end
38
- rescue
39
- # Do nothing
18
+ require_relative 'axlsx/util/simple_typed_list'
19
+ require_relative 'axlsx/util/constants'
20
+ require_relative 'axlsx/util/validators'
21
+ require_relative 'axlsx/util/accessors'
22
+ require_relative 'axlsx/util/serialized_attributes'
23
+ require_relative 'axlsx/util/options_parser'
24
+ require_relative 'axlsx/util/uri_utils'
25
+ require_relative 'axlsx/util/mime_type_utils'
26
+ require_relative 'axlsx/util/buffered_zip_output_stream'
27
+ require_relative 'axlsx/util/zip_command'
28
+
29
+ require_relative 'axlsx/stylesheet/styles'
30
+
31
+ require_relative 'axlsx/doc_props/app'
32
+ require_relative 'axlsx/doc_props/core'
33
+ require_relative 'axlsx/content_type/content_type'
34
+ require_relative 'axlsx/rels/relationships'
35
+
36
+ require_relative 'axlsx/drawing/drawing'
37
+ require_relative 'axlsx/workbook/workbook'
38
+ require_relative 'axlsx/package'
39
+
40
+ if Gem.loaded_specs.key?("axlsx_styler")
41
+ raise StandardError, "Please remove `axlsx_styler` from your Gemfile, the associated functionality is now built-in to `caxlsx` directly."
40
42
  end
41
43
 
42
44
  # xlsx generation with charts, images, automated column width, customizable styles
@@ -51,11 +53,11 @@ module Axlsx
51
53
  #
52
54
  # Defining as a class method on Axlsx to refrain from monkeypatching Object for all users of this gem.
53
55
  def self.instance_values_for(object)
54
- Hash[object.instance_variables.map { |name| [name.to_s[1..-1], object.instance_variable_get(name)] }]
56
+ object.instance_variables.to_h { |name| [name.to_s[1..], object.instance_variable_get(name)] }
55
57
  end
56
58
 
57
59
  # determines the cell range for the items provided
58
- def self.cell_range(cells, absolute=true)
60
+ def self.cell_range(cells, absolute = true)
59
61
  return "" unless cells.first.is_a? Cell
60
62
 
61
63
  first_cell, last_cell = cells.minmax_by(&:pos)
@@ -76,7 +78,7 @@ module Axlsx
76
78
  cells.sort_by(&:pos)
77
79
  end
78
80
 
79
- #global reference html entity encoding
81
+ # global reference html entity encoding
80
82
  # @return [HtmlEntities]
81
83
  def self.coder
82
84
  @@coder ||= ::HTMLEntities.new
@@ -89,12 +91,10 @@ module Axlsx
89
91
  letters_str = name[/[A-Z]+/]
90
92
 
91
93
  # capitalization?!?
92
- v = letters_str.reverse.chars.reduce({:base=>1, :i=>0}) do |val, c|
94
+ v = letters_str.reverse.chars.each_with_object({ base: 1, i: 0 }) do |c, val|
93
95
  val[:i] += ((c.bytes.first - 64) * val[:base])
94
96
 
95
97
  val[:base] *= 26
96
-
97
- next val
98
98
  end
99
99
 
100
100
  col_index = (v[:i] - 1)
@@ -103,37 +103,51 @@ module Axlsx
103
103
 
104
104
  row_index = (numbers_str.to_i - 1)
105
105
 
106
- return [col_index, row_index]
106
+ [col_index, row_index]
107
107
  end
108
108
 
109
109
  # converts the column index into alphabetical values.
110
110
  # @note This follows the standard spreadsheet convention of naming columns A to Z, followed by AA to AZ etc.
111
111
  # @return [String]
112
112
  def self.col_ref(index)
113
- chars = ''
114
- while index >= 26 do
115
- index, char = index.divmod(26)
116
- chars.prepend((char + 65).chr)
117
- index -= 1
113
+ # Every row will call this for each column / cell and so we can cache result and avoid lots of small object
114
+ # allocations.
115
+ @col_ref ||= {}
116
+ @col_ref[index] ||= begin
117
+ i = index
118
+ chars = +''
119
+ while i >= 26
120
+ i, char = i.divmod(26)
121
+ chars.prepend((char + 65).chr)
122
+ i -= 1
123
+ end
124
+ chars.prepend((i + 65).chr)
125
+ chars.freeze
118
126
  end
119
- chars.prepend((index + 65).chr)
120
- chars
127
+ end
128
+
129
+ # converts the row index into string values.
130
+ # @note The spreadsheet rows are 1-based and the passed in index is 0-based, so we add 1.
131
+ # @return [String]
132
+ def self.row_ref(index)
133
+ @row_ref ||= {}
134
+ @row_ref[index] ||= (index + 1).to_s.freeze
121
135
  end
122
136
 
123
137
  # @return [String] The alpha(column)numeric(row) reference for this sell.
124
138
  # @example Relative Cell Reference
125
139
  # ws.rows.first.cells.first.r #=> "A1"
126
140
  def self.cell_r(c_index, r_index)
127
- col_ref(c_index) << (r_index+1).to_s
141
+ col_ref(c_index) + row_ref(r_index)
128
142
  end
129
143
 
130
- # Creates an array of individual cell references based on an excel reference range.
144
+ # Creates an array of individual cell references based on an Excel reference range.
131
145
  # @param [String] range A cell range, for example A1:D5
132
146
  # @return [Array]
133
147
  def self.range_to_a(range)
134
- range.match(/^(\w+?\d+)\:(\w+?\d+)$/)
135
- start_col, start_row = name_to_indices($1)
136
- end_col, end_row = name_to_indices($2)
148
+ range =~ /^(\w+?\d+):(\w+?\d+)$/
149
+ start_col, start_row = name_to_indices(::Regexp.last_match(1))
150
+ end_col, end_row = name_to_indices(::Regexp.last_match(2))
137
151
  (start_row..end_row).to_a.map do |row_num|
138
152
  (start_col..end_col).to_a.map do |col_num|
139
153
  cell_r(col_num, row_num)
@@ -141,16 +155,16 @@ module Axlsx
141
155
  end
142
156
  end
143
157
 
144
- # performs the increadible feat of changing snake_case to CamelCase
158
+ # performs the incredible feat of changing snake_case to CamelCase
145
159
  # @param [String] s The snake case string to camelize
146
160
  # @return [String]
147
- def self.camel(s="", all_caps = true)
161
+ def self.camel(s = "", all_caps = true)
148
162
  s = s.to_s
149
163
  s = s.capitalize if all_caps
150
- s.gsub(/_(.)/){ $1.upcase }
164
+ s.gsub(/_(.)/) { ::Regexp.last_match(1).upcase }
151
165
  end
152
166
 
153
- # returns the provided string with all invalid control charaters
167
+ # returns the provided string with all invalid control characters
154
168
  # removed.
155
169
  # @param [String] str The string to process
156
170
  # @return [String]
@@ -168,18 +182,18 @@ module Axlsx
168
182
  # @param [Object] value The value to process
169
183
  # @return [Object]
170
184
  def self.booleanize(value)
171
- if value == true || value == false
172
- value ? 1 : 0
185
+ if BOOLEAN_VALUES.include?(value)
186
+ value ? '1' : '0'
173
187
  else
174
188
  value
175
189
  end
176
190
  end
177
191
 
178
192
  # utility method for performing a deep merge on a Hash
179
- # @param [Hash] Hash to merge into
180
- # @param [Hash] Hash to be added
193
+ # @param [Hash] first_hash Hash to merge into
194
+ # @param [Hash] second_hash Hash to be added
181
195
  def self.hash_deep_merge(first_hash, second_hash)
182
- first_hash.merge(second_hash) do |key, this_val, other_val|
196
+ first_hash.merge(second_hash) do |_key, this_val, other_val|
183
197
  if this_val.is_a?(Hash) && other_val.is_a?(Hash)
184
198
  Axlsx.hash_deep_merge(this_val, other_val)
185
199
  else
@@ -190,7 +204,7 @@ module Axlsx
190
204
 
191
205
  # Instructs the serializer to not try to escape cell value input.
192
206
  # This will give you a huge speed bonus, but if you content has <, > or other xml character data
193
- # the workbook will be invalid and excel will complain.
207
+ # the workbook will be invalid and Excel will complain.
194
208
  def self.trust_input
195
209
  @trust_input ||= false
196
210
  end
@@ -201,4 +215,50 @@ module Axlsx
201
215
  def self.trust_input=(trust_me)
202
216
  @trust_input = trust_me
203
217
  end
218
+
219
+ # Whether to treat values starting with an equals sign as formulas or as literal strings.
220
+ # Allowing user-generated data to be interpreted as formulas is a security risk.
221
+ # See https://www.owasp.org/index.php/CSV_Injection for details.
222
+ # @return [Boolean]
223
+ def self.escape_formulas
224
+ !defined?(@escape_formulas) || @escape_formulas.nil? ? true : @escape_formulas
225
+ end
226
+
227
+ # Sets whether to treat values starting with an equals sign as formulas or as literal strings.
228
+ # @param [Boolean] value The value to set.
229
+ def self.escape_formulas=(value)
230
+ Axlsx.validate_boolean(value)
231
+ @escape_formulas = value
232
+ end
233
+
234
+ # Whether to validate the sheet name length.
235
+ # @return [Boolean]
236
+ def self.validate_sheet_name_length
237
+ !defined?(@validate_sheet_name_length) || @validate_sheet_name_length.then { |v| v.nil? || v }
238
+ end
239
+
240
+ # Sets whether to validate sheet name length.
241
+ # By default it validates the max length for sheet names to make it compatible with Microsoft Excel
242
+ # On paper, and by real world examples this is still a valid limitation, but some implementations (e.g. Libre Office) might not break on longer names.
243
+ # Use it if you are sure that the end users could still open the files.
244
+ # @param [Boolean] value The value to set.
245
+ def self.validate_sheet_name_length=(value)
246
+ Axlsx.validate_boolean(value)
247
+ @validate_sheet_name_length = value
248
+ end
249
+
250
+ # Returns a URI parser instance, preferring RFC2396_PARSER if available,
251
+ # otherwise falling back to DEFAULT_PARSER. This method ensures consistent
252
+ # URI parsing across different Ruby versions.
253
+ # This method can be removed when dropping compatibility for Ruby < 3.4
254
+ # See https://github.com/ruby/uri/pull/114 for details.
255
+ # @return [Object]
256
+ def self.uri_parser
257
+ @uri_parser ||=
258
+ if defined?(URI::RFC2396_PARSER)
259
+ URI::RFC2396_PARSER
260
+ else
261
+ URI::DEFAULT_PARSER
262
+ end
263
+ end
204
264
  end
data/lib/caxlsx.rb CHANGED
@@ -1,2 +1,3 @@
1
- # encoding: UTF-8
2
- require 'axlsx.rb'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'axlsx'
metadata CHANGED
@@ -1,56 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caxlsx
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Randy Morgan
8
8
  - Jurriaan Pruis
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2022-10-21 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: nokogiri
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '1.10'
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.10.4
24
- type: :runtime
25
- prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- requirements:
28
- - - "~>"
29
- - !ruby/object:Gem::Version
30
- version: '1.10'
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.10.4
34
- - !ruby/object:Gem::Dependency
35
- name: rubyzip
36
- requirement: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 1.3.0
41
- - - "<"
42
- - !ruby/object:Gem::Version
43
- version: '3'
44
- type: :runtime
45
- prerelease: false
46
- version_requirements: !ruby/object:Gem::Requirement
47
- requirements:
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: 1.3.0
51
- - - "<"
52
- - !ruby/object:Gem::Version
53
- version: '3'
54
13
  - !ruby/object:Gem::Dependency
55
14
  name: htmlentities
56
15
  requirement: !ruby/object:Gem::Requirement
@@ -86,54 +45,54 @@ dependencies:
86
45
  - !ruby/object:Gem::Version
87
46
  version: '1.0'
88
47
  - !ruby/object:Gem::Dependency
89
- name: yard
48
+ name: nokogiri
90
49
  requirement: !ruby/object:Gem::Requirement
91
50
  requirements:
92
51
  - - "~>"
93
52
  - !ruby/object:Gem::Version
94
- version: 0.9.8
95
- type: :development
96
- prerelease: false
97
- version_requirements: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - "~>"
100
- - !ruby/object:Gem::Version
101
- version: 0.9.8
102
- - !ruby/object:Gem::Dependency
103
- name: kramdown
104
- requirement: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - "~>"
53
+ version: '1.10'
54
+ - - ">="
107
55
  - !ruby/object:Gem::Version
108
- version: '2.3'
109
- type: :development
56
+ version: 1.10.4
57
+ type: :runtime
110
58
  prerelease: false
111
59
  version_requirements: !ruby/object:Gem::Requirement
112
60
  requirements:
113
61
  - - "~>"
114
62
  - !ruby/object:Gem::Version
115
- version: '2.3'
63
+ version: '1.10'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 1.10.4
116
67
  - !ruby/object:Gem::Dependency
117
- name: timecop
68
+ name: rubyzip
118
69
  requirement: !ruby/object:Gem::Requirement
119
70
  requirements:
120
- - - "~>"
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '2.4'
74
+ - - "<"
121
75
  - !ruby/object:Gem::Version
122
- version: 0.9.0
123
- type: :development
76
+ version: '4'
77
+ type: :runtime
124
78
  prerelease: false
125
79
  version_requirements: !ruby/object:Gem::Requirement
126
80
  requirements:
127
- - - "~>"
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '2.4'
84
+ - - "<"
128
85
  - !ruby/object:Gem::Version
129
- version: 0.9.0
130
- description: " xlsx spreadsheet generation with charts, images, automated column
131
- width, customizable styles and full schema validation. Axlsx helps you create beautiful
132
- Office Open XML Spreadsheet documents ( Excel, Google Spreadsheets, Numbers, LibreOffice)
86
+ version: '4'
87
+ description: 'xlsx spreadsheet generation with charts, images, automated column width,
88
+ customizable styles and full schema validation. Axlsx helps you create beautiful
89
+ Office Open XML Spreadsheet documents (Excel, Google Spreadsheets, Numbers, LibreOffice)
133
90
  without having to understand the entire ECMA specification. Check out the README
134
91
  for some examples of how easy it is. Best of all, you can validate your xlsx file
135
92
  before serialization so you know for sure that anything generated is going to load
136
- on your client's machine.\n"
93
+ on your client''s machine.
94
+
95
+ '
137
96
  email: noel@peden.biz
138
97
  executables: []
139
98
  extensions: []
@@ -181,6 +140,7 @@ files:
181
140
  - lib/axlsx/drawing/pic.rb
182
141
  - lib/axlsx/drawing/picture_locking.rb
183
142
  - lib/axlsx/drawing/pie_3D_chart.rb
143
+ - lib/axlsx/drawing/pie_chart.rb
184
144
  - lib/axlsx/drawing/pie_series.rb
185
145
  - lib/axlsx/drawing/scaling.rb
186
146
  - lib/axlsx/drawing/scatter_chart.rb
@@ -216,14 +176,17 @@ files:
216
176
  - lib/axlsx/stylesheet/table_style.rb
217
177
  - lib/axlsx/stylesheet/table_style_element.rb
218
178
  - lib/axlsx/stylesheet/table_styles.rb
179
+ - lib/axlsx/stylesheet/theme.rb
219
180
  - lib/axlsx/stylesheet/xf.rb
220
181
  - lib/axlsx/util/accessors.rb
182
+ - lib/axlsx/util/buffered_zip_output_stream.rb
221
183
  - lib/axlsx/util/constants.rb
222
184
  - lib/axlsx/util/mime_type_utils.rb
223
185
  - lib/axlsx/util/options_parser.rb
224
186
  - lib/axlsx/util/serialized_attributes.rb
225
187
  - lib/axlsx/util/simple_typed_list.rb
226
188
  - lib/axlsx/util/storage.rb
189
+ - lib/axlsx/util/uri_utils.rb
227
190
  - lib/axlsx/util/validators.rb
228
191
  - lib/axlsx/util/zip_command.rb
229
192
  - lib/axlsx/version.rb
@@ -236,6 +199,8 @@ files:
236
199
  - lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb
237
200
  - lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb
238
201
  - lib/axlsx/workbook/worksheet/auto_filter/filters.rb
202
+ - lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb
203
+ - lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb
239
204
  - lib/axlsx/workbook/worksheet/border_creator.rb
240
205
  - lib/axlsx/workbook/worksheet/break.rb
241
206
  - lib/axlsx/workbook/worksheet/cell.rb
@@ -328,8 +293,11 @@ files:
328
293
  homepage: https://github.com/caxlsx/caxlsx
329
294
  licenses:
330
295
  - MIT
331
- metadata: {}
332
- post_install_message:
296
+ metadata:
297
+ bug_tracker_uri: https://github.com/caxlsx/caxlsx/issues
298
+ changelog_uri: https://github.com/caxlsx/caxlsx/blob/master/CHANGELOG.md
299
+ source_code_uri: https://github.com/caxlsx/caxlsx
300
+ rubygems_mfa_required: 'true'
333
301
  rdoc_options: []
334
302
  require_paths:
335
303
  - lib
@@ -337,15 +305,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
337
305
  requirements:
338
306
  - - ">="
339
307
  - !ruby/object:Gem::Version
340
- version: '2.3'
308
+ version: '2.6'
341
309
  required_rubygems_version: !ruby/object:Gem::Requirement
342
310
  requirements:
343
311
  - - ">="
344
312
  - !ruby/object:Gem::Version
345
313
  version: '0'
346
314
  requirements: []
347
- rubygems_version: 3.0.9
348
- signing_key:
315
+ rubygems_version: 4.0.10
349
316
  specification_version: 4
350
317
  summary: Excel OOXML (xlsx) with charts, styles, images and autowidth columns.
351
318
  test_files: []