caxlsx 3.3.0 → 3.4.1
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 +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +26 -6
- data/Rakefile +0 -1
- data/lib/axlsx/content_type/abstract_content_type.rb +2 -5
- data/lib/axlsx/content_type/content_type.rb +0 -4
- data/lib/axlsx/content_type/default.rb +1 -5
- data/lib/axlsx/content_type/override.rb +0 -4
- data/lib/axlsx/doc_props/app.rb +1 -6
- data/lib/axlsx/doc_props/core.rb +1 -6
- data/lib/axlsx/drawing/area_chart.rb +3 -6
- data/lib/axlsx/drawing/area_series.rb +1 -4
- data/lib/axlsx/drawing/ax_data_source.rb +1 -6
- data/lib/axlsx/drawing/axes.rb +5 -6
- data/lib/axlsx/drawing/axis.rb +7 -12
- data/lib/axlsx/drawing/bar_3D_chart.rb +7 -10
- data/lib/axlsx/drawing/bar_chart.rb +6 -9
- data/lib/axlsx/drawing/bar_series.rb +2 -8
- data/lib/axlsx/drawing/bubble_chart.rb +2 -5
- data/lib/axlsx/drawing/bubble_series.rb +3 -6
- data/lib/axlsx/drawing/cat_axis.rb +2 -7
- data/lib/axlsx/drawing/chart.rb +7 -12
- data/lib/axlsx/drawing/d_lbls.rb +23 -22
- data/lib/axlsx/drawing/drawing.rb +4 -8
- data/lib/axlsx/drawing/graphic_frame.rb +0 -3
- data/lib/axlsx/drawing/hyperlink.rb +4 -7
- data/lib/axlsx/drawing/line_3D_chart.rb +10 -14
- data/lib/axlsx/drawing/line_chart.rb +3 -6
- data/lib/axlsx/drawing/line_series.rb +1 -4
- data/lib/axlsx/drawing/marker.rb +5 -9
- data/lib/axlsx/drawing/num_data.rb +4 -9
- data/lib/axlsx/drawing/num_data_source.rb +3 -7
- data/lib/axlsx/drawing/num_val.rb +2 -5
- data/lib/axlsx/drawing/one_cell_anchor.rb +4 -6
- data/lib/axlsx/drawing/pic.rb +46 -13
- data/lib/axlsx/drawing/picture_locking.rb +3 -6
- data/lib/axlsx/drawing/pie_3D_chart.rb +2 -7
- data/lib/axlsx/drawing/pie_series.rb +1 -6
- data/lib/axlsx/drawing/scaling.rb +2 -5
- data/lib/axlsx/drawing/scatter_chart.rb +2 -5
- data/lib/axlsx/drawing/scatter_series.rb +2 -5
- data/lib/axlsx/drawing/ser_axis.rb +2 -6
- data/lib/axlsx/drawing/series.rb +3 -5
- data/lib/axlsx/drawing/series_title.rb +0 -2
- data/lib/axlsx/drawing/str_data.rb +3 -8
- data/lib/axlsx/drawing/str_val.rb +2 -5
- data/lib/axlsx/drawing/title.rb +12 -15
- data/lib/axlsx/drawing/two_cell_anchor.rb +5 -7
- data/lib/axlsx/drawing/val_axis.rb +1 -4
- data/lib/axlsx/drawing/view_3D.rb +24 -24
- data/lib/axlsx/drawing/vml_drawing.rb +2 -5
- data/lib/axlsx/drawing/vml_shape.rb +4 -7
- data/lib/axlsx/package.rb +35 -36
- data/lib/axlsx/rels/relationship.rb +21 -24
- data/lib/axlsx/rels/relationships.rb +3 -6
- data/lib/axlsx/stylesheet/border.rb +1 -4
- data/lib/axlsx/stylesheet/border_pr.rb +3 -5
- data/lib/axlsx/stylesheet/cell_alignment.rb +2 -10
- data/lib/axlsx/stylesheet/cell_protection.rb +1 -4
- data/lib/axlsx/stylesheet/cell_style.rb +3 -7
- data/lib/axlsx/stylesheet/color.rb +6 -5
- data/lib/axlsx/stylesheet/dxf.rb +2 -6
- data/lib/axlsx/stylesheet/fill.rb +0 -4
- data/lib/axlsx/stylesheet/font.rb +7 -6
- data/lib/axlsx/stylesheet/gradient_fill.rb +4 -6
- data/lib/axlsx/stylesheet/gradient_stop.rb +2 -3
- data/lib/axlsx/stylesheet/num_fmt.rb +1 -4
- data/lib/axlsx/stylesheet/pattern_fill.rb +3 -5
- data/lib/axlsx/stylesheet/styles.rb +53 -45
- data/lib/axlsx/stylesheet/table_style.rb +5 -8
- data/lib/axlsx/stylesheet/table_style_element.rb +1 -4
- data/lib/axlsx/stylesheet/table_styles.rb +3 -7
- data/lib/axlsx/stylesheet/xf.rb +3 -6
- data/lib/axlsx/util/accessors.rb +2 -4
- data/lib/axlsx/util/constants.rb +3 -5
- data/lib/axlsx/util/mime_type_utils.rb +13 -0
- data/lib/axlsx/util/options_parser.rb +1 -2
- data/lib/axlsx/util/serialized_attributes.rb +4 -5
- data/lib/axlsx/util/simple_typed_list.rb +18 -17
- data/lib/axlsx/util/storage.rb +32 -36
- data/lib/axlsx/util/validators.rb +7 -4
- data/lib/axlsx/util/zip_command.rb +0 -2
- data/lib/axlsx/version.rb +1 -2
- data/lib/axlsx/workbook/defined_name.rb +6 -5
- data/lib/axlsx/workbook/defined_names.rb +1 -2
- data/lib/axlsx/workbook/shared_strings_table.rb +3 -6
- data/lib/axlsx/workbook/workbook.rb +96 -91
- data/lib/axlsx/workbook/workbook_view.rb +5 -10
- data/lib/axlsx/workbook/workbook_views.rb +1 -3
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +9 -8
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +6 -6
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +13 -14
- data/lib/axlsx/workbook/worksheet/border_creator.rb +29 -26
- data/lib/axlsx/workbook/worksheet/break.rb +2 -5
- data/lib/axlsx/workbook/worksheet/cell.rb +55 -27
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +11 -11
- data/lib/axlsx/workbook/worksheet/cfvo.rb +2 -2
- data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -5
- data/lib/axlsx/workbook/worksheet/col.rb +4 -7
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +4 -5
- data/lib/axlsx/workbook/worksheet/color_scale.rb +10 -12
- data/lib/axlsx/workbook/worksheet/cols.rb +6 -6
- data/lib/axlsx/workbook/worksheet/comment.rb +4 -5
- data/lib/axlsx/workbook/worksheet/comments.rb +6 -10
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +4 -5
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +2 -6
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +2 -4
- data/lib/axlsx/workbook/worksheet/data_bar.rb +20 -22
- data/lib/axlsx/workbook/worksheet/data_validation.rb +4 -5
- data/lib/axlsx/workbook/worksheet/data_validations.rb +2 -5
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -3
- data/lib/axlsx/workbook/worksheet/dimension.rb +5 -4
- data/lib/axlsx/workbook/worksheet/header_footer.rb +0 -1
- data/lib/axlsx/workbook/worksheet/icon_set.rb +2 -3
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +8 -8
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +0 -1
- data/lib/axlsx/workbook/worksheet/page_margins.rb +2 -2
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -3
- data/lib/axlsx/workbook/worksheet/page_setup.rb +117 -120
- data/lib/axlsx/workbook/worksheet/pane.rb +16 -17
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +8 -11
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -11
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -4
- data/lib/axlsx/workbook/worksheet/print_options.rb +0 -1
- data/lib/axlsx/workbook/worksheet/protected_range.rb +4 -5
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +9 -9
- data/lib/axlsx/workbook/worksheet/rich_text.rb +4 -6
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +21 -5
- data/lib/axlsx/workbook/worksheet/row.rb +24 -15
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +3 -4
- data/lib/axlsx/workbook/worksheet/selection.rb +7 -9
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +5 -6
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +4 -6
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +18 -18
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +4 -4
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +12 -13
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +35 -42
- data/lib/axlsx/workbook/worksheet/table.rb +7 -9
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +2 -3
- data/lib/axlsx/workbook/worksheet/tables.rb +4 -4
- data/lib/axlsx/workbook/worksheet/worksheet.rb +63 -35
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -6
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +3 -2
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +5 -6
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +4 -4
- data/lib/axlsx.rb +23 -9
- data/lib/caxlsx.rb +0 -1
- metadata +3 -3
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
1
|
module Axlsx
|
|
4
2
|
class BorderCreator
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def initialize(worksheet, cells, args)
|
|
3
|
+
def initialize(worksheet:, cells:, edges: nil, style: nil, color: nil)
|
|
8
4
|
@worksheet = worksheet
|
|
9
|
-
@cells
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
else
|
|
15
|
-
@edges = args || Axlsx::Border::Edges
|
|
16
|
-
@width = :thin
|
|
17
|
-
@color = '000000'
|
|
18
|
-
end
|
|
5
|
+
@cells = cells
|
|
6
|
+
|
|
7
|
+
@edges = edges || :all
|
|
8
|
+
@style = style || :thin
|
|
9
|
+
@color = color || "000000"
|
|
19
10
|
|
|
20
11
|
if @edges == :all
|
|
21
12
|
@edges = Axlsx::Border::EDGES
|
|
22
|
-
elsif
|
|
23
|
-
|
|
13
|
+
elsif !@edges.is_a?(Array)
|
|
14
|
+
raise ArgumentError.new("Invalid edges provided, #{@edges}")
|
|
24
15
|
else
|
|
25
|
-
@edges =
|
|
16
|
+
@edges = @edges.map { |x| x&.to_sym }.uniq
|
|
17
|
+
|
|
18
|
+
if !(@edges - Axlsx::Border::EDGES).empty?
|
|
19
|
+
raise ArgumentError.new("Invalid edges provided, #{edges}")
|
|
20
|
+
end
|
|
26
21
|
end
|
|
27
22
|
end
|
|
28
23
|
|
|
29
24
|
def draw
|
|
30
|
-
@
|
|
31
|
-
worksheet.add_style(
|
|
32
|
-
|
|
25
|
+
if @cells.size == 1
|
|
26
|
+
@worksheet.add_style(
|
|
27
|
+
first_cell,
|
|
33
28
|
{
|
|
34
|
-
border: {style: @
|
|
29
|
+
border: { style: @style, color: @color, edges: @edges }
|
|
35
30
|
}
|
|
36
31
|
)
|
|
32
|
+
else
|
|
33
|
+
@edges.each do |edge|
|
|
34
|
+
@worksheet.add_style(
|
|
35
|
+
border_cells[edge],
|
|
36
|
+
{
|
|
37
|
+
border: { style: @style, color: @color, edges: [edge] }
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
end
|
|
37
41
|
end
|
|
38
42
|
end
|
|
39
43
|
|
|
@@ -44,16 +48,16 @@ module Axlsx
|
|
|
44
48
|
top: "#{first_cell}:#{last_col}#{first_row}",
|
|
45
49
|
right: "#{last_col}#{first_row}:#{last_cell}",
|
|
46
50
|
bottom: "#{first_col}#{last_row}:#{last_cell}",
|
|
47
|
-
left: "#{first_cell}:#{first_col}#{last_row}"
|
|
51
|
+
left: "#{first_cell}:#{first_col}#{last_row}"
|
|
48
52
|
}
|
|
49
53
|
end
|
|
50
54
|
|
|
51
55
|
def first_cell
|
|
52
|
-
@first_cell ||= cells.first.r
|
|
56
|
+
@first_cell ||= @cells.first.r
|
|
53
57
|
end
|
|
54
58
|
|
|
55
59
|
def last_cell
|
|
56
|
-
@last_cell ||= cells.last.r
|
|
60
|
+
@last_cell ||= @cells.last.r
|
|
57
61
|
end
|
|
58
62
|
|
|
59
63
|
def first_row
|
|
@@ -71,6 +75,5 @@ module Axlsx
|
|
|
71
75
|
def last_col
|
|
72
76
|
@last_col ||= last_cell.scan(/\D+/).first
|
|
73
77
|
end
|
|
74
|
-
|
|
75
78
|
end
|
|
76
79
|
end
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
module Axlsx
|
|
2
|
-
|
|
3
2
|
# The Break class stores the details for row and column page breaks.
|
|
4
3
|
# @see RowBreaks, ColBreaks
|
|
5
4
|
class Break
|
|
6
|
-
|
|
7
5
|
include Axlsx::OptionsParser
|
|
8
6
|
include Axlsx::Accessors
|
|
9
7
|
include Axlsx::SerializedAttributes
|
|
@@ -15,7 +13,7 @@ module Axlsx
|
|
|
15
13
|
# @option options [Integer] max Zero-based index of end row or column of the break. For row breaks, specifies column index; for column breaks, specifies row index.
|
|
16
14
|
# @option options [Boolean] man Manual Break flag. 1 means the break is a manually inserted break.
|
|
17
15
|
# @option option [Boolean] pt Flag indicating that a PivotTable created this break.
|
|
18
|
-
def initialize(options={})
|
|
16
|
+
def initialize(options = {})
|
|
19
17
|
parse_options options
|
|
20
18
|
yield self if block_given?
|
|
21
19
|
end
|
|
@@ -27,9 +25,8 @@ module Axlsx
|
|
|
27
25
|
serializable_attributes :id, :min, :max, :man, :pt
|
|
28
26
|
|
|
29
27
|
# serializes the break to xml
|
|
30
|
-
def to_xml_string(str='')
|
|
28
|
+
def to_xml_string(str = '')
|
|
31
29
|
serialized_tag('brk', str)
|
|
32
30
|
end
|
|
33
31
|
end
|
|
34
32
|
end
|
|
35
|
-
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
1
|
require 'cgi'
|
|
3
2
|
module Axlsx
|
|
4
3
|
# A cell in a worksheet.
|
|
@@ -7,7 +6,6 @@ module Axlsx
|
|
|
7
6
|
#
|
|
8
7
|
# @see Worksheet#add_row
|
|
9
8
|
class Cell
|
|
10
|
-
|
|
11
9
|
include Axlsx::OptionsParser
|
|
12
10
|
|
|
13
11
|
# @param [Row] row The row this cell belongs to.
|
|
@@ -30,10 +28,9 @@ module Axlsx
|
|
|
30
28
|
# @option options [String] color an 8 letter rgb specification
|
|
31
29
|
# @option options [Number] formula_value The value to cache for a formula cell.
|
|
32
30
|
# @option options [Symbol] scheme must be one of :none, major, :minor
|
|
33
|
-
# @option options [Boolean] escape_formulas
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
# (see https://www.owasp.org/index.php/CSV_Injection for details).
|
|
31
|
+
# @option options [Boolean] escape_formulas Whether to treat values starting with an equals
|
|
32
|
+
# sign as formulas or as literal strings. Allowing user-generated data to be interpreted as
|
|
33
|
+
# formulas is a security risk. See https://www.owasp.org/index.php/CSV_Injection for details.
|
|
37
34
|
def initialize(row, value = nil, options = {})
|
|
38
35
|
@row = row
|
|
39
36
|
# Do not use instance vars if not needed to use less RAM
|
|
@@ -42,15 +39,13 @@ module Axlsx
|
|
|
42
39
|
type = options.delete(:type) || cell_type_from_value(value)
|
|
43
40
|
self.type = type unless type == :string
|
|
44
41
|
|
|
45
|
-
escape_formulas = options[:escape_formulas]
|
|
46
|
-
self.escape_formulas = escape_formulas unless escape_formulas.nil?
|
|
47
|
-
|
|
48
42
|
val = options.delete(:style)
|
|
49
43
|
self.style = val unless val.nil? || val == 0
|
|
50
44
|
val = options.delete(:formula_value)
|
|
51
45
|
self.formula_value = val unless val.nil?
|
|
52
46
|
|
|
53
47
|
parse_options(options)
|
|
48
|
+
self.escape_formulas = row.worksheet.escape_formulas if escape_formulas.nil?
|
|
54
49
|
|
|
55
50
|
self.value = value
|
|
56
51
|
value.cell = self if contains_rich_text?
|
|
@@ -75,6 +70,16 @@ module Axlsx
|
|
|
75
70
|
CELL_TYPES = [:date, :time, :float, :integer, :richtext,
|
|
76
71
|
:string, :boolean, :iso_8601, :text].freeze
|
|
77
72
|
|
|
73
|
+
# Leading characters that indicate a formula.
|
|
74
|
+
# See: https://owasp.org/www-community/attacks/CSV_Injection
|
|
75
|
+
FORMULA_PREFIXES = ['='.freeze].freeze
|
|
76
|
+
|
|
77
|
+
# Leading characters that indicate an array formula.
|
|
78
|
+
ARRAY_FORMULA_PREFIXES = ['{='.freeze].freeze
|
|
79
|
+
|
|
80
|
+
# Trailing character that indicates an array formula.
|
|
81
|
+
ARRAY_FORMULA_SUFFIX = '}'.freeze
|
|
82
|
+
|
|
78
83
|
# The index of the cellXfs item to be applied to this cell.
|
|
79
84
|
# @return [Integer]
|
|
80
85
|
# @see Axlsx::Styles
|
|
@@ -104,7 +109,7 @@ module Axlsx
|
|
|
104
109
|
self.raw_style = new_style
|
|
105
110
|
|
|
106
111
|
wb = row.worksheet.workbook
|
|
107
|
-
|
|
112
|
+
|
|
108
113
|
wb.styled_cells << self
|
|
109
114
|
end
|
|
110
115
|
|
|
@@ -134,16 +139,17 @@ module Axlsx
|
|
|
134
139
|
self.value = @value unless !defined?(@value) || @value.nil?
|
|
135
140
|
end
|
|
136
141
|
|
|
137
|
-
# Whether to treat
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
# (see https://www.owasp.org/index.php/CSV_Injection for details).
|
|
142
|
+
# Whether to treat values starting with an equals sign as formulas or as literal strings.
|
|
143
|
+
# Allowing user-generated data to be interpreted as formulas is a security risk.
|
|
144
|
+
# See https://www.owasp.org/index.php/CSV_Injection for details.
|
|
141
145
|
# @return [Boolean]
|
|
142
146
|
attr_reader :escape_formulas
|
|
143
147
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
148
|
+
# Sets whether to treat values starting with an equals sign as formulas or as literal strings.
|
|
149
|
+
# @param [Boolean] value The value to set.
|
|
150
|
+
def escape_formulas=(value)
|
|
151
|
+
Axlsx.validate_boolean(value)
|
|
152
|
+
@escape_formulas = value
|
|
147
153
|
end
|
|
148
154
|
|
|
149
155
|
# The value of this cell.
|
|
@@ -152,7 +158,7 @@ module Axlsx
|
|
|
152
158
|
|
|
153
159
|
# @see value
|
|
154
160
|
def value=(v)
|
|
155
|
-
#TODO: consider doing value based type determination first?
|
|
161
|
+
# TODO: consider doing value based type determination first?
|
|
156
162
|
@value = cast_value(v)
|
|
157
163
|
end
|
|
158
164
|
|
|
@@ -172,12 +178,14 @@ module Axlsx
|
|
|
172
178
|
!is_text_run? && # No inline styles
|
|
173
179
|
!@value.nil? && # Not nil
|
|
174
180
|
!@value.empty? && # Not empty
|
|
175
|
-
|
|
181
|
+
!is_formula? && # Not a formula
|
|
182
|
+
!is_array_formula? # Not an array formula
|
|
176
183
|
end
|
|
177
184
|
|
|
178
185
|
# The inline font_name property for the cell
|
|
179
186
|
# @return [String]
|
|
180
187
|
attr_reader :font_name
|
|
188
|
+
|
|
181
189
|
# @see font_name
|
|
182
190
|
def font_name=(v) set_run_style :validate_string, :font_name, v; end
|
|
183
191
|
|
|
@@ -204,6 +212,7 @@ module Axlsx
|
|
|
204
212
|
# 255  OEM_CHARSET
|
|
205
213
|
# @return [String]
|
|
206
214
|
attr_reader :charset
|
|
215
|
+
|
|
207
216
|
# @see charset
|
|
208
217
|
def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end
|
|
209
218
|
|
|
@@ -215,6 +224,7 @@ module Axlsx
|
|
|
215
224
|
# 4 Script
|
|
216
225
|
# 5 Decorative
|
|
217
226
|
attr_reader :family
|
|
227
|
+
|
|
218
228
|
# @see family
|
|
219
229
|
def family=(v)
|
|
220
230
|
set_run_style :validate_family, :family, v.to_i
|
|
@@ -223,42 +233,49 @@ module Axlsx
|
|
|
223
233
|
# The inline bold property for the cell
|
|
224
234
|
# @return [Boolean]
|
|
225
235
|
attr_reader :b
|
|
236
|
+
|
|
226
237
|
# @see b
|
|
227
238
|
def b=(v) set_run_style :validate_boolean, :b, v; end
|
|
228
239
|
|
|
229
240
|
# The inline italic property for the cell
|
|
230
241
|
# @return [Boolean]
|
|
231
242
|
attr_reader :i
|
|
243
|
+
|
|
232
244
|
# @see i
|
|
233
245
|
def i=(v) set_run_style :validate_boolean, :i, v; end
|
|
234
246
|
|
|
235
247
|
# The inline strike property for the cell
|
|
236
248
|
# @return [Boolean]
|
|
237
249
|
attr_reader :strike
|
|
250
|
+
|
|
238
251
|
# @see strike
|
|
239
252
|
def strike=(v) set_run_style :validate_boolean, :strike, v; end
|
|
240
253
|
|
|
241
254
|
# The inline outline property for the cell
|
|
242
255
|
# @return [Boolean]
|
|
243
256
|
attr_reader :outline
|
|
257
|
+
|
|
244
258
|
# @see outline
|
|
245
259
|
def outline=(v) set_run_style :validate_boolean, :outline, v; end
|
|
246
260
|
|
|
247
261
|
# The inline shadow property for the cell
|
|
248
262
|
# @return [Boolean]
|
|
249
263
|
attr_reader :shadow
|
|
264
|
+
|
|
250
265
|
# @see shadow
|
|
251
266
|
def shadow=(v) set_run_style :validate_boolean, :shadow, v; end
|
|
252
267
|
|
|
253
268
|
# The inline condense property for the cell
|
|
254
269
|
# @return [Boolean]
|
|
255
270
|
attr_reader :condense
|
|
271
|
+
|
|
256
272
|
# @see condense
|
|
257
273
|
def condense=(v) set_run_style :validate_boolean, :condense, v; end
|
|
258
274
|
|
|
259
275
|
# The inline extend property for the cell
|
|
260
276
|
# @return [Boolean]
|
|
261
277
|
attr_reader :extend
|
|
278
|
+
|
|
262
279
|
# @see extend
|
|
263
280
|
def extend=(v) set_run_style :validate_boolean, :extend, v; end
|
|
264
281
|
|
|
@@ -268,6 +285,7 @@ module Axlsx
|
|
|
268
285
|
# @return [String]
|
|
269
286
|
# @note true is for backwards compatability and is reassigned to :single
|
|
270
287
|
attr_reader :u
|
|
288
|
+
|
|
271
289
|
# @see u
|
|
272
290
|
def u=(v)
|
|
273
291
|
v = :single if (v == true || v == 1 || v == :true || v == 'true')
|
|
@@ -277,15 +295,17 @@ module Axlsx
|
|
|
277
295
|
# The inline color property for the cell
|
|
278
296
|
# @return [Color]
|
|
279
297
|
attr_reader :color
|
|
298
|
+
|
|
280
299
|
# @param [String] v The 8 character representation for an rgb color #FFFFFFFF"
|
|
281
300
|
def color=(v)
|
|
282
|
-
@color = v.is_a?(Color) ? v : Color.new(:rgb=>v)
|
|
301
|
+
@color = v.is_a?(Color) ? v : Color.new(:rgb => v)
|
|
283
302
|
@is_text_run = true
|
|
284
303
|
end
|
|
285
304
|
|
|
286
305
|
# The inline sz property for the cell
|
|
287
306
|
# @return [Inteter]
|
|
288
307
|
attr_reader :sz
|
|
308
|
+
|
|
289
309
|
# @see sz
|
|
290
310
|
def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end
|
|
291
311
|
|
|
@@ -293,6 +313,7 @@ module Axlsx
|
|
|
293
313
|
# this must be one of [:baseline, :subscript, :superscript]
|
|
294
314
|
# @return [Symbol]
|
|
295
315
|
attr_reader :vertAlign
|
|
316
|
+
|
|
296
317
|
# @see vertAlign
|
|
297
318
|
def vertAlign=(v)
|
|
298
319
|
RestrictionValidator.validate :cell_vertAlign, [:baseline, :subscript, :superscript], v
|
|
@@ -303,6 +324,7 @@ module Axlsx
|
|
|
303
324
|
# this must be one of [:none, major, minor]
|
|
304
325
|
# @return [Symbol]
|
|
305
326
|
attr_reader :scheme
|
|
327
|
+
|
|
306
328
|
# @see scheme
|
|
307
329
|
def scheme=(v)
|
|
308
330
|
RestrictionValidator.validate :cell_scheme, [:none, :major, :minor], v
|
|
@@ -329,7 +351,7 @@ module Axlsx
|
|
|
329
351
|
# @example Absolute Cell Reference
|
|
330
352
|
# ws.rows.first.cells.first.r #=> "$A$1"
|
|
331
353
|
def r_abs
|
|
332
|
-
"$#{r.match(%r{([A-Z]+)([0-9]+)})[1,2].join('$')}"
|
|
354
|
+
"$#{r.match(%r{([A-Z]+)([0-9]+)})[1, 2].join('$')}"
|
|
333
355
|
end
|
|
334
356
|
|
|
335
357
|
# @return [Integer] The cellXfs item index applied to this cell.
|
|
@@ -338,6 +360,7 @@ module Axlsx
|
|
|
338
360
|
Axlsx::validate_unsigned_int(v)
|
|
339
361
|
count = styles.cellXfs.size
|
|
340
362
|
raise ArgumentError, "Invalid cellXfs id" unless v < count
|
|
363
|
+
|
|
341
364
|
@style = v
|
|
342
365
|
end
|
|
343
366
|
|
|
@@ -352,7 +375,7 @@ module Axlsx
|
|
|
352
375
|
def merge(target)
|
|
353
376
|
start, stop = if target.is_a?(String)
|
|
354
377
|
[self.r, target]
|
|
355
|
-
elsif
|
|
378
|
+
elsif target.is_a?(Cell)
|
|
356
379
|
Axlsx.sort_cells([self, target]).map { |c| c.r }
|
|
357
380
|
end
|
|
358
381
|
self.row.worksheet.merge_cells "#{start}:#{stop}" unless stop.nil?
|
|
@@ -370,11 +393,15 @@ module Axlsx
|
|
|
370
393
|
def is_formula?
|
|
371
394
|
return false if escape_formulas
|
|
372
395
|
|
|
373
|
-
type == :string && @value.to_s.start_with?(
|
|
396
|
+
type == :string && @value.to_s.start_with?(*FORMULA_PREFIXES)
|
|
374
397
|
end
|
|
375
398
|
|
|
376
399
|
def is_array_formula?
|
|
377
|
-
|
|
400
|
+
return false if escape_formulas
|
|
401
|
+
|
|
402
|
+
type == :string &&
|
|
403
|
+
@value.to_s.start_with?(*ARRAY_FORMULA_PREFIXES) &&
|
|
404
|
+
@value.to_s.end_with?(ARRAY_FORMULA_SUFFIX)
|
|
378
405
|
end
|
|
379
406
|
|
|
380
407
|
# returns the absolute or relative string style reference for
|
|
@@ -382,7 +409,7 @@ module Axlsx
|
|
|
382
409
|
# @param [Boolean] absolute -when false a relative reference will be
|
|
383
410
|
# returned.
|
|
384
411
|
# @return [String]
|
|
385
|
-
def reference(absolute=true)
|
|
412
|
+
def reference(absolute = true)
|
|
386
413
|
absolute ? r_abs : r
|
|
387
414
|
end
|
|
388
415
|
|
|
@@ -452,6 +479,7 @@ module Axlsx
|
|
|
452
479
|
# Utility method for setting inline style attributes
|
|
453
480
|
def set_run_style(validator, attr, value)
|
|
454
481
|
return unless INLINE_STYLES.include?(attr.to_sym)
|
|
482
|
+
|
|
455
483
|
Axlsx.send(validator, value) unless validator.nil?
|
|
456
484
|
self.instance_variable_set :"@#{attr.to_s}", value
|
|
457
485
|
@is_text_run = true
|
|
@@ -499,6 +527,7 @@ module Axlsx
|
|
|
499
527
|
# @see Axlsx#date1904
|
|
500
528
|
def cast_value(v)
|
|
501
529
|
return v if v.is_a?(RichText) || v.nil?
|
|
530
|
+
|
|
502
531
|
case type
|
|
503
532
|
when :date
|
|
504
533
|
self.style = STYLE_DATE if self.style == 0
|
|
@@ -521,12 +550,11 @@ module Axlsx
|
|
|
521
550
|
when :boolean
|
|
522
551
|
v ? 1 : 0
|
|
523
552
|
when :iso_8601
|
|
524
|
-
#consumer is responsible for ensuring the iso_8601 format when specifying this type
|
|
553
|
+
# consumer is responsible for ensuring the iso_8601 format when specifying this type
|
|
525
554
|
v
|
|
526
555
|
else
|
|
527
556
|
v.to_s
|
|
528
557
|
end
|
|
529
558
|
end
|
|
530
|
-
|
|
531
559
|
end
|
|
532
560
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
module Axlsx
|
|
2
|
-
|
|
3
2
|
# The Cell Serializer class contains the logic for serializing cells based on their type.
|
|
4
3
|
class CellSerializer
|
|
5
4
|
class << self
|
|
@@ -8,9 +7,10 @@ module Axlsx
|
|
|
8
7
|
# @param [Integer] column_index The index of the cell's column
|
|
9
8
|
# @param [String] str The string to apend serialization to.
|
|
10
9
|
# @return [String]
|
|
11
|
-
def to_xml_string(row_index, column_index, cell, str='')
|
|
10
|
+
def to_xml_string(row_index, column_index, cell, str = '')
|
|
12
11
|
str << ('<c r="' << Axlsx::cell_r(column_index, row_index) << '" s="' << cell.style.to_s << '" ')
|
|
13
12
|
return str << '/>' if cell.value.nil?
|
|
13
|
+
|
|
14
14
|
method = cell.type
|
|
15
15
|
self.send(method, cell, str)
|
|
16
16
|
str << '</c>'
|
|
@@ -22,7 +22,7 @@ module Axlsx
|
|
|
22
22
|
def run_xml_string(cell, str = '')
|
|
23
23
|
if cell.is_text_run?
|
|
24
24
|
valid = RichTextRun::INLINE_STYLES - [:value, :type]
|
|
25
|
-
data = Hash[Axlsx.instance_values_for(cell).map{ |k, v| [k.to_sym, v] }]
|
|
25
|
+
data = Hash[Axlsx.instance_values_for(cell).map { |k, v| [k.to_sym, v] }]
|
|
26
26
|
data = data.select { |key, value| valid.include?(key) && !value.nil? }
|
|
27
27
|
RichText.new(cell.value.to_s, data).to_xml_string(str)
|
|
28
28
|
elsif cell.contains_rich_text?
|
|
@@ -37,7 +37,7 @@ module Axlsx
|
|
|
37
37
|
# @param [Cell] cell The cell that is being serialized
|
|
38
38
|
# @param [String] str The string the serialized content will be appended to.
|
|
39
39
|
# @return [String]
|
|
40
|
-
def iso_8601(cell, str='')
|
|
40
|
+
def iso_8601(cell, str = '')
|
|
41
41
|
value_serialization 'd', cell.value, str
|
|
42
42
|
end
|
|
43
43
|
|
|
@@ -45,7 +45,7 @@ module Axlsx
|
|
|
45
45
|
# @param [Cell] cell The cell that is being serialized
|
|
46
46
|
# @param [String] str The string the serialized content will be appended to.
|
|
47
47
|
# @return [String]
|
|
48
|
-
def date(cell, str='')
|
|
48
|
+
def date(cell, str = '')
|
|
49
49
|
value_serialization false, DateTimeConverter::date_to_serial(cell.value).to_s, str
|
|
50
50
|
end
|
|
51
51
|
|
|
@@ -53,7 +53,7 @@ module Axlsx
|
|
|
53
53
|
# @param [Cell] cell The cell that is being serialized
|
|
54
54
|
# @param [String] str The string the serialized content will be appended to.
|
|
55
55
|
# @return [String]
|
|
56
|
-
def time(cell, str='')
|
|
56
|
+
def time(cell, str = '')
|
|
57
57
|
value_serialization false, DateTimeConverter::time_to_serial(cell.value).to_s, str
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -61,7 +61,7 @@ module Axlsx
|
|
|
61
61
|
# @param [Cell] cell The cell that is being serialized
|
|
62
62
|
# @param [String] str The string the serialized content will be appended to.
|
|
63
63
|
# @return [String]
|
|
64
|
-
def boolean(cell, str='')
|
|
64
|
+
def boolean(cell, str = '')
|
|
65
65
|
value_serialization 'b', cell.value.to_s, str
|
|
66
66
|
end
|
|
67
67
|
|
|
@@ -69,7 +69,7 @@ module Axlsx
|
|
|
69
69
|
# @param [Cell] cell The cell that is being serialized
|
|
70
70
|
# @param [String] str The string the serialized content will be appended to.
|
|
71
71
|
# @return [String]
|
|
72
|
-
def float(cell, str='')
|
|
72
|
+
def float(cell, str = '')
|
|
73
73
|
numeric cell, str
|
|
74
74
|
end
|
|
75
75
|
|
|
@@ -85,7 +85,7 @@ module Axlsx
|
|
|
85
85
|
# @param [Cell] cell The cell that is being serialized
|
|
86
86
|
# @param [String] str The string the serialized content will be appended to.
|
|
87
87
|
# @return [String]
|
|
88
|
-
def formula_serialization(cell, str='')
|
|
88
|
+
def formula_serialization(cell, str = '')
|
|
89
89
|
str << ('t="str"><f>' << cell.clean_value.to_s.sub('=', '') << '</f>')
|
|
90
90
|
str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil?
|
|
91
91
|
end
|
|
@@ -94,7 +94,7 @@ module Axlsx
|
|
|
94
94
|
# @param [Cell] cell The cell that is being serialized
|
|
95
95
|
# @param [String] str The string the serialized content will be appended to.
|
|
96
96
|
# @return [String]
|
|
97
|
-
def array_formula_serialization(cell, str='')
|
|
97
|
+
def array_formula_serialization(cell, str = '')
|
|
98
98
|
str << ('t="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.to_s.sub('{=', '').sub(/}$/, '') << '</f>')
|
|
99
99
|
str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil?
|
|
100
100
|
end
|
|
@@ -113,7 +113,7 @@ module Axlsx
|
|
|
113
113
|
# @param [Cell] cell The cell that is being serialized
|
|
114
114
|
# @param [String] str The string the serialized content will be appended to.
|
|
115
115
|
# @return [String]
|
|
116
|
-
def string(cell, str='')
|
|
116
|
+
def string(cell, str = '')
|
|
117
117
|
if cell.is_array_formula?
|
|
118
118
|
array_formula_serialization cell, str
|
|
119
119
|
elsif cell.is_formula?
|
|
@@ -7,7 +7,6 @@ module Axlsx
|
|
|
7
7
|
# @see ConditionalFormattingRule#initialize
|
|
8
8
|
#
|
|
9
9
|
class Cfvo
|
|
10
|
-
|
|
11
10
|
include Axlsx::OptionsParser
|
|
12
11
|
include Axlsx::SerializedAttributes
|
|
13
12
|
|
|
@@ -15,7 +14,7 @@ module Axlsx
|
|
|
15
14
|
# @option options [Symbol] type The type of conditional formatting value object
|
|
16
15
|
# @option options [Boolean] gte threshold value usage indicator
|
|
17
16
|
# @option options [String] val The value of the conditional formatting object
|
|
18
|
-
def initialize(options={})
|
|
17
|
+
def initialize(options = {})
|
|
19
18
|
@gte = true
|
|
20
19
|
parse_options options
|
|
21
20
|
end
|
|
@@ -47,6 +46,7 @@ module Axlsx
|
|
|
47
46
|
# @see val
|
|
48
47
|
def val=(v)
|
|
49
48
|
raise ArgumentError, "#{v.inspect} must respond to to_s" unless v.respond_to?(:to_s)
|
|
49
|
+
|
|
50
50
|
@val = v.to_s
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
module Axlsx
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#first two items
|
|
2
|
+
# A collection of Cfvo objects that initializes with the required
|
|
3
|
+
# first two items
|
|
5
4
|
class Cfvos < SimpleTypedList
|
|
6
|
-
|
|
7
5
|
def initialize
|
|
8
6
|
super(Cfvo)
|
|
9
7
|
end
|
|
@@ -11,7 +9,7 @@ module Axlsx
|
|
|
11
9
|
# Serialize the Cfvo object
|
|
12
10
|
# @param [String] str
|
|
13
11
|
# @return [String]
|
|
14
|
-
def to_xml_string(str='')
|
|
12
|
+
def to_xml_string(str = '')
|
|
15
13
|
each { |cfvo| cfvo.to_xml_string(str) }
|
|
16
14
|
end
|
|
17
15
|
end
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
1
|
module Axlsx
|
|
3
|
-
|
|
4
2
|
# The Col class defines column attributes for columns in sheets.
|
|
5
3
|
class Col
|
|
6
|
-
|
|
7
4
|
# Maximum column width limit in MS Excel is 255 characters
|
|
8
5
|
# https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
|
|
9
6
|
MAX_WIDTH = 255
|
|
@@ -19,7 +16,7 @@ module Axlsx
|
|
|
19
16
|
# @option options [Boolean] phonetic see Col#phonetic
|
|
20
17
|
# @option options [Integer] style see Col#style
|
|
21
18
|
# @option options [Numeric] width see Col#width
|
|
22
|
-
def initialize(min, max, options={})
|
|
19
|
+
def initialize(min, max, options = {})
|
|
23
20
|
Axlsx.validate_unsigned_int(max)
|
|
24
21
|
Axlsx.validate_unsigned_int(min)
|
|
25
22
|
@min = min
|
|
@@ -90,6 +87,7 @@ module Axlsx
|
|
|
90
87
|
def outline_level=(v)
|
|
91
88
|
Axlsx.validate_unsigned_numeric(v)
|
|
92
89
|
raise ArgumentError, 'outlineLevel must be between 0 and 7' unless 0 <= v && v <= 7
|
|
90
|
+
|
|
93
91
|
@outline_level = v
|
|
94
92
|
end
|
|
95
93
|
alias :outlineLevel= :outline_level=
|
|
@@ -106,14 +104,14 @@ module Axlsx
|
|
|
106
104
|
@style = v
|
|
107
105
|
end
|
|
108
106
|
|
|
109
|
-
|
|
107
|
+
# @see Col#width
|
|
110
108
|
def width=(v)
|
|
111
109
|
# Removing this validation make a 10% difference in performance
|
|
112
110
|
# as it is called EVERY TIME A CELL IS ADDED - the proper solution
|
|
113
111
|
# is to only set this if a calculated value is greated than the
|
|
114
112
|
# current @width value.
|
|
115
113
|
# TODO!!!
|
|
116
|
-
#Axlsx.validate_unsigned_numeric(v) unless v == nil
|
|
114
|
+
# Axlsx.validate_unsigned_numeric(v) unless v == nil
|
|
117
115
|
@custom_width = @best_fit = v != nil
|
|
118
116
|
@width = v.nil? ? v : [v, MAX_WIDTH].min
|
|
119
117
|
end
|
|
@@ -140,6 +138,5 @@ module Axlsx
|
|
|
140
138
|
def to_xml_string(str = '')
|
|
141
139
|
serialized_tag('col', str)
|
|
142
140
|
end
|
|
143
|
-
|
|
144
141
|
end
|
|
145
142
|
end
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
module Axlsx
|
|
2
|
-
|
|
3
2
|
# A collection of Brake objects.
|
|
4
|
-
# Please do not use this class directly. Instead use
|
|
3
|
+
# Please do not use this class directly. Instead use
|
|
5
4
|
# Worksheet#add_break
|
|
6
5
|
class ColBreaks < SimpleTypedList
|
|
7
|
-
|
|
8
6
|
# Instantiates a new list restricted to Break types
|
|
9
7
|
def initialize
|
|
10
8
|
super Break
|
|
@@ -12,7 +10,7 @@ module Axlsx
|
|
|
12
10
|
|
|
13
11
|
# A column break specific helper for adding a break.
|
|
14
12
|
# @param [Hash] options A list of options to pass into the Break object
|
|
15
|
-
# The max and man options are fixed, however any other valid option for
|
|
13
|
+
# The max and man options are fixed, however any other valid option for
|
|
16
14
|
# Break will be passed to the created break object.
|
|
17
15
|
# @see Break
|
|
18
16
|
def add_break(options)
|
|
@@ -25,8 +23,9 @@ module Axlsx
|
|
|
25
23
|
# <colBreaks count="1" manualBreakCount="1">
|
|
26
24
|
# <brk id="3" max="1048575" man="1"/>
|
|
27
25
|
# </colBreaks>
|
|
28
|
-
def to_xml_string(str='')
|
|
26
|
+
def to_xml_string(str = '')
|
|
29
27
|
return if empty?
|
|
28
|
+
|
|
30
29
|
str << ('<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">')
|
|
31
30
|
each { |brk| brk.to_xml_string(str) }
|
|
32
31
|
str << '</colBreaks>'
|