caxlsx 4.4.1 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcbb7e84632bd4649224e5d86f862f8f72a4782213f26a93b8b526e6fd303c23
4
- data.tar.gz: bba54de54404af1abad6be6a853a69d8702222dbe1e7f7abfffdd397ade6afeb
3
+ metadata.gz: 4788f1b6fd206e4e4727a10114249a6ddd0eb8e3d3eed2d1f74e43e6c415b1fc
4
+ data.tar.gz: c8883c5e7ed0f029cb3b09f3741f724bb2ebe823c6084524e9ba72468f6291ef
5
5
  SHA512:
6
- metadata.gz: b1d3e462d9cc08999723034b1b75553f2e05da0a98c802adf6a90378761d8b2bbe4eb25d2092452678a359bcc5b67aa54d3b3638c368a82d2b6a1b898bd2310d
7
- data.tar.gz: ac43a99324114c37ba093a19212685f206f844d8991d4d0da48e9421d0efedcb00ef1799e74bafc66be400c32fd9bd5684ae8b6a9694b9fad81bdb60bfd51be9
6
+ metadata.gz: d8c5703e775090e2b1a9fec353f67e713d83ac21d6bfe980d45fc876b5506ca849ee37d8e6588b759c7434c66d444f15f90c9da6e4026042a43fc7a5910de831
7
+ data.tar.gz: 79e6e3341fdff59db93bc8534d77edaf2817305ab3053d0daaa66a2b3a8323f60ef07a8b49a6301d2985dc818795233c7879500f45b61b2296a454adb7df9e47
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@ CHANGELOG
2
2
  ---------
3
3
  - **Unreleased**
4
4
 
5
+ - **June.09.26**: 4.5.0
6
+ - [PR #527](https://github.com/caxlsx/caxlsx/pull/527) Fix PivotTable countNums subtotal label never applied. Solves [Issue #526](https://github.com/caxlsx/caxlsx/issues/526)
7
+ - [PR #522](https://github.com/caxlsx/caxlsx/pull/522) Allow custom name for pivot table data fields via :name option
8
+ - [PR #520](https://github.com/caxlsx/caxlsx/pull/520) Add `use_auto_formatting` and `apply_width_height_formats` accessors to `PivotTable`
9
+ - [PR #517](https://github.com/caxlsx/caxlsx/pull/517) Fix invalid XML when pivot table has both `columns` and multiple `data` fields configured. Solves [Issue #414](https://github.com/caxlsx/caxlsx/issues/414)
10
+
11
+ - **March.23.26**: 4.4.2
12
+ - [PR #510](https://github.com/caxlsx/caxlsx/pull/510) Add configurable `major_tick_mark` and `minor_tick_mark` attributes to chart axes
13
+ - [PR #495](https://github.com/caxlsx/caxlsx/pull/495) Make worksheet name length validation optional
14
+ - [PR #496](https://github.com/caxlsx/caxlsx/pull/496) Fix FrozenError when passing in a frozen hash to add_style
15
+ - [PR #500](https://github.com/caxlsx/caxlsx/pull/500) Full Ruby 4.0 compatibility
16
+ - [PR #504](https://github.com/caxlsx/caxlsx/pull/504) Support automatic tick label intervals on chart axes
17
+ - [PR #508](https://github.com/caxlsx/caxlsx/pull/508) Auto-insert missing rows or columns to make autofilter works when using not yet existing ranges
18
+ - [PR #512](https://github.com/caxlsx/caxlsx/pull/512) Freeze valid tick mark values constant
19
+
5
20
  - **December.03.25**: 4.4.1
6
21
  - [PR #482](https://github.com/caxlsx/caxlsx/pull/482) Suppress Zip64 when it't not necessary
7
22
 
@@ -19,6 +19,8 @@ module Axlsx
19
19
  @title = @color = nil
20
20
  self.ax_pos = :b
21
21
  self.tick_lbl_pos = :nextTo
22
+ self.major_tick_mark = :cross
23
+ self.minor_tick_mark = :none
22
24
  self.format_code = "General"
23
25
  self.crosses = :autoZero
24
26
  self.gridlines = true
@@ -57,6 +59,18 @@ module Axlsx
57
59
  attr_reader :tick_lbl_pos
58
60
  alias :tickLblPos :tick_lbl_pos
59
61
 
62
+ # the type of major tick mark
63
+ # must be one of [:cross, :in, :none, :out]
64
+ # @return [Symbol]
65
+ attr_reader :major_tick_mark
66
+ alias :majorTickMark :major_tick_mark
67
+
68
+ # the type of minor tick mark
69
+ # must be one of [:cross, :in, :none, :out]
70
+ # @return [Symbol]
71
+ attr_reader :minor_tick_mark
72
+ alias :minorTickMark :minor_tick_mark
73
+
60
74
  # The number format format code for this axis
61
75
  # default :General
62
76
  # @return [String]
@@ -113,6 +127,24 @@ module Axlsx
113
127
  end
114
128
  alias :tickLblPos= :tick_lbl_pos=
115
129
 
130
+ VALID_TICK_MARK_VALUES = [:cross, :in, :none, :out].freeze
131
+
132
+ # the type of major tick mark
133
+ # must be one of [:cross, :in, :none, :out]
134
+ def major_tick_mark=(v)
135
+ RestrictionValidator.validate "#{self.class}.major_tick_mark", VALID_TICK_MARK_VALUES, v
136
+ @major_tick_mark = v
137
+ end
138
+ alias :majorTickMark= :major_tick_mark=
139
+
140
+ # the type of minor tick mark
141
+ # must be one of [:cross, :in, :none, :out]
142
+ def minor_tick_mark=(v)
143
+ RestrictionValidator.validate "#{self.class}.minor_tick_mark", VALID_TICK_MARK_VALUES, v
144
+ @minor_tick_mark = v
145
+ end
146
+ alias :minorTickMark= :minor_tick_mark=
147
+
116
148
  # The number format format code for this axis
117
149
  # default :General
118
150
  def format_code=(v)
@@ -186,8 +218,8 @@ module Axlsx
186
218
  # otherwise it will never take, as it will always prefer the 'General' formatting
187
219
  # of the cells themselves
188
220
  str << '<c:numFmt formatCode="' << @format_code << '" sourceLinked="' << (@format_code.eql?('General') ? '1' : '0') << '"/>'
189
- str << '<c:majorTickMark val="none"/>'
190
- str << '<c:minorTickMark val="none"/>'
221
+ str << '<c:majorTickMark val="' << @major_tick_mark.to_s << '"/>'
222
+ str << '<c:minorTickMark val="' << @minor_tick_mark.to_s << '"/>'
191
223
  str << '<c:tickLblPos val="' << @tick_lbl_pos.to_s << '"/>'
192
224
  # TODO: this is also being used for series colors
193
225
  # time to extract this into a class spPr - Shape Properties
@@ -4,11 +4,9 @@ module Axlsx
4
4
  # A CatAxis object defines a chart category axis
5
5
  class CatAxis < Axis
6
6
  # Creates a new CatAxis object
7
- # @option options [Integer] tick_lbl_skip
8
- # @option options [Integer] tick_mark_skip
7
+ # @option options [Integer, nil] tick_lbl_skip
8
+ # @option options [Integer, nil] tick_mark_skip
9
9
  def initialize(options = {})
10
- @tick_lbl_skip = 1
11
- @tick_mark_skip = 1
12
10
  self.auto = 1
13
11
  self.lbl_algn = :ctr
14
12
  self.lbl_offset = "100"
@@ -32,12 +30,12 @@ module Axlsx
32
30
  alias :lblOffset :lbl_offset
33
31
 
34
32
  # The number of tick labels to skip between labels
35
- # @return [Integer]
33
+ # @return [Integer, nil]
36
34
  attr_reader :tick_lbl_skip
37
35
  alias :tickLblSkip :tick_lbl_skip
38
36
 
39
37
  # The number of tickmarks to be skipped before the next one is rendered.
40
- # @return [Boolean]
38
+ # @return [Integer, nil]
41
39
  attr_reader :tick_mark_skip
42
40
  alias :tickMarkSkip :tick_mark_skip
43
41
 
@@ -46,14 +44,14 @@ module Axlsx
46
44
 
47
45
  # @see tick_lbl_skip
48
46
  def tick_lbl_skip=(v)
49
- Axlsx.validate_unsigned_int(v)
47
+ Axlsx.validate_unsigned_int(v) unless v.nil?
50
48
  @tick_lbl_skip = v
51
49
  end
52
50
  alias :tickLblSkip= :tick_lbl_skip=
53
51
 
54
52
  # @see tick_mark_skip
55
53
  def tick_mark_skip=(v)
56
- Axlsx.validate_unsigned_int(v)
54
+ Axlsx.validate_unsigned_int(v) unless v.nil?
57
55
  @tick_mark_skip = v
58
56
  end
59
57
  alias :tickMarkSkip= :tick_mark_skip=
@@ -89,8 +87,8 @@ module Axlsx
89
87
  str << '<c:auto val="' << @auto.to_s << '"/>'
90
88
  str << '<c:lblAlgn val="' << @lbl_algn.to_s << '"/>'
91
89
  str << '<c:lblOffset val="' << @lbl_offset.to_i.to_s << '"/>'
92
- str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>'
93
- str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>'
90
+ str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>' unless @tick_lbl_skip.nil?
91
+ str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>' unless @tick_mark_skip.nil?
94
92
  str << '</c:catAx>'
95
93
  end
96
94
  end
@@ -1,56 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
4
- require_relative 'd_lbls'
5
- require_relative 'title'
6
- require_relative 'series_title'
7
- require_relative 'series'
8
- require_relative 'pie_series'
9
- require_relative 'bar_series'
10
- require_relative 'line_series'
11
- require_relative 'scatter_series'
12
- require_relative 'bubble_series'
13
- require_relative 'area_series'
14
-
15
- require_relative 'scaling'
16
- require_relative 'axis'
17
-
18
- require_relative 'str_val'
19
- require_relative 'num_val'
20
- require_relative 'str_data'
21
- require_relative 'num_data'
22
- require_relative 'num_data_source'
23
- require_relative 'ax_data_source'
24
-
25
- require_relative 'ser_axis'
26
- require_relative 'cat_axis'
27
- require_relative 'val_axis'
28
- require_relative 'axes'
29
-
30
- require_relative 'marker'
31
-
32
- require_relative 'one_cell_anchor'
33
- require_relative 'two_cell_anchor'
34
- require_relative 'graphic_frame'
35
-
36
- require_relative 'view_3D'
37
- require_relative 'chart'
38
- require_relative 'pie_3D_chart'
39
- require_relative 'pie_chart'
40
- require_relative 'bar_3D_chart'
41
- require_relative 'bar_chart'
42
- require_relative 'line_chart'
43
- require_relative 'line_3D_chart'
44
- require_relative 'scatter_chart'
45
- require_relative 'bubble_chart'
46
- require_relative 'area_chart'
47
-
48
- require_relative 'picture_locking'
49
- require_relative 'pic'
50
- require_relative 'hyperlink'
51
-
52
- require_relative 'vml_drawing'
53
- require_relative 'vml_shape'
4
+ autoload :DLbls, 'axlsx/drawing/d_lbls'
5
+ autoload :Title, 'axlsx/drawing/title'
6
+ autoload :SeriesTitle, 'axlsx/drawing/series_title'
7
+ autoload :Series, 'axlsx/drawing/series'
8
+ autoload :PieSeries, 'axlsx/drawing/pie_series'
9
+ autoload :BarSeries, 'axlsx/drawing/bar_series'
10
+ autoload :LineSeries, 'axlsx/drawing/line_series'
11
+ autoload :ScatterSeries, 'axlsx/drawing/scatter_series'
12
+ autoload :BubbleSeries, 'axlsx/drawing/bubble_series'
13
+ autoload :AreaSeries, 'axlsx/drawing/area_series'
14
+
15
+ autoload :Scaling, 'axlsx/drawing/scaling'
16
+ autoload :Axis, 'axlsx/drawing/axis'
17
+
18
+ autoload :StrVal, 'axlsx/drawing/str_val'
19
+ autoload :NumVal, 'axlsx/drawing/num_val'
20
+ autoload :StrData, 'axlsx/drawing/str_data'
21
+ autoload :NumData, 'axlsx/drawing/num_data'
22
+ autoload :NumDataSource, 'axlsx/drawing/num_data_source'
23
+ autoload :AxDataSource, 'axlsx/drawing/ax_data_source'
24
+
25
+ autoload :SerAxis, 'axlsx/drawing/ser_axis'
26
+ autoload :CatAxis, 'axlsx/drawing/cat_axis'
27
+ autoload :ValAxis, 'axlsx/drawing/val_axis'
28
+ autoload :Axes, 'axlsx/drawing/axes'
29
+
30
+ autoload :Marker, 'axlsx/drawing/marker'
31
+
32
+ autoload :OneCellAnchor, 'axlsx/drawing/one_cell_anchor'
33
+ autoload :TwoCellAnchor, 'axlsx/drawing/two_cell_anchor'
34
+ autoload :GraphicFrame, 'axlsx/drawing/graphic_frame'
35
+
36
+ autoload :View3D, 'axlsx/drawing/view_3D'
37
+ autoload :Chart, 'axlsx/drawing/chart'
38
+ autoload :Pie3DChart, 'axlsx/drawing/pie_3D_chart'
39
+ autoload :PieChart, 'axlsx/drawing/pie_chart'
40
+ autoload :Bar3DChart, 'axlsx/drawing/bar_3D_chart'
41
+ autoload :BarChart, 'axlsx/drawing/bar_chart'
42
+ autoload :LineChart, 'axlsx/drawing/line_chart'
43
+ autoload :Line3DChart, 'axlsx/drawing/line_3D_chart'
44
+ autoload :ScatterChart, 'axlsx/drawing/scatter_chart'
45
+ autoload :BubbleChart, 'axlsx/drawing/bubble_chart'
46
+ autoload :AreaChart, 'axlsx/drawing/area_chart'
47
+
48
+ autoload :PictureLocking, 'axlsx/drawing/picture_locking'
49
+ autoload :Pic, 'axlsx/drawing/pic'
50
+ autoload :Hyperlink, 'axlsx/drawing/hyperlink'
51
+
52
+ autoload :VmlDrawing, 'axlsx/drawing/vml_drawing'
53
+ autoload :VmlShape, 'axlsx/drawing/vml_shape'
54
54
 
55
55
  # A Drawing is a canvas for charts and images. Each worksheet has a single drawing that manages anchors.
56
56
  # The anchors reference the charts or images via graphical frames. This is not a trivial relationship so please do follow the advice in the note.
@@ -4,33 +4,32 @@ module Axlsx
4
4
  # A SerAxis object defines a series axis
5
5
  class SerAxis < Axis
6
6
  # The number of tick labels to skip between labels
7
- # @return [Integer]
7
+ # @return [Integer, nil]
8
8
  attr_reader :tick_lbl_skip
9
9
  alias :tickLblSkip :tick_lbl_skip
10
10
 
11
11
  # The number of tickmarks to be skipped before the next one is rendered.
12
- # @return [Boolean]
12
+ # @return [Integer, nil]
13
13
  attr_reader :tick_mark_skip
14
14
  alias :tickMarkSkip :tick_mark_skip
15
15
 
16
16
  # Creates a new SerAxis object
17
- # @option options [Integer] tick_lbl_skip
18
- # @option options [Integer] tick_mark_skip
17
+ # @option options [Integer, nil] tick_lbl_skip
18
+ # @option options [Integer, nil] tick_mark_skip
19
19
  def initialize(options = {})
20
- @tick_lbl_skip, @tick_mark_skip = 1, 1
21
20
  super
22
21
  end
23
22
 
24
23
  # @see tickLblSkip
25
24
  def tick_lbl_skip=(v)
26
- Axlsx.validate_unsigned_int(v)
25
+ Axlsx.validate_unsigned_int(v) unless v.nil?
27
26
  @tick_lbl_skip = v
28
27
  end
29
28
  alias :tickLblSkip= :tick_lbl_skip=
30
29
 
31
30
  # @see tickMarkSkip
32
31
  def tick_mark_skip=(v)
33
- Axlsx.validate_unsigned_int(v)
32
+ Axlsx.validate_unsigned_int(v) unless v.nil?
34
33
  @tick_mark_skip = v
35
34
  end
36
35
  alias :tickMarkSkip= :tick_mark_skip=
@@ -1,24 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
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 'theme'
19
- require_relative 'dxf'
20
- require_relative 'xf'
21
- require_relative 'cell_protection'
4
+ autoload :Border, 'axlsx/stylesheet/border'
5
+ autoload :BorderPr, 'axlsx/stylesheet/border_pr'
6
+ autoload :CellAlignment, 'axlsx/stylesheet/cell_alignment'
7
+ autoload :CellStyle, 'axlsx/stylesheet/cell_style'
8
+ autoload :Color, 'axlsx/stylesheet/color'
9
+ autoload :Fill, 'axlsx/stylesheet/fill'
10
+ autoload :Font, 'axlsx/stylesheet/font'
11
+ autoload :GradientFill, 'axlsx/stylesheet/gradient_fill'
12
+ autoload :GradientStop, 'axlsx/stylesheet/gradient_stop'
13
+ autoload :NumFmt, 'axlsx/stylesheet/num_fmt'
14
+ autoload :PatternFill, 'axlsx/stylesheet/pattern_fill'
15
+ autoload :TableStyle, 'axlsx/stylesheet/table_style'
16
+ autoload :TableStyles, 'axlsx/stylesheet/table_styles'
17
+ autoload :TableStyleElement, 'axlsx/stylesheet/table_style_element'
18
+ autoload :Theme, 'axlsx/stylesheet/theme'
19
+ autoload :Dxf, 'axlsx/stylesheet/dxf'
20
+ autoload :Xf, 'axlsx/stylesheet/xf'
21
+ autoload :CellProtection, 'axlsx/stylesheet/cell_protection'
22
22
 
23
23
  # The Styles class manages worksheet styles
24
24
  # 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.
@@ -228,6 +228,8 @@ module Axlsx
228
228
  # An index for cell styles where keys are styles codes as per Axlsx::Style and values are Cell#raw_style
229
229
  # The reason for the backward key/value ordering is that style lookup must be most efficient, while `add_style` can be less efficient
230
230
  def add_style(options = {})
231
+ options = options.dup
232
+
231
233
  # Default to :xf
232
234
  options[:type] ||= :xf
233
235
 
data/lib/axlsx/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Axlsx
4
4
  # The current version
5
- VERSION = "4.4.1"
5
+ VERSION = "4.5.0"
6
6
  end
@@ -1,64 +1,69 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
4
- require_relative 'worksheet/sheet_calc_pr'
5
- require_relative 'worksheet/auto_filter/auto_filter'
6
- require_relative 'worksheet/date_time_converter'
7
- require_relative 'worksheet/protected_range'
8
- require_relative 'worksheet/protected_ranges'
9
- require_relative 'worksheet/rich_text_run'
10
- require_relative 'worksheet/rich_text'
11
- require_relative 'worksheet/cell_serializer'
12
- require_relative 'worksheet/cell'
13
- require_relative 'worksheet/page_margins'
14
- require_relative 'worksheet/page_set_up_pr'
15
- require_relative 'worksheet/outline_pr'
16
- require_relative 'worksheet/page_setup'
17
- require_relative 'worksheet/header_footer'
18
- require_relative 'worksheet/print_options'
19
- require_relative 'worksheet/cfvo'
20
- require_relative 'worksheet/cfvos'
21
- require_relative 'worksheet/color_scale'
22
- require_relative 'worksheet/data_bar'
23
- require_relative 'worksheet/icon_set'
24
- require_relative 'worksheet/conditional_formatting'
25
- require_relative 'worksheet/conditional_formatting_rule'
26
- require_relative 'worksheet/conditional_formattings'
27
- require_relative 'worksheet/row'
28
- require_relative 'worksheet/col'
29
- require_relative 'worksheet/cols'
30
- require_relative 'worksheet/comments'
31
- require_relative 'worksheet/comment'
32
- require_relative 'worksheet/merged_cells'
33
- require_relative 'worksheet/sheet_protection'
34
- require_relative 'worksheet/sheet_pr'
35
- require_relative 'worksheet/dimension'
36
- require_relative 'worksheet/sheet_data'
37
- require_relative 'worksheet/worksheet_drawing'
38
- require_relative 'worksheet/worksheet_comments'
39
- require_relative 'worksheet/worksheet_hyperlink'
40
- require_relative 'worksheet/worksheet_hyperlinks'
41
- require_relative 'worksheet/break'
42
- require_relative 'worksheet/row_breaks'
43
- require_relative 'worksheet/col_breaks'
44
- require_relative 'workbook_view'
45
- require_relative 'workbook_views'
46
- require_relative 'worksheet/worksheet'
47
- require_relative 'shared_strings_table'
48
- require_relative 'defined_name'
49
- require_relative 'defined_names'
50
- require_relative 'worksheet/table_style_info'
51
- require_relative 'worksheet/table'
52
- require_relative 'worksheet/tables'
53
- require_relative 'worksheet/pivot_table_cache_definition'
54
- require_relative 'worksheet/pivot_table'
55
- require_relative 'worksheet/pivot_tables'
56
- require_relative 'worksheet/data_validation'
57
- require_relative 'worksheet/data_validations'
58
- require_relative 'worksheet/sheet_view'
59
- require_relative 'worksheet/sheet_format_pr'
60
- require_relative 'worksheet/pane'
61
- require_relative 'worksheet/selection'
4
+ autoload :SheetCalcPr, 'axlsx/workbook/worksheet/sheet_calc_pr'
5
+ autoload :AutoFilter, 'axlsx/workbook/worksheet/auto_filter/auto_filter'
6
+ autoload :FilterColumn, 'axlsx/workbook/worksheet/auto_filter/filter_column'
7
+ autoload :Filters, 'axlsx/workbook/worksheet/auto_filter/filters'
8
+ autoload :SortState, 'axlsx/workbook/worksheet/auto_filter/sort_state'
9
+ autoload :SortCondition, 'axlsx/workbook/worksheet/auto_filter/sort_condition'
10
+ autoload :DateTimeConverter, 'axlsx/workbook/worksheet/date_time_converter'
11
+ autoload :ProtectedRange, 'axlsx/workbook/worksheet/protected_range'
12
+ autoload :ProtectedRanges, 'axlsx/workbook/worksheet/protected_ranges'
13
+ autoload :RichTextRun, 'axlsx/workbook/worksheet/rich_text_run'
14
+ autoload :RichText, 'axlsx/workbook/worksheet/rich_text'
15
+ autoload :CellSerializer, 'axlsx/workbook/worksheet/cell_serializer'
16
+ autoload :Cell, 'axlsx/workbook/worksheet/cell'
17
+ autoload :PageMargins, 'axlsx/workbook/worksheet/page_margins'
18
+ autoload :PageSetUpPr, 'axlsx/workbook/worksheet/page_set_up_pr'
19
+ autoload :OutlinePr, 'axlsx/workbook/worksheet/outline_pr'
20
+ autoload :PageSetup, 'axlsx/workbook/worksheet/page_setup'
21
+ autoload :HeaderFooter, 'axlsx/workbook/worksheet/header_footer'
22
+ autoload :PrintOptions, 'axlsx/workbook/worksheet/print_options'
23
+ autoload :Cfvo, 'axlsx/workbook/worksheet/cfvo'
24
+ autoload :Cfvos, 'axlsx/workbook/worksheet/cfvos'
25
+ autoload :ColorScale, 'axlsx/workbook/worksheet/color_scale'
26
+ autoload :DataBar, 'axlsx/workbook/worksheet/data_bar'
27
+ autoload :IconSet, 'axlsx/workbook/worksheet/icon_set'
28
+ autoload :ConditionalFormatting, 'axlsx/workbook/worksheet/conditional_formatting'
29
+ autoload :ConditionalFormattingRule, 'axlsx/workbook/worksheet/conditional_formatting_rule'
30
+ autoload :ConditionalFormattings, 'axlsx/workbook/worksheet/conditional_formattings'
31
+ autoload :Row, 'axlsx/workbook/worksheet/row'
32
+ autoload :Col, 'axlsx/workbook/worksheet/col'
33
+ autoload :Cols, 'axlsx/workbook/worksheet/cols'
34
+ autoload :Comments, 'axlsx/workbook/worksheet/comments'
35
+ autoload :Comment, 'axlsx/workbook/worksheet/comment'
36
+ autoload :MergedCells, 'axlsx/workbook/worksheet/merged_cells'
37
+ autoload :SheetProtection, 'axlsx/workbook/worksheet/sheet_protection'
38
+ autoload :SheetPr, 'axlsx/workbook/worksheet/sheet_pr'
39
+ autoload :Dimension, 'axlsx/workbook/worksheet/dimension'
40
+ autoload :SheetData, 'axlsx/workbook/worksheet/sheet_data'
41
+ autoload :WorksheetDrawing, 'axlsx/workbook/worksheet/worksheet_drawing'
42
+ autoload :WorksheetComments, 'axlsx/workbook/worksheet/worksheet_comments'
43
+ autoload :WorksheetHyperlink, 'axlsx/workbook/worksheet/worksheet_hyperlink'
44
+ autoload :WorksheetHyperlinks, 'axlsx/workbook/worksheet/worksheet_hyperlinks'
45
+ autoload :Break, 'axlsx/workbook/worksheet/break'
46
+ autoload :RowBreaks, 'axlsx/workbook/worksheet/row_breaks'
47
+ autoload :ColBreaks, 'axlsx/workbook/worksheet/col_breaks'
48
+ autoload :WorkbookView, 'axlsx/workbook/workbook_view'
49
+ autoload :WorkbookViews, 'axlsx/workbook/workbook_views'
50
+ autoload :Worksheet, 'axlsx/workbook/worksheet/worksheet'
51
+ autoload :BorderCreator, 'axlsx/workbook/worksheet/border_creator'
52
+ autoload :SharedStringsTable, 'axlsx/workbook/shared_strings_table'
53
+ autoload :DefinedName, 'axlsx/workbook/defined_name'
54
+ autoload :DefinedNames, 'axlsx/workbook/defined_names'
55
+ autoload :TableStyleInfo, 'axlsx/workbook/worksheet/table_style_info'
56
+ autoload :Table, 'axlsx/workbook/worksheet/table'
57
+ autoload :Tables, 'axlsx/workbook/worksheet/tables'
58
+ autoload :PivotTableCacheDefinition, 'axlsx/workbook/worksheet/pivot_table_cache_definition'
59
+ autoload :PivotTable, 'axlsx/workbook/worksheet/pivot_table'
60
+ autoload :PivotTables, 'axlsx/workbook/worksheet/pivot_tables'
61
+ autoload :DataValidation, 'axlsx/workbook/worksheet/data_validation'
62
+ autoload :DataValidations, 'axlsx/workbook/worksheet/data_validations'
63
+ autoload :SheetView, 'axlsx/workbook/worksheet/sheet_view'
64
+ autoload :SheetFormatPr, 'axlsx/workbook/worksheet/sheet_format_pr'
65
+ autoload :Pane, 'axlsx/workbook/worksheet/pane'
66
+ autoload :Selection, 'axlsx/workbook/worksheet/selection'
62
67
 
63
68
  # The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles.
64
69
  # The following parts of the Office Open XML spreadsheet specification are not implemented in this version.
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'filter_column'
4
- require_relative 'filters'
5
- require_relative 'sort_state'
6
-
7
3
  module Axlsx
8
4
  # This class represents an auto filter range in a worksheet
9
5
  class AutoFilter
@@ -30,7 +26,25 @@ module Axlsx
30
26
  def defined_name
31
27
  return unless range
32
28
 
33
- Axlsx.cell_range(range.split(':').collect { |name| worksheet.name_to_cell(name) })
29
+ cells = range.split(':').collect do |name|
30
+ cell = worksheet.name_to_cell(name)
31
+ next cell if cell
32
+
33
+ # We're calculating the defined_name for the AutoFilter just before serializing,
34
+ # so in theory adding new rows or columns should not cause weird offset issues
35
+ col_index, row_index = *Axlsx.name_to_indices(name)
36
+ while (row = worksheet.rows[row_index]).nil?
37
+ worksheet.add_row
38
+ end
39
+
40
+ while (cell = row[col_index]).nil?
41
+ row.add_cell
42
+ end
43
+
44
+ cell
45
+ end
46
+
47
+ Axlsx.cell_range(cells)
34
48
  end
35
49
 
36
50
  # A collection of filterColumns for this auto_filter
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'sort_condition'
4
-
5
3
  module Axlsx
6
4
  # This class performs sorting on a range in a worksheet
7
5
  class SortState
@@ -29,6 +29,8 @@ module Axlsx
29
29
  @grand_totals = :both
30
30
  @sort_on_headers = {}
31
31
  @style_info = {}
32
+ @use_auto_formatting = true
33
+ @apply_width_height_formats = true
32
34
  parse_options options
33
35
  yield self if block_given?
34
36
  end
@@ -85,6 +87,14 @@ module Axlsx
85
87
  # @return [Worksheet]
86
88
  attr_writer :data_sheet
87
89
 
90
+ # Whether to apply auto formatting to the pivot table.
91
+ # @return [Boolean]
92
+ attr_accessor :use_auto_formatting
93
+
94
+ # Whether to apply width/height formats to the pivot table.
95
+ # @return [Boolean]
96
+ attr_accessor :apply_width_height_formats
97
+
88
98
  # @see #data_sheet
89
99
  def data_sheet
90
100
  @data_sheet || @sheet
@@ -207,7 +217,11 @@ module Axlsx
207
217
  str << ' dataOnRows="1"' if data.size <= 1
208
218
  str << ' rowGrandTotals="0"' if grand_totals == :col_only || grand_totals == :none
209
219
  str << ' colGrandTotals="0"' if grand_totals == :row_only || grand_totals == :none
210
- str << ' applyNumberFormats="0" applyBorderFormats="0" applyFontFormats="0" applyPatternFormats="0" applyAlignmentFormats="0" applyWidthHeightFormats="1" dataCaption="Data" showMultipleLabel="0" showMemberPropertyTips="0" useAutoFormatting="1" indent="0" compact="0" compactData="0" gridDropZones="1" multipleFieldFilters="0">'
220
+ str << ' applyNumberFormats="0" applyBorderFormats="0" applyFontFormats="0" applyPatternFormats="0" applyAlignmentFormats="0"'
221
+ str << ' applyWidthHeightFormats="' << (@apply_width_height_formats ? '1' : '0') << '"'
222
+ str << ' dataCaption="Data" showMultipleLabel="0" showMemberPropertyTips="0"'
223
+ str << ' useAutoFormatting="' << (@use_auto_formatting ? '1' : '0') << '"'
224
+ str << ' indent="0" compact="0" compactData="0" gridDropZones="1" multipleFieldFilters="0">'
211
225
 
212
226
  str << '<location firstDataCol="1" firstDataRow="1" firstHeaderRow="1" ref="' << ref << '"/>'
213
227
  str << '<pivotFields count="' << header_cells_count.to_s << '">'
@@ -246,6 +260,18 @@ module Axlsx
246
260
  else
247
261
  str << '<colItems count="1"><i/></colItems>'
248
262
  end
263
+ elsif data.size > 1
264
+ str << '<colFields count="' << (columns.size + 1).to_s << '">'
265
+ columns.each do |column_value|
266
+ str << '<field x="' << header_index_of(column_value).to_s << '"/>'
267
+ end
268
+ str << '<field x="-2"/></colFields>'
269
+ str << "<colItems count=\"#{data.size}\">"
270
+ str << '<i><x/></i>'
271
+ (data.size - 1).times do |i|
272
+ str << "<i i=\"#{i + 1}\"><x v=\"#{i + 1}\"/></i>"
273
+ end
274
+ str << '</colItems>'
249
275
  else
250
276
  str << '<colFields count="' << columns.size.to_s << '">'
251
277
  columns.each do |column_value|
@@ -264,8 +290,9 @@ module Axlsx
264
290
  str << "<dataFields count=\"#{data.size}\">"
265
291
  data.each do |datum_value|
266
292
  subtotal_name = datum_value[:subtotal] || 'sum'
267
- subtotal_name = 'count' if name == 'countNums' # both count & countNums are labelled as count
268
- str << "<dataField name='#{subtotal_name.capitalize} of #{datum_value[:ref]}' fld='#{header_index_of(datum_value[:ref])}' baseField='0' baseItem='0'"
293
+ subtotal_name = 'count' if datum_value[:subtotal] == 'countNums' # both count & countNums are labelled as count
294
+ field_name = datum_value[:name] || "#{subtotal_name.capitalize} of #{datum_value[:ref]}"
295
+ str << "<dataField name='#{field_name}' fld='#{header_index_of(datum_value[:ref])}' baseField='0' baseItem='0'"
269
296
  str << " numFmtId='#{datum_value[:num_fmt]}'" if datum_value[:num_fmt]
270
297
  str << " subtotal='#{datum_value[:subtotal]}' " if datum_value[:subtotal]
271
298
  str << "/>"
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "border_creator"
4
-
5
3
  module Axlsx
6
4
  # The Worksheet class represents a worksheet in the workbook.
7
5
  class Worksheet
@@ -768,7 +766,7 @@ module Axlsx
768
766
  raise ArgumentError, ERR_SHEET_NAME_EMPTY if name.empty?
769
767
 
770
768
  character_length = name.encode("utf-16")[1..-1].encode("utf-16").bytesize / 2
771
- raise ArgumentError, format(ERR_SHEET_NAME_TOO_LONG, name) if character_length > WORKSHEET_MAX_NAME_LENGTH
769
+ raise ArgumentError, format(ERR_SHEET_NAME_TOO_LONG, name) if character_length > WORKSHEET_MAX_NAME_LENGTH && Axlsx.validate_sheet_name_length
772
770
  raise ArgumentError, format(ERR_SHEET_NAME_CHARACTER_FORBIDDEN, name) if WORKSHEET_NAME_FORBIDDEN_CHARS.any? { |char| name.include? char }
773
771
 
774
772
  name = Axlsx.coder.encode(name)
data/lib/axlsx.rb CHANGED
@@ -9,7 +9,7 @@ require 'nokogiri'
9
9
  require 'zip'
10
10
 
11
11
  # Ruby core dependencies
12
- require 'cgi'
12
+ require 'cgi/escape'
13
13
  require 'set'
14
14
  require 'time'
15
15
  require 'uri'
@@ -231,6 +231,22 @@ module Axlsx
231
231
  @escape_formulas = value
232
232
  end
233
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
+
234
250
  # Returns a URI parser instance, preferring RFC2396_PARSER if available,
235
251
  # otherwise falling back to DEFAULT_PARSER. This method ensures consistent
236
252
  # URI parsing across different Ruby versions.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caxlsx
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Randy Morgan
@@ -312,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
312
312
  - !ruby/object:Gem::Version
313
313
  version: '0'
314
314
  requirements: []
315
- rubygems_version: 3.6.9
315
+ rubygems_version: 4.0.10
316
316
  specification_version: 4
317
317
  summary: Excel OOXML (xlsx) with charts, styles, images and autowidth columns.
318
318
  test_files: []