caxlsx 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -12
- data/README.md +1 -1
- data/lib/axlsx/content_type/abstract_content_type.rb +2 -2
- data/lib/axlsx/content_type/content_type.rb +3 -3
- data/lib/axlsx/drawing/area_chart.rb +3 -3
- data/lib/axlsx/drawing/area_series.rb +2 -2
- data/lib/axlsx/drawing/ax_data_source.rb +1 -1
- data/lib/axlsx/drawing/axes.rb +1 -1
- data/lib/axlsx/drawing/axis.rb +1 -1
- data/lib/axlsx/drawing/bar_3D_chart.rb +3 -3
- data/lib/axlsx/drawing/bar_chart.rb +3 -3
- data/lib/axlsx/drawing/bar_series.rb +2 -2
- data/lib/axlsx/drawing/bubble_chart.rb +2 -2
- data/lib/axlsx/drawing/bubble_series.rb +2 -2
- data/lib/axlsx/drawing/cat_axis.rb +3 -3
- data/lib/axlsx/drawing/d_lbls.rb +4 -4
- data/lib/axlsx/drawing/drawing.rb +50 -50
- data/lib/axlsx/drawing/hyperlink.rb +1 -1
- data/lib/axlsx/drawing/line_3D_chart.rb +3 -3
- data/lib/axlsx/drawing/line_chart.rb +3 -3
- data/lib/axlsx/drawing/line_series.rb +2 -2
- data/lib/axlsx/drawing/num_val.rb +1 -1
- data/lib/axlsx/drawing/pic.rb +4 -4
- data/lib/axlsx/drawing/pie_3D_chart.rb +2 -2
- data/lib/axlsx/drawing/pie_chart.rb +2 -2
- data/lib/axlsx/drawing/pie_series.rb +2 -2
- data/lib/axlsx/drawing/scatter_chart.rb +2 -2
- data/lib/axlsx/drawing/scatter_series.rb +2 -2
- data/lib/axlsx/drawing/ser_axis.rb +3 -3
- data/lib/axlsx/drawing/two_cell_anchor.rb +1 -1
- data/lib/axlsx/drawing/val_axis.rb +2 -2
- data/lib/axlsx/package.rb +7 -10
- data/lib/axlsx/rels/relationship.rb +2 -2
- data/lib/axlsx/rels/relationships.rb +2 -2
- data/lib/axlsx/stylesheet/border_pr.rb +1 -1
- data/lib/axlsx/stylesheet/cell_alignment.rb +1 -1
- data/lib/axlsx/stylesheet/cell_style.rb +1 -1
- data/lib/axlsx/stylesheet/color.rb +2 -2
- data/lib/axlsx/stylesheet/font.rb +1 -1
- data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
- data/lib/axlsx/stylesheet/styles.rb +27 -31
- data/lib/axlsx/stylesheet/xf.rb +1 -1
- data/lib/axlsx/util/accessors.rb +1 -1
- data/lib/axlsx/util/constants.rb +2 -2
- data/lib/axlsx/util/serialized_attributes.rb +2 -2
- data/lib/axlsx/util/simple_typed_list.rb +25 -12
- data/lib/axlsx/util/storage.rb +3 -3
- data/lib/axlsx/util/validators.rb +1 -1
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/defined_name.rb +1 -1
- data/lib/axlsx/workbook/shared_strings_table.rb +3 -3
- data/lib/axlsx/workbook/workbook.rb +61 -61
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +4 -4
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +1 -1
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +3 -3
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +1 -1
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +2 -2
- data/lib/axlsx/workbook/worksheet/border_creator.rb +4 -4
- data/lib/axlsx/workbook/worksheet/cell.rb +7 -7
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
- data/lib/axlsx/workbook/worksheet/col.rb +22 -9
- data/lib/axlsx/workbook/worksheet/comment.rb +2 -2
- data/lib/axlsx/workbook/worksheet/comments.rb +1 -1
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +2 -2
- data/lib/axlsx/workbook/worksheet/data_validation.rb +1 -1
- data/lib/axlsx/workbook/worksheet/data_validations.rb +2 -2
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +2 -2
- data/lib/axlsx/workbook/worksheet/dimension.rb +1 -1
- data/lib/axlsx/workbook/worksheet/icon_set.rb +1 -1
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +1 -1
- data/lib/axlsx/workbook/worksheet/page_setup.rb +2 -2
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +29 -5
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +1 -1
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +1 -1
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -1
- data/lib/axlsx/workbook/worksheet/worksheet.rb +10 -12
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +3 -3
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +1 -1
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +1 -1
- data/lib/axlsx.rb +44 -30
- data/lib/caxlsx.rb +1 -1
- metadata +6 -6
@@ -7,7 +7,7 @@ module Axlsx
|
|
7
7
|
# As a developer, you should never need to directly work against this class. Simply set 'use_shared_strings'
|
8
8
|
# on the package or workbook to generate a package that uses the shared strings table instead of inline strings.
|
9
9
|
# @note Serialization performance is affected by using this serialization method so if you do not need interoperability
|
10
|
-
# it is
|
10
|
+
# it is recommended that you use the default inline string method of serialization.
|
11
11
|
class SharedStringsTable
|
12
12
|
# The total number of strings in the workbook including duplicates
|
13
13
|
# Empty cells are treated as blank strings
|
@@ -29,7 +29,7 @@ module Axlsx
|
|
29
29
|
# @see Workbook#xml_space
|
30
30
|
attr_reader :xml_space
|
31
31
|
|
32
|
-
# Creates a new Shared Strings Table
|
32
|
+
# Creates a new Shared Strings Table against an array of cells
|
33
33
|
# @param [Array] cells This is an array of all of the cells in the workbook
|
34
34
|
# @param [Symbol] xml_space The xml:space behavior for the shared string table.
|
35
35
|
def initialize(cells, xml_space = :preserve)
|
@@ -54,7 +54,7 @@ module Axlsx
|
|
54
54
|
|
55
55
|
private
|
56
56
|
|
57
|
-
#
|
57
|
+
# Iterate over all of the cells in the array.
|
58
58
|
# if our unique cells array does not contain a sharable cell,
|
59
59
|
# add the cell to our unique cells array and set the ssti attribute on the index of this cell in the shared strings table
|
60
60
|
# if a sharable cell already exists in our unique_cells array, set the ssti attribute of the cell and move on.
|
@@ -1,67 +1,67 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Axlsx
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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'
|
62
62
|
|
63
63
|
# The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles.
|
64
|
-
# The following parts of the Office Open XML spreadsheet specification are not
|
64
|
+
# The following parts of the Office Open XML spreadsheet specification are not implemented in this version.
|
65
65
|
#
|
66
66
|
# bookViews
|
67
67
|
# calcPr
|
@@ -217,7 +217,7 @@ module Axlsx
|
|
217
217
|
# Indicates if the epoc date for serialization should be 1904. If false, 1900 is used.
|
218
218
|
@@date1904 = false
|
219
219
|
|
220
|
-
# A quick helper to
|
220
|
+
# A quick helper to retrieve a worksheet by name
|
221
221
|
# @param [String] name The name of the sheet you are looking for
|
222
222
|
# @return [Worksheet] The sheet found, or nil
|
223
223
|
def sheet_by_name(name)
|
@@ -386,7 +386,7 @@ module Axlsx
|
|
386
386
|
end
|
387
387
|
|
388
388
|
# The xml:space attribute for the worksheet.
|
389
|
-
# This determines how whitespace is handled
|
389
|
+
# This determines how whitespace is handled within the document.
|
390
390
|
# The most relevant part being whitespace in the cell text.
|
391
391
|
# allowed values are :preserve and :default. Axlsx uses :preserve unless
|
392
392
|
# you explicily set this to :default.
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require_relative 'filter_column'
|
4
|
+
require_relative 'filters'
|
5
|
+
require_relative 'sort_state'
|
6
6
|
|
7
7
|
module Axlsx
|
8
8
|
# This class represents an auto filter range in a worksheet
|
@@ -80,7 +80,7 @@ module Axlsx
|
|
80
80
|
condition.order == :asc ? index1 <=> index2 : index2 <=> index1
|
81
81
|
end
|
82
82
|
|
83
|
-
break unless comparison
|
83
|
+
break unless comparison == 0
|
84
84
|
end
|
85
85
|
|
86
86
|
comparison
|
@@ -10,7 +10,7 @@ module Axlsx
|
|
10
10
|
include Axlsx::SerializedAttributes
|
11
11
|
|
12
12
|
# Creates a new FilterColumn object
|
13
|
-
# @note This class
|
13
|
+
# @note This class yields its filter object as that is where the vast majority of processing will be done
|
14
14
|
# @param [Integer|Cell] col_id The zero based index for the column to which this filter will be applied
|
15
15
|
# @param [Symbol] filter_type The symbolized class name of the filter to apply to this column.
|
16
16
|
# @param [Hash] options options for this object and the filter
|
@@ -13,7 +13,7 @@ module Axlsx
|
|
13
13
|
# @option [Boolean] blank @see blank
|
14
14
|
# @option [String] calendar_type @see calendar_type
|
15
15
|
# @option [Array] filter_items An array of values that will be used to create filter objects.
|
16
|
-
# @option [Array] date_group_items An array of
|
16
|
+
# @option [Array] date_group_items An array of hashes defining date group item filters to apply.
|
17
17
|
# @note The recommended way to interact with filter objects is via AutoFilter#add_column
|
18
18
|
# @example
|
19
19
|
# ws.auto_filter.add_column(0, :filters, :blank => true, :calendar_type => 'japan', :filter_items => [100, 'a'])
|
@@ -36,7 +36,7 @@ module Axlsx
|
|
36
36
|
# even when those dates are not using the same calendar system / date formatting.
|
37
37
|
attr_reader :calendar_type
|
38
38
|
|
39
|
-
# Tells us if the row of the cell provided should be
|
39
|
+
# Tells us if the row of the cell provided should be filtered as it
|
40
40
|
# does not meet any of the specified filter_items or
|
41
41
|
# date_group_items restrictions.
|
42
42
|
# @param [Cell] cell The cell to test against items
|
@@ -138,7 +138,7 @@ module Axlsx
|
|
138
138
|
|
139
139
|
# Creates a new DateGroupItem
|
140
140
|
# @param [Hash] options A hash of options to use when
|
141
|
-
#
|
141
|
+
# instantiating the object
|
142
142
|
# @option [String] date_time_grouping the part of the date this
|
143
143
|
# filter should apply for grouping
|
144
144
|
# @option [Integer|String] year @see year
|
@@ -6,7 +6,7 @@ module Axlsx
|
|
6
6
|
# Creates a new SortCondition object
|
7
7
|
# @param [Integer] column_index Zero-based index indicating the AutoFilter column to which the sorting should be applied to
|
8
8
|
# @param [Symbol] order The order the column should be sorted on, can only be :asc or :desc
|
9
|
-
# @param [Array] custom_list An array
|
9
|
+
# @param [Array] custom_list An array containing a custom sorting list in order.
|
10
10
|
def initialize(column_index:, order:, custom_list:)
|
11
11
|
Axlsx.validate_int column_index
|
12
12
|
@column_index = column_index
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'sort_condition'
|
4
4
|
|
5
5
|
module Axlsx
|
6
6
|
# This class performs sorting on a range in a worksheet
|
@@ -21,7 +21,7 @@ module Axlsx
|
|
21
21
|
# It requires a column_index for the sorting, descending and the custom order are optional.
|
22
22
|
# @param [Integer] column_index Zero-based index indicating the AutoFilter column to which the sorting should be applied to
|
23
23
|
# @param [Symbol] order The order the column should be sorted on, can only be :asc or :desc
|
24
|
-
# @param [Array] custom_list An array
|
24
|
+
# @param [Array] custom_list An array containing a custom sorting list in order.
|
25
25
|
# @return [SortCondition]
|
26
26
|
def add_sort_condition(column_index:, order: :asc, custom_list: [])
|
27
27
|
sort_conditions << SortCondition.new(column_index: column_index, order: order, custom_list: custom_list)
|
@@ -63,19 +63,19 @@ module Axlsx
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def first_row
|
66
|
-
@first_row ||= first_cell
|
66
|
+
@first_row ||= first_cell[/\d+/]
|
67
67
|
end
|
68
68
|
|
69
69
|
def first_col
|
70
|
-
@first_col ||= first_cell
|
70
|
+
@first_col ||= first_cell[/\D+/]
|
71
71
|
end
|
72
72
|
|
73
73
|
def last_row
|
74
|
-
@last_row ||= last_cell
|
74
|
+
@last_row ||= last_cell[/\d+/]
|
75
75
|
end
|
76
76
|
|
77
77
|
def last_col
|
78
|
-
@last_col ||= last_cell
|
78
|
+
@last_col ||= last_cell[/\D+/]
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Axlsx
|
4
4
|
# A cell in a worksheet.
|
5
|
-
# Cell stores
|
5
|
+
# Cell stores information required to serialize a single worksheet cell to xml. You must provide the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell's type will recast the value to the type specified. Altering the cell's value via the property accessor will also automatically cast the provided value to the cell's type.
|
6
6
|
# @note The recommended way to generate cells is via Worksheet#add_row
|
7
7
|
#
|
8
8
|
# @see Worksheet#add_row
|
@@ -41,7 +41,7 @@ module Axlsx
|
|
41
41
|
self.type = type unless type == :string
|
42
42
|
|
43
43
|
val = options.delete(:style)
|
44
|
-
self.style = val unless val.nil? || val
|
44
|
+
self.style = val unless val.nil? || val == 0
|
45
45
|
val = options.delete(:formula_value)
|
46
46
|
self.formula_value = val unless val.nil?
|
47
47
|
val = options.delete(:escape_formulas)
|
@@ -57,11 +57,11 @@ module Axlsx
|
|
57
57
|
# you need to set this.
|
58
58
|
attr_accessor :formula_value
|
59
59
|
|
60
|
-
# An array of available inline
|
60
|
+
# An array of available inline styles.
|
61
61
|
# TODO change this to a hash where each key defines attr name and validator (and any info the validator requires)
|
62
|
-
# then move it out to a module so we can
|
62
|
+
# then move it out to a module so we can reuse in in other classes.
|
63
63
|
# needs to define bla=(v) and bla methods on the class that hook into a
|
64
|
-
# set_attr method that kicks the
|
64
|
+
# set_attr method that kicks the supplied validator and updates the instance_variable
|
65
65
|
# for the key
|
66
66
|
INLINE_STYLES = [:value, :type, :font_name, :charset,
|
67
67
|
:family, :b, :i, :strike, :outline,
|
@@ -549,14 +549,14 @@ module Axlsx
|
|
549
549
|
|
550
550
|
case type
|
551
551
|
when :date
|
552
|
-
self.style = STYLE_DATE if style
|
552
|
+
self.style = STYLE_DATE if style == 0
|
553
553
|
if !v.is_a?(Date) && v.respond_to?(:to_date)
|
554
554
|
v.to_date
|
555
555
|
else
|
556
556
|
v
|
557
557
|
end
|
558
558
|
when :time
|
559
|
-
self.style = STYLE_DATE if style
|
559
|
+
self.style = STYLE_DATE if style == 0
|
560
560
|
if !v.is_a?(Time) && v.respond_to?(:to_time)
|
561
561
|
v.to_time
|
562
562
|
else
|
@@ -7,7 +7,7 @@ module Axlsx
|
|
7
7
|
# Calls the proper serialization method based on type.
|
8
8
|
# @param [Integer] row_index The index of the cell's row
|
9
9
|
# @param [Integer] column_index The index of the cell's column
|
10
|
-
# @param [String] str The string to
|
10
|
+
# @param [String] str The string to append serialization to.
|
11
11
|
# @return [String]
|
12
12
|
def to_xml_string(row_index, column_index, cell, str = +'')
|
13
13
|
str << '<c r="'
|
@@ -110,7 +110,7 @@ module Axlsx
|
|
110
110
|
def width=(v)
|
111
111
|
# Removing this validation make a 10% difference in performance
|
112
112
|
# as it is called EVERY TIME A CELL IS ADDED - the proper solution
|
113
|
-
# is to only set this if a calculated value is
|
113
|
+
# is to only set this if a calculated value is greater than the
|
114
114
|
# current @width value.
|
115
115
|
# TODO!!!
|
116
116
|
# Axlsx.validate_unsigned_numeric(v) unless v == nil
|
@@ -121,17 +121,30 @@ module Axlsx
|
|
121
121
|
# updates the width for this col based on the cells autowidth and
|
122
122
|
# an optionally specified fixed width
|
123
123
|
# @param [Cell] cell The cell to use in updating this col's width
|
124
|
-
# @param [
|
125
|
-
#
|
124
|
+
# @param [Numeric, :auto, :ignore, nil] fixed_width Decides how the width
|
125
|
+
# of the cell should be updated. If this is specified as as Numeric the
|
126
|
+
# width is set to this value and the cell's attributes are ignored. If set
|
127
|
+
# to `nil` or `:auto` and `use_autowidth` is true, it uses the autowidth of
|
128
|
+
# the cell. If set to `:ignore`, the cell's width is not changed. In any
|
129
|
+
# case the col's width is set to the new value only if the current width is
|
130
|
+
# smaller than the new one, so that the largest width of all cells in this
|
131
|
+
# column is used.
|
126
132
|
# @param [Boolean] use_autowidth If this is false, the cell's
|
127
133
|
# autowidth value will be ignored.
|
128
134
|
def update_width(cell, fixed_width = nil, use_autowidth = true)
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
+
cell_width =
|
136
|
+
case fixed_width
|
137
|
+
when Numeric
|
138
|
+
fixed_width
|
139
|
+
when nil, :auto
|
140
|
+
cell.autowidth if use_autowidth
|
141
|
+
when :ignore
|
142
|
+
nil
|
143
|
+
else
|
144
|
+
raise ArgumentError, "fixed_with must be a Numeric, :auto, :ignore or nil, but is '#{fixed_width.inspect}'"
|
145
|
+
end
|
146
|
+
|
147
|
+
self.width = cell_width unless (width || 0) > (cell_width || 0)
|
135
148
|
end
|
136
149
|
|
137
150
|
# Serialize this columns data to an xml string
|
@@ -11,8 +11,8 @@ module Axlsx
|
|
11
11
|
# @param [Hash] options
|
12
12
|
# @option [String] author the author of the comment
|
13
13
|
# @option [String] text The text for the comment
|
14
|
-
# @option [String] ref The
|
15
|
-
# @option [Boolean] visible This controls the
|
14
|
+
# @option [String] ref The reference (e.g. 'A3' where this comment will be anchored.
|
15
|
+
# @option [Boolean] visible This controls the visibility of the associated vml_shape.
|
16
16
|
def initialize(comments, options = {})
|
17
17
|
raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
|
18
18
|
|
@@ -37,7 +37,7 @@ module Axlsx
|
|
37
37
|
# @note the author, text and ref options are required
|
38
38
|
# @option options [String] author The name of the author for this comment
|
39
39
|
# @option options [String] text The text for this comment
|
40
|
-
# @option options [
|
40
|
+
# @option options [String|Cell] ref The cell that this comment is attached to.
|
41
41
|
def add_comment(options = {})
|
42
42
|
raise ArgumentError, "Comment require an author" unless options[:author]
|
43
43
|
raise ArgumentError, "Comment requires text" unless options[:text]
|
@@ -83,7 +83,7 @@ module Axlsx
|
|
83
83
|
def to_xml_string(str = +'')
|
84
84
|
str << '<conditionalFormatting sqref="' << sqref << '">'
|
85
85
|
rules.each_with_index do |rule, index|
|
86
|
-
str << ' ' unless index
|
86
|
+
str << ' ' unless index == 0
|
87
87
|
rule.to_xml_string(str)
|
88
88
|
end
|
89
89
|
str << '</conditionalFormatting>'
|
@@ -24,7 +24,7 @@ module Axlsx
|
|
24
24
|
# @option options [Integer] rank If a top/bottom N rule, the value of N
|
25
25
|
# @option options [Integer] stdDev The number of standard deviations above or below the average to match
|
26
26
|
# @option options [Boolean] stopIfTrue Stop evaluating rules after this rule matches
|
27
|
-
# @option options [Symbol] timePeriod The time period in a date
|
27
|
+
# @option options [Symbol] timePeriod The time period in a date occurring... rule
|
28
28
|
# @option options [String] formula The formula to match against in i.e. an equal rule. Use a [minimum, maximum] array for cellIs between/notBetween conditionals.
|
29
29
|
def initialize(options = {})
|
30
30
|
@color_scale = @data_bar = @icon_set = @formula = nil
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Axlsx
|
4
|
-
# A simple, self serializing class for storing conditional
|
4
|
+
# A simple, self serializing class for storing conditional formatting
|
5
5
|
class ConditionalFormattings < SimpleTypedList
|
6
6
|
# creates a new Tables object
|
7
7
|
def initialize(worksheet)
|
@@ -15,7 +15,7 @@ module Axlsx
|
|
15
15
|
# @return [Worksheet]
|
16
16
|
attr_reader :worksheet
|
17
17
|
|
18
|
-
# serialize the conditional
|
18
|
+
# serialize the conditional formatting
|
19
19
|
def to_xml_string(str = +'')
|
20
20
|
return if empty?
|
21
21
|
|
@@ -278,7 +278,7 @@ module Axlsx
|
|
278
278
|
|
279
279
|
str << '<dataValidation '
|
280
280
|
h.each_with_index do |key_value, index|
|
281
|
-
str << ' ' unless index
|
281
|
+
str << ' ' unless index == 0
|
282
282
|
str << key_value.first << '="' << Axlsx.booleanize(key_value.last).to_s << '"'
|
283
283
|
end
|
284
284
|
str << '>'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Axlsx
|
4
|
-
# A simple, self serializing class for storing conditional
|
4
|
+
# A simple, self serializing class for storing conditional formatting
|
5
5
|
class DataValidations < SimpleTypedList
|
6
6
|
# creates a new Tables object
|
7
7
|
def initialize(worksheet)
|
@@ -15,7 +15,7 @@ module Axlsx
|
|
15
15
|
# @return [Worksheet]
|
16
16
|
attr_reader :worksheet
|
17
17
|
|
18
|
-
# serialize the conditional
|
18
|
+
# serialize the conditional formatting
|
19
19
|
def to_xml_string(str = +'')
|
20
20
|
return if empty?
|
21
21
|
|
@@ -3,9 +3,9 @@
|
|
3
3
|
require "date"
|
4
4
|
|
5
5
|
module Axlsx
|
6
|
-
# The DateTimeConverter class converts both data and time types to their
|
6
|
+
# The DateTimeConverter class converts both data and time types to their appropriate Excel serializations
|
7
7
|
class DateTimeConverter
|
8
|
-
# The date_to_serial method converts Date objects to the
|
8
|
+
# The date_to_serial method converts Date objects to the equivalent Excel serialized forms
|
9
9
|
# @param [Date] date the date to be serialized
|
10
10
|
# @return [Numeric]
|
11
11
|
def self.date_to_serial(date)
|
@@ -99,7 +99,7 @@ module Axlsx
|
|
99
99
|
|
100
100
|
private
|
101
101
|
|
102
|
-
#
|
102
|
+
# Initialize the simple typed list of value objects
|
103
103
|
def initialize_value_objects
|
104
104
|
@value_objects = SimpleTypedList.new Cfvo
|
105
105
|
@interpolationPoints.each { |point| @value_objects << Cfvo.new(type: :percent, val: point) }
|
@@ -13,7 +13,7 @@ module Axlsx
|
|
13
13
|
:apply_styles
|
14
14
|
|
15
15
|
# These attributes are all boolean so I'm doing a bit of a hand
|
16
|
-
# waving magic show to set up the
|
16
|
+
# waving magic show to set up the attribute accessors
|
17
17
|
boolean_attr_accessor :summary_below,
|
18
18
|
:summary_right,
|
19
19
|
:apply_styles
|
@@ -38,13 +38,13 @@ module Axlsx
|
|
38
38
|
# * verticalDpi
|
39
39
|
|
40
40
|
# Number of vertical pages to fit on.
|
41
|
-
# @note PageSetup#fit_to is the
|
41
|
+
# @note PageSetup#fit_to is the recommended way to manage page fitting as only specifying one of fit_to_width/fit_to_height will result in the counterpart
|
42
42
|
# being set to 1.
|
43
43
|
# @return [Integer]
|
44
44
|
attr_reader :fit_to_height
|
45
45
|
|
46
46
|
# Number of horizontal pages to fit on.
|
47
|
-
# @note PageSetup#fit_to is the
|
47
|
+
# @note PageSetup#fit_to is the recommended way to manage page fitting as only specifying one of width/height will result in the counterpart
|
48
48
|
# being set to 1.
|
49
49
|
# @return [Integer]
|
50
50
|
attr_reader :fit_to_width
|
@@ -26,6 +26,7 @@ module Axlsx
|
|
26
26
|
@pages = []
|
27
27
|
@subtotal = nil
|
28
28
|
@no_subtotals_on_headers = []
|
29
|
+
@grand_totals = :both
|
29
30
|
@sort_on_headers = {}
|
30
31
|
@style_info = {}
|
31
32
|
parse_options options
|
@@ -51,6 +52,19 @@ module Axlsx
|
|
51
52
|
@sort_on_headers = headers
|
52
53
|
end
|
53
54
|
|
55
|
+
# Defines which Grand Totals are to be shown.
|
56
|
+
# @return [Symbol] The row and/or column Grand Totals that are to be shown.
|
57
|
+
# Defaults to `:both` to show both row & column grand totals.
|
58
|
+
# Set to `:row_only`, `:col_only`, or `:none` to hide one or both Grand Totals.
|
59
|
+
attr_reader :grand_totals
|
60
|
+
|
61
|
+
# (see #grand_totals)
|
62
|
+
def grand_totals=(value)
|
63
|
+
RestrictionValidator.validate "PivotTable.grand_totals", [:both, :row_only, :col_only, :none], value
|
64
|
+
|
65
|
+
@grand_totals = value
|
66
|
+
end
|
67
|
+
|
54
68
|
# Style info for the pivot table
|
55
69
|
# @return [Hash]
|
56
70
|
attr_accessor :style_info
|
@@ -114,7 +128,8 @@ module Axlsx
|
|
114
128
|
@columns = v
|
115
129
|
end
|
116
130
|
|
117
|
-
# The data
|
131
|
+
# The data as an array of either headers (String) or hashes or mix of the two.
|
132
|
+
# Hash in format of { ref: header, num_fmt: numFmts, subtotal: subtotal }, where header is String, numFmts is Integer, and subtotal one of %w[sum count average max min product countNums stdDev stdDevp var varp]; leave subtotal blank to sum values
|
118
133
|
# @return [Array]
|
119
134
|
attr_reader :data
|
120
135
|
|
@@ -188,7 +203,11 @@ module Axlsx
|
|
188
203
|
def to_xml_string(str = +'')
|
189
204
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
190
205
|
|
191
|
-
str << '<pivotTableDefinition xmlns="' << XML_NS << '" name="' << name << '" cacheId="' << cache_definition.cache_id.to_s << '"'
|
206
|
+
str << '<pivotTableDefinition xmlns="' << XML_NS << '" name="' << name << '" cacheId="' << cache_definition.cache_id.to_s << '"'
|
207
|
+
str << ' dataOnRows="1"' if data.size <= 1
|
208
|
+
str << ' rowGrandTotals="0"' if grand_totals == :col_only || grand_totals == :none
|
209
|
+
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">'
|
192
211
|
|
193
212
|
str << '<location firstDataCol="1" firstDataRow="1" firstHeaderRow="1" ref="' << ref << '"/>'
|
194
213
|
str << '<pivotFields count="' << header_cells_count.to_s << '">'
|
@@ -244,8 +263,9 @@ module Axlsx
|
|
244
263
|
unless data.empty?
|
245
264
|
str << "<dataFields count=\"#{data.size}\">"
|
246
265
|
data.each do |datum_value|
|
247
|
-
|
248
|
-
|
266
|
+
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'"
|
249
269
|
str << " numFmtId='#{datum_value[:num_fmt]}'" if datum_value[:num_fmt]
|
250
270
|
str << " subtotal='#{datum_value[:subtotal]}' " if datum_value[:subtotal]
|
251
271
|
str << "/>"
|
@@ -311,7 +331,11 @@ module Axlsx
|
|
311
331
|
elsif columns.include? cell_ref
|
312
332
|
attributes << 'axis="axisCol"'
|
313
333
|
attributes << "sortType=\"#{sorttype == :descending ? 'descending' : 'ascending'}\"" if sorttype
|
314
|
-
|
334
|
+
if subtotal
|
335
|
+
include_items_tag = true
|
336
|
+
else
|
337
|
+
attributes << 'defaultSubtotal="0"'
|
338
|
+
end
|
315
339
|
elsif pages.include? cell_ref
|
316
340
|
attributes << 'axis="axisPage"'
|
317
341
|
include_items_tag = true
|
@@ -143,7 +143,7 @@ module Axlsx
|
|
143
143
|
# It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true
|
144
144
|
# @return [Boolean]
|
145
145
|
# @return [String]
|
146
|
-
# @note true is for backwards
|
146
|
+
# @note true is for backwards compatibility and is reassigned to :single
|
147
147
|
attr_reader :u
|
148
148
|
|
149
149
|
# @see u
|