caxlsx 3.4.1 → 4.1.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 +24 -1
- data/README.md +9 -11
- data/Rakefile +7 -5
- data/examples/generate.rb +3 -1
- data/lib/axlsx/content_type/abstract_content_type.rb +12 -4
- data/lib/axlsx/content_type/content_type.rb +8 -6
- data/lib/axlsx/content_type/default.rb +7 -2
- data/lib/axlsx/content_type/override.rb +7 -2
- data/lib/axlsx/doc_props/app.rb +95 -26
- data/lib/axlsx/doc_props/core.rb +8 -6
- data/lib/axlsx/drawing/area_chart.rb +10 -8
- data/lib/axlsx/drawing/area_series.rb +20 -12
- data/lib/axlsx/drawing/ax_data_source.rb +2 -0
- data/lib/axlsx/drawing/axes.rb +6 -4
- data/lib/axlsx/drawing/axis.rb +42 -22
- data/lib/axlsx/drawing/bar_3D_chart.rb +14 -12
- data/lib/axlsx/drawing/bar_chart.rb +13 -11
- data/lib/axlsx/drawing/bar_series.rb +20 -9
- data/lib/axlsx/drawing/bubble_chart.rb +6 -4
- data/lib/axlsx/drawing/bubble_series.rb +8 -6
- data/lib/axlsx/drawing/cat_axis.rb +29 -12
- data/lib/axlsx/drawing/chart.rb +46 -20
- data/lib/axlsx/drawing/d_lbls.rb +10 -8
- data/lib/axlsx/drawing/drawing.rb +59 -56
- data/lib/axlsx/drawing/graphic_frame.rb +6 -4
- data/lib/axlsx/drawing/hyperlink.rb +19 -8
- data/lib/axlsx/drawing/line_3D_chart.rb +7 -5
- data/lib/axlsx/drawing/line_chart.rb +10 -8
- data/lib/axlsx/drawing/line_series.rb +20 -12
- data/lib/axlsx/drawing/marker.rb +24 -7
- data/lib/axlsx/drawing/num_data.rb +9 -7
- data/lib/axlsx/drawing/num_data_source.rb +9 -7
- data/lib/axlsx/drawing/num_val.rb +7 -5
- data/lib/axlsx/drawing/one_cell_anchor.rb +13 -5
- data/lib/axlsx/drawing/pic.rb +26 -15
- data/lib/axlsx/drawing/picture_locking.rb +3 -1
- data/lib/axlsx/drawing/pie_3D_chart.rb +6 -4
- data/lib/axlsx/drawing/pie_chart.rb +36 -0
- data/lib/axlsx/drawing/pie_series.rb +23 -9
- data/lib/axlsx/drawing/scaling.rb +25 -9
- data/lib/axlsx/drawing/scatter_chart.rb +7 -5
- data/lib/axlsx/drawing/scatter_series.rb +14 -12
- data/lib/axlsx/drawing/ser_axis.rb +13 -5
- data/lib/axlsx/drawing/series.rb +13 -5
- data/lib/axlsx/drawing/series_title.rb +6 -4
- data/lib/axlsx/drawing/str_data.rb +7 -5
- data/lib/axlsx/drawing/str_val.rb +6 -4
- data/lib/axlsx/drawing/title.rb +13 -14
- data/lib/axlsx/drawing/two_cell_anchor.rb +4 -2
- data/lib/axlsx/drawing/val_axis.rb +4 -2
- data/lib/axlsx/drawing/view_3D.rb +16 -8
- data/lib/axlsx/drawing/vml_drawing.rb +18 -16
- data/lib/axlsx/drawing/vml_shape.rb +24 -22
- data/lib/axlsx/package.rb +73 -67
- data/lib/axlsx/rels/relationship.rb +21 -6
- data/lib/axlsx/rels/relationships.rb +6 -4
- data/lib/axlsx/stylesheet/border.rb +15 -4
- data/lib/axlsx/stylesheet/border_pr.rb +19 -6
- data/lib/axlsx/stylesheet/cell_alignment.rb +41 -10
- data/lib/axlsx/stylesheet/cell_protection.rb +12 -3
- data/lib/axlsx/stylesheet/cell_style.rb +33 -8
- data/lib/axlsx/stylesheet/color.rb +15 -7
- data/lib/axlsx/stylesheet/dxf.rb +34 -9
- data/lib/axlsx/stylesheet/fill.rb +7 -2
- data/lib/axlsx/stylesheet/font.rb +65 -17
- data/lib/axlsx/stylesheet/gradient_fill.rb +12 -4
- data/lib/axlsx/stylesheet/gradient_stop.rb +14 -5
- data/lib/axlsx/stylesheet/num_fmt.rb +14 -10
- data/lib/axlsx/stylesheet/pattern_fill.rb +18 -5
- data/lib/axlsx/stylesheet/styles.rb +124 -82
- data/lib/axlsx/stylesheet/table_style.rb +19 -6
- data/lib/axlsx/stylesheet/table_style_element.rb +15 -4
- data/lib/axlsx/stylesheet/table_styles.rb +14 -5
- data/lib/axlsx/stylesheet/xf.rb +73 -18
- data/lib/axlsx/util/accessors.rb +10 -6
- data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
- data/lib/axlsx/util/constants.rb +117 -104
- data/lib/axlsx/util/mime_type_utils.rb +3 -5
- data/lib/axlsx/util/options_parser.rb +3 -1
- data/lib/axlsx/util/serialized_attributes.rb +42 -17
- data/lib/axlsx/util/simple_typed_list.rb +47 -47
- data/lib/axlsx/util/storage.rb +11 -10
- data/lib/axlsx/util/validators.rb +101 -41
- data/lib/axlsx/util/zip_command.rb +10 -10
- data/lib/axlsx/version.rb +3 -1
- data/lib/axlsx/workbook/defined_name.rb +6 -4
- data/lib/axlsx/workbook/defined_names.rb +4 -2
- data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
- data/lib/axlsx/workbook/workbook.rb +94 -79
- data/lib/axlsx/workbook/workbook_view.rb +3 -1
- data/lib/axlsx/workbook/workbook_views.rb +4 -2
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -5
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +11 -7
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
- data/lib/axlsx/workbook/worksheet/border_creator.rb +5 -3
- data/lib/axlsx/workbook/worksheet/break.rb +3 -1
- data/lib/axlsx/workbook/worksheet/cell.rb +83 -64
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
- data/lib/axlsx/workbook/worksheet/cfvo.rb +11 -3
- data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -1
- data/lib/axlsx/workbook/worksheet/col.rb +5 -3
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +6 -4
- data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
- data/lib/axlsx/workbook/worksheet/cols.rb +4 -2
- data/lib/axlsx/workbook/worksheet/comment.rb +8 -6
- data/lib/axlsx/workbook/worksheet/comments.rb +6 -4
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +16 -5
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +73 -16
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +4 -2
- data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
- data/lib/axlsx/workbook/worksheet/data_validation.rb +69 -28
- data/lib/axlsx/workbook/worksheet/data_validations.rb +4 -2
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +7 -5
- data/lib/axlsx/workbook/worksheet/dimension.rb +4 -2
- data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -2
- data/lib/axlsx/workbook/worksheet/icon_set.rb +38 -9
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +6 -6
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/page_margins.rb +39 -11
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -4
- data/lib/axlsx/workbook/worksheet/page_setup.rb +34 -9
- data/lib/axlsx/workbook/worksheet/pane.rb +17 -9
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +20 -19
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -6
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -1
- data/lib/axlsx/workbook/worksheet/print_options.rb +3 -1
- data/lib/axlsx/workbook/worksheet/protected_range.rb +3 -1
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +6 -4
- data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +46 -24
- data/lib/axlsx/workbook/worksheet/row.rb +11 -9
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +7 -5
- data/lib/axlsx/workbook/worksheet/selection.rb +15 -7
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +6 -2
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +8 -4
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +11 -9
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +38 -15
- data/lib/axlsx/workbook/worksheet/table.rb +9 -7
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +4 -2
- data/lib/axlsx/workbook/worksheet/tables.rb +4 -2
- data/lib/axlsx/workbook/worksheet/worksheet.rb +56 -39
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -2
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +8 -2
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +7 -5
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +5 -3
- data/lib/axlsx.rb +56 -42
- data/lib/caxlsx.rb +3 -1
- metadata +39 -71
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# The GradientStop object represents a color point in a gradient.
|
3
5
|
# @see Open Office XML Part 1 §18.8.24
|
@@ -20,16 +22,23 @@ module Axlsx
|
|
20
22
|
end
|
21
23
|
|
22
24
|
# @see color
|
23
|
-
def color=(v)
|
25
|
+
def color=(v)
|
26
|
+
DataTypeValidator.validate "GradientStop.color", Color, v
|
27
|
+
@color = v
|
28
|
+
end
|
29
|
+
|
24
30
|
# @see position
|
25
|
-
def position=(v)
|
31
|
+
def position=(v)
|
32
|
+
DataTypeValidator.validate "GradientStop.position", Float, v, ->(arg) { arg >= 0 && arg <= 1 }
|
33
|
+
@position = v
|
34
|
+
end
|
26
35
|
|
27
36
|
# Serializes the object
|
28
37
|
# @param [String] str
|
29
38
|
# @return [String]
|
30
|
-
def to_xml_string(str = '')
|
31
|
-
str <<
|
32
|
-
|
39
|
+
def to_xml_string(str = +'')
|
40
|
+
str << '<stop position="' << position.to_s << '">'
|
41
|
+
color.to_xml_string(str)
|
33
42
|
str << '</stop>'
|
34
43
|
end
|
35
44
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A NumFmt object defines an identifier and formatting code for data in cells.
|
3
5
|
# @note The recommended way to manage styles is Styles#add_style
|
@@ -18,7 +20,7 @@ module Axlsx
|
|
18
20
|
serializable_attributes :formatCode, :numFmtId
|
19
21
|
|
20
22
|
# @return [String] The formatting to use for this number format.
|
21
|
-
# @see
|
23
|
+
# @see https://support.microsoft.com/kb/264372
|
22
24
|
attr_reader :formatCode
|
23
25
|
|
24
26
|
# @return [Integer] An unsigned integer referencing a standard or custom number format.
|
@@ -59,25 +61,27 @@ module Axlsx
|
|
59
61
|
attr_reader :numFmtId
|
60
62
|
|
61
63
|
# @see numFmtId
|
62
|
-
def numFmtId=(v)
|
64
|
+
def numFmtId=(v)
|
65
|
+
Axlsx.validate_unsigned_int v
|
66
|
+
@numFmtId = v
|
67
|
+
end
|
63
68
|
|
64
69
|
# @see formatCode
|
65
|
-
def formatCode=(v)
|
70
|
+
def formatCode=(v)
|
71
|
+
Axlsx.validate_string v
|
72
|
+
@formatCode = v
|
73
|
+
end
|
66
74
|
|
67
75
|
# Serializes the object
|
68
76
|
# @param [String] str
|
69
77
|
# @return [String]
|
70
|
-
def to_xml_string(str = '')
|
78
|
+
def to_xml_string(str = +'')
|
71
79
|
serialized_tag('numFmt', str)
|
72
80
|
end
|
73
81
|
|
74
82
|
# Override to avoid removing underscores
|
75
|
-
def serialized_attributes(str = '', additional_attributes = {})
|
76
|
-
|
77
|
-
attributes.each do |key, value|
|
78
|
-
str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.booleanize(value)}\" "
|
79
|
-
end
|
80
|
-
str
|
83
|
+
def serialized_attributes(str = +'', additional_attributes = {})
|
84
|
+
super(str, additional_attributes, false)
|
81
85
|
end
|
82
86
|
end
|
83
87
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A PatternFill is the pattern and solid fill styling for a cell.
|
3
5
|
# @note The recommended way to manage styles is with Styles#add_style
|
@@ -47,17 +49,28 @@ module Axlsx
|
|
47
49
|
attr_reader :patternType
|
48
50
|
|
49
51
|
# @see fgColor
|
50
|
-
def fgColor=(v)
|
52
|
+
def fgColor=(v)
|
53
|
+
DataTypeValidator.validate "PatternFill.fgColor", Color, v
|
54
|
+
@fgColor = v
|
55
|
+
end
|
56
|
+
|
51
57
|
# @see bgColor
|
52
|
-
def bgColor=(v)
|
58
|
+
def bgColor=(v)
|
59
|
+
DataTypeValidator.validate "PatternFill.bgColor", Color, v
|
60
|
+
@bgColor = v
|
61
|
+
end
|
62
|
+
|
53
63
|
# @see patternType
|
54
|
-
def patternType=(v)
|
64
|
+
def patternType=(v)
|
65
|
+
Axlsx.validate_pattern_type v
|
66
|
+
@patternType = v
|
67
|
+
end
|
55
68
|
|
56
69
|
# Serializes the object
|
57
70
|
# @param [String] str
|
58
71
|
# @return [String]
|
59
|
-
def to_xml_string(str = '')
|
60
|
-
str <<
|
72
|
+
def to_xml_string(str = +'')
|
73
|
+
str << '<patternFill patternType="' << patternType.to_s << '">'
|
61
74
|
if fgColor.is_a?(Color)
|
62
75
|
fgColor.to_xml_string str, "fgColor"
|
63
76
|
end
|
@@ -1,21 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
|
-
require 'axlsx/stylesheet/border
|
3
|
-
require 'axlsx/stylesheet/border_pr
|
4
|
-
require 'axlsx/stylesheet/cell_alignment
|
5
|
-
require 'axlsx/stylesheet/cell_style
|
6
|
-
require 'axlsx/stylesheet/color
|
7
|
-
require 'axlsx/stylesheet/fill
|
8
|
-
require 'axlsx/stylesheet/font
|
9
|
-
require 'axlsx/stylesheet/gradient_fill
|
10
|
-
require 'axlsx/stylesheet/gradient_stop
|
11
|
-
require 'axlsx/stylesheet/num_fmt
|
12
|
-
require 'axlsx/stylesheet/pattern_fill
|
13
|
-
require 'axlsx/stylesheet/table_style
|
14
|
-
require 'axlsx/stylesheet/table_styles
|
15
|
-
require 'axlsx/stylesheet/table_style_element
|
16
|
-
require 'axlsx/stylesheet/dxf
|
17
|
-
require 'axlsx/stylesheet/xf
|
18
|
-
require 'axlsx/stylesheet/cell_protection
|
4
|
+
require 'axlsx/stylesheet/border'
|
5
|
+
require 'axlsx/stylesheet/border_pr'
|
6
|
+
require 'axlsx/stylesheet/cell_alignment'
|
7
|
+
require 'axlsx/stylesheet/cell_style'
|
8
|
+
require 'axlsx/stylesheet/color'
|
9
|
+
require 'axlsx/stylesheet/fill'
|
10
|
+
require 'axlsx/stylesheet/font'
|
11
|
+
require 'axlsx/stylesheet/gradient_fill'
|
12
|
+
require 'axlsx/stylesheet/gradient_stop'
|
13
|
+
require 'axlsx/stylesheet/num_fmt'
|
14
|
+
require 'axlsx/stylesheet/pattern_fill'
|
15
|
+
require 'axlsx/stylesheet/table_style'
|
16
|
+
require 'axlsx/stylesheet/table_styles'
|
17
|
+
require 'axlsx/stylesheet/table_style_element'
|
18
|
+
require 'axlsx/stylesheet/dxf'
|
19
|
+
require 'axlsx/stylesheet/xf'
|
20
|
+
require 'axlsx/stylesheet/cell_protection'
|
19
21
|
|
20
22
|
# The Styles class manages worksheet styles
|
21
23
|
# In addition to creating the require style objects for a valid xlsx package, this class provides the key mechanism for adding styles to your workbook, and safely applying them to the cells of your worksheet.
|
@@ -108,14 +110,14 @@ module Axlsx
|
|
108
110
|
# @see Styles#add_style
|
109
111
|
attr_reader :dxfs
|
110
112
|
|
111
|
-
# The collection of table styles that will be available to the user in the
|
113
|
+
# The collection of table styles that will be available to the user in the Excel UI
|
112
114
|
# @return [SimpleTypedList]
|
113
115
|
# @note The recommended way to manage styles is with add_style
|
114
116
|
# @see Styles#add_style
|
115
117
|
attr_reader :tableStyles
|
116
118
|
|
117
119
|
# Creates a new Styles object and prepopulates it with the requires objects to generate a valid package style part.
|
118
|
-
def initialize
|
120
|
+
def initialize
|
119
121
|
load_default_styles
|
120
122
|
end
|
121
123
|
|
@@ -263,12 +265,12 @@ module Axlsx
|
|
263
265
|
alignment = parse_alignment_options options
|
264
266
|
protection = parse_protection_options options
|
265
267
|
|
266
|
-
case options[:type]
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
268
|
+
style = case options[:type]
|
269
|
+
when :dxf
|
270
|
+
Dxf.new fill: fill, font: font, numFmt: numFmt, border: border, alignment: alignment, protection: protection
|
271
|
+
else
|
272
|
+
Xf.new fillId: fill || 0, fontId: font || 0, numFmtId: numFmt || 0, borderId: border || 0, alignment: alignment, protection: protection, applyFill: !fill.nil?, applyFont: !font.nil?, applyNumberFormat: !numFmt.nil?, applyBorder: !border.nil?, applyAlignment: !alignment.nil?, applyProtection: !protection.nil?
|
273
|
+
end
|
272
274
|
|
273
275
|
if options[:type] == :xf
|
274
276
|
xf_index = (cellXfs << style)
|
@@ -276,11 +278,9 @@ module Axlsx
|
|
276
278
|
# Add styles to style_index cache for re-use
|
277
279
|
style_index[xf_index] = raw_style
|
278
280
|
|
279
|
-
|
281
|
+
xf_index
|
280
282
|
else
|
281
|
-
|
282
|
-
|
283
|
-
return dxf_index
|
283
|
+
dxfs << style
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
@@ -327,25 +327,62 @@ module Axlsx
|
|
327
327
|
|
328
328
|
Axlsx.instance_values_for(fonts.first).each do |key, value|
|
329
329
|
# Thanks for that 1.8.7 - cant do a simple merge...
|
330
|
-
options[key.to_sym] = value unless options.
|
330
|
+
options[key.to_sym] = value unless options.key?(key.to_sym)
|
331
331
|
end
|
332
332
|
font = Font.new(options)
|
333
|
-
font.color = Color.new(:
|
333
|
+
font.color = Color.new(rgb: options[:fg_color]) if options[:fg_color]
|
334
334
|
font.name = options[:font_name] if options[:font_name]
|
335
335
|
options[:type] == :dxf ? font : fonts << font
|
336
336
|
end
|
337
337
|
|
338
338
|
# parses add_style options for fills. If the options hash contains :type => :dxf we return a Fill object. If not, we return the index of the fill after being added to the fills collection.
|
339
|
-
# @note noop
|
340
|
-
# @option options [String] bg_color The rgb color to apply to the fill
|
339
|
+
# @note noop unless at least one of the documented attributes is specified in options
|
340
|
+
# @option options [String] bg_color The rgb color to apply to the fill. An alias for pattern_bg_color if you need only a solid background
|
341
|
+
# @option options [String] pattern_type The fill pattern to apply to the fill
|
342
|
+
# @option options [String] pattern_bg_color The rgb color to apply to the fill as the first color
|
343
|
+
# @option options [String] pattern_fg_color The rgb color to apply to the fill as the second color
|
341
344
|
# @return [Fill|Integer]
|
342
345
|
def parse_fill_options(options = {})
|
343
|
-
return unless options[:bg_color]
|
346
|
+
return unless options[:bg_color] || options[:pattern_type] || options[:pattern_bg_color] || options[:pattern_fg_color]
|
344
347
|
|
345
|
-
|
348
|
+
pattern_type = options[:pattern_type] || :solid
|
346
349
|
dxf = options[:type] == :dxf
|
347
|
-
|
348
|
-
|
350
|
+
|
351
|
+
pattern_options = {
|
352
|
+
patternType: pattern_type
|
353
|
+
}
|
354
|
+
|
355
|
+
if options[:pattern_bg_color] && options[:bg_color]
|
356
|
+
warn 'Both `bg_color` and `pattern_bg_color` got defined. To get a solid background without defining it in `patter_type`, use only `bg_color`, otherwise use only `pattern_bg_color` to avoid confusion.'
|
357
|
+
end
|
358
|
+
|
359
|
+
bg_color = options[:pattern_bg_color] || options[:bg_color]
|
360
|
+
fg_color = options[:pattern_fg_color]
|
361
|
+
|
362
|
+
# Both bgColor and fgColor happens to configure the background of the cell.
|
363
|
+
# One of them sets the "background" of the cell, while the other one is
|
364
|
+
# responsibe for the "pattern" of the cell. When you pick "solid" pattern for
|
365
|
+
# a normal xf style, then it's a rectangle covering all bgColor with fgColor,
|
366
|
+
# which means we need to to set the given background color to fgColor as well.
|
367
|
+
# For some reason I wasn't able find, it works the opposite for dxf styles
|
368
|
+
# (differential formatting records), so to get the expected color, we need
|
369
|
+
# to put it into bgColor. We only need these cross-assignments when using
|
370
|
+
# "solid" pattern and the user provided only one color to get the least
|
371
|
+
# amount of surprise
|
372
|
+
|
373
|
+
if bg_color
|
374
|
+
pattern_options[:bgColor] = Color.new(rgb: bg_color)
|
375
|
+
elsif pattern_type == :solid && fg_color
|
376
|
+
pattern_options[:bgColor] = Color.new(rgb: fg_color)
|
377
|
+
end
|
378
|
+
|
379
|
+
if fg_color
|
380
|
+
pattern_options[:fgColor] = Color.new(rgb: fg_color)
|
381
|
+
elsif pattern_type == :solid && bg_color
|
382
|
+
pattern_options[:fgColor] = Color.new(rgb: bg_color)
|
383
|
+
end
|
384
|
+
|
385
|
+
pattern = PatternFill.new(pattern_options)
|
349
386
|
fill = Fill.new(pattern)
|
350
387
|
dxf ? fill : fills << fill
|
351
388
|
end
|
@@ -364,13 +401,13 @@ module Axlsx
|
|
364
401
|
# { :border => { :style => :thick, :color => "FFFF0000", :edges => [:top, :bottom] }
|
365
402
|
# @return [Border|Integer]
|
366
403
|
def parse_border_options(options = {})
|
367
|
-
if options[:border].nil? && Border::EDGES.all? { |x| options["border_#{x}"
|
404
|
+
if options[:border].nil? && Border::EDGES.all? { |x| options[:"border_#{x}"].nil? }
|
368
405
|
return nil
|
369
406
|
end
|
370
407
|
|
371
408
|
if options[:border].is_a?(Integer)
|
372
409
|
if options[:border] >= borders.size
|
373
|
-
raise ArgumentError, (ERR_INVALID_BORDER_ID
|
410
|
+
raise ArgumentError, format(ERR_INVALID_BORDER_ID, options[:border])
|
374
411
|
end
|
375
412
|
|
376
413
|
if options[:type] == :dxf
|
@@ -380,9 +417,9 @@ module Axlsx
|
|
380
417
|
end
|
381
418
|
end
|
382
419
|
|
383
|
-
validate_border_hash =
|
384
|
-
|
385
|
-
raise ArgumentError, (ERR_INVALID_BORDER_OPTIONS
|
420
|
+
validate_border_hash = lambda { |val|
|
421
|
+
unless val.key?(:style) && val.key?(:color)
|
422
|
+
raise ArgumentError, format(ERR_INVALID_BORDER_OPTIONS, options[:border])
|
386
423
|
end
|
387
424
|
}
|
388
425
|
|
@@ -390,28 +427,26 @@ module Axlsx
|
|
390
427
|
|
391
428
|
if options[:border].nil?
|
392
429
|
base_border_opts = {}
|
393
|
-
|
394
|
-
|
395
|
-
borders_array += options[:border]
|
430
|
+
elsif options[:border].is_a?(Array)
|
431
|
+
borders_array += options[:border]
|
396
432
|
|
397
|
-
|
433
|
+
base_border_opts = {}
|
398
434
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
end
|
435
|
+
options[:border].each do |b_opts|
|
436
|
+
if b_opts[:edges].nil?
|
437
|
+
base_border_opts = base_border_opts.merge(b_opts)
|
403
438
|
end
|
404
|
-
|
405
|
-
|
439
|
+
end
|
440
|
+
else
|
441
|
+
borders_array << options[:border]
|
406
442
|
|
407
|
-
|
443
|
+
base_border_opts = options[:border]
|
408
444
|
|
409
|
-
|
410
|
-
end
|
445
|
+
validate_border_hash.call(base_border_opts)
|
411
446
|
end
|
412
447
|
|
413
448
|
Border::EDGES.each do |edge|
|
414
|
-
val = options["border_#{edge}"
|
449
|
+
val = options[:"border_#{edge}"]
|
415
450
|
|
416
451
|
if val
|
417
452
|
borders_array << val.merge(edges: [edge])
|
@@ -432,8 +467,8 @@ module Axlsx
|
|
432
467
|
end
|
433
468
|
end
|
434
469
|
|
435
|
-
if options["border_#{edge}"
|
436
|
-
edge_b_opts = edge_b_opts.merge(options["border_#{edge}"
|
470
|
+
if options[:"border_#{edge}"]
|
471
|
+
edge_b_opts = edge_b_opts.merge(options[:"border_#{edge}"])
|
437
472
|
skip_edge = false
|
438
473
|
end
|
439
474
|
|
@@ -441,23 +476,23 @@ module Axlsx
|
|
441
476
|
next
|
442
477
|
end
|
443
478
|
|
444
|
-
|
479
|
+
unless edge_b_opts.empty?
|
445
480
|
if base_border_opts.empty?
|
446
481
|
validate_border_hash.call(edge_b_opts)
|
447
482
|
end
|
448
483
|
|
449
484
|
border.prs << BorderPr.new({
|
450
|
-
:
|
451
|
-
:
|
452
|
-
:
|
485
|
+
name: edge,
|
486
|
+
style: edge_b_opts[:style],
|
487
|
+
color: Color.new(rgb: edge_b_opts[:color])
|
453
488
|
})
|
454
489
|
end
|
455
490
|
end
|
456
491
|
|
457
492
|
if options[:type] == :dxf
|
458
|
-
|
493
|
+
border
|
459
494
|
else
|
460
|
-
|
495
|
+
borders << border
|
461
496
|
end
|
462
497
|
end
|
463
498
|
|
@@ -472,9 +507,14 @@ module Axlsx
|
|
472
507
|
# When the type is :dxf we always need to create a new numFmt object
|
473
508
|
if options[:format_code] || options[:type] == :dxf
|
474
509
|
# If this is a standard xf we pull from numFmts the highest current and increment for num_fmt
|
475
|
-
options[:num_fmt] ||= (@numFmts.map
|
476
|
-
numFmt = NumFmt.new(:
|
477
|
-
options[:type] == :dxf
|
510
|
+
options[:num_fmt] ||= (@numFmts.map(&:numFmtId).max + 1) if options[:type] != :dxf
|
511
|
+
numFmt = NumFmt.new(numFmtId: options[:num_fmt] || 0, formatCode: options[:format_code].to_s)
|
512
|
+
if options[:type] == :dxf
|
513
|
+
numFmt
|
514
|
+
else
|
515
|
+
numFmts << numFmt
|
516
|
+
numFmt.numFmtId
|
517
|
+
end
|
478
518
|
else
|
479
519
|
options[:num_fmt]
|
480
520
|
end
|
@@ -483,8 +523,8 @@ module Axlsx
|
|
483
523
|
# Serializes the object
|
484
524
|
# @param [String] str
|
485
525
|
# @return [String]
|
486
|
-
def to_xml_string(str = '')
|
487
|
-
str <<
|
526
|
+
def to_xml_string(str = +'')
|
527
|
+
str << '<styleSheet xmlns="' << XML_NS << '">'
|
488
528
|
instance_vals = Axlsx.instance_values_for(self)
|
489
529
|
[:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
|
490
530
|
instance_vals[key.to_s].to_xml_string(str) unless instance_vals[key.to_s].nil?
|
@@ -498,46 +538,48 @@ module Axlsx
|
|
498
538
|
# Axlsx::STYLE_THIN_BORDER
|
499
539
|
def load_default_styles
|
500
540
|
@numFmts = SimpleTypedList.new NumFmt, 'numFmts'
|
501
|
-
@numFmts << NumFmt.new(:
|
502
|
-
@numFmts << NumFmt.new(:
|
541
|
+
@numFmts << NumFmt.new(numFmtId: NUM_FMT_YYYYMMDD, formatCode: "yyyy/mm/dd")
|
542
|
+
@numFmts << NumFmt.new(numFmtId: NUM_FMT_YYYYMMDDHHMMSS, formatCode: "yyyy/mm/dd hh:mm:ss")
|
503
543
|
|
504
544
|
@numFmts.lock
|
505
545
|
|
506
546
|
@fonts = SimpleTypedList.new Font, 'fonts'
|
507
|
-
@fonts << Font.new(:
|
547
|
+
@fonts << Font.new(name: "Arial", sz: 11, family: 1)
|
508
548
|
@fonts.lock
|
509
549
|
|
510
550
|
@fills = SimpleTypedList.new Fill, 'fills'
|
511
|
-
@fills << Fill.new(Axlsx::PatternFill.new(:
|
512
|
-
@fills << Fill.new(Axlsx::PatternFill.new(:
|
551
|
+
@fills << Fill.new(Axlsx::PatternFill.new(patternType: :none))
|
552
|
+
@fills << Fill.new(Axlsx::PatternFill.new(patternType: :gray125))
|
513
553
|
@fills.lock
|
514
554
|
|
515
555
|
@borders = SimpleTypedList.new Border, 'borders'
|
516
556
|
@borders << Border.new
|
517
557
|
black_border = Border.new
|
518
558
|
[:left, :right, :top, :bottom].each do |item|
|
519
|
-
black_border.prs << BorderPr.new(:
|
559
|
+
black_border.prs << BorderPr.new(name: item, style: :thin, color: Color.new(rgb: "FF000000"))
|
520
560
|
end
|
521
561
|
@borders << black_border
|
522
562
|
@borders.lock
|
523
563
|
|
524
564
|
@cellStyleXfs = SimpleTypedList.new Xf, "cellStyleXfs"
|
525
|
-
@cellStyleXfs << Xf.new(:
|
565
|
+
@cellStyleXfs << Xf.new(borderId: 0, numFmtId: 0, fontId: 0, fillId: 0)
|
526
566
|
@cellStyleXfs.lock
|
527
567
|
|
528
568
|
@cellStyles = SimpleTypedList.new CellStyle, 'cellStyles'
|
529
|
-
@cellStyles << CellStyle.new(:
|
569
|
+
@cellStyles << CellStyle.new(name: "Normal", builtinId: 0, xfId: 0)
|
530
570
|
@cellStyles.lock
|
531
571
|
|
532
572
|
@cellXfs = SimpleTypedList.new Xf, "cellXfs"
|
533
|
-
@cellXfs << Xf.new(:
|
534
|
-
@cellXfs << Xf.new(:
|
573
|
+
@cellXfs << Xf.new(borderId: 0, xfId: 0, numFmtId: 0, fontId: 0, fillId: 0)
|
574
|
+
@cellXfs << Xf.new(borderId: 1, xfId: 0, numFmtId: 0, fontId: 0, fillId: 0)
|
535
575
|
# default date formatting
|
536
|
-
@cellXfs << Xf.new(:
|
576
|
+
@cellXfs << Xf.new(borderId: 0, xfId: 0, numFmtId: 14, fontId: 0, fillId: 0, applyNumberFormat: 1)
|
537
577
|
@cellXfs.lock
|
538
578
|
|
539
|
-
@dxfs = SimpleTypedList.new(Dxf, "dxfs")
|
540
|
-
@
|
579
|
+
@dxfs = SimpleTypedList.new(Dxf, "dxfs")
|
580
|
+
@dxfs.lock
|
581
|
+
@tableStyles = TableStyles.new(defaultTableStyle: "TableStyleMedium9", defaultPivotStyle: "PivotStyleLight16")
|
582
|
+
@tableStyles.lock
|
541
583
|
end
|
542
584
|
end
|
543
585
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# A single table style definition and is a collection for tableStyleElements
|
3
5
|
# @note Table are not supported in this version and only the defaults required for a valid workbook are created.
|
@@ -13,7 +15,7 @@ module Axlsx
|
|
13
15
|
def initialize(name, options = {})
|
14
16
|
self.name = name
|
15
17
|
parse_options options
|
16
|
-
super
|
18
|
+
super(TableStyleElement)
|
17
19
|
end
|
18
20
|
|
19
21
|
serializable_attributes :name, :pivot, :table
|
@@ -31,18 +33,29 @@ module Axlsx
|
|
31
33
|
attr_reader :table
|
32
34
|
|
33
35
|
# @see name
|
34
|
-
def name=(v)
|
36
|
+
def name=(v)
|
37
|
+
Axlsx.validate_string v
|
38
|
+
@name = v
|
39
|
+
end
|
40
|
+
|
35
41
|
# @see pivot
|
36
|
-
def pivot=(v)
|
42
|
+
def pivot=(v)
|
43
|
+
Axlsx.validate_boolean v
|
44
|
+
@pivot = v
|
45
|
+
end
|
46
|
+
|
37
47
|
# @see table
|
38
|
-
def table=(v)
|
48
|
+
def table=(v)
|
49
|
+
Axlsx.validate_boolean v
|
50
|
+
@table = v
|
51
|
+
end
|
39
52
|
|
40
53
|
# Serializes the object
|
41
54
|
# @param [String] str
|
42
55
|
# @return [String]
|
43
|
-
def to_xml_string(str = '')
|
56
|
+
def to_xml_string(str = +'')
|
44
57
|
str << '<tableStyle '
|
45
|
-
serialized_attributes str, { :
|
58
|
+
serialized_attributes str, { count: size }
|
46
59
|
str << '>'
|
47
60
|
each { |table_style_el| table_style_el.to_xml_string(str) }
|
48
61
|
str << '</tableStyle>'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# an element of style that belongs to a table style.
|
3
5
|
# @note tables and table styles are not supported in this version. This class exists in preparation for that support.
|
@@ -56,18 +58,27 @@ module Axlsx
|
|
56
58
|
attr_reader :dxfId
|
57
59
|
|
58
60
|
# @see type
|
59
|
-
def type=(v)
|
61
|
+
def type=(v)
|
62
|
+
Axlsx.validate_table_element_type v
|
63
|
+
@type = v
|
64
|
+
end
|
60
65
|
|
61
66
|
# @see size
|
62
|
-
def size=(v)
|
67
|
+
def size=(v)
|
68
|
+
Axlsx.validate_unsigned_int v
|
69
|
+
@size = v
|
70
|
+
end
|
63
71
|
|
64
72
|
# @see dxfId
|
65
|
-
def dxfId=(v)
|
73
|
+
def dxfId=(v)
|
74
|
+
Axlsx.validate_unsigned_int v
|
75
|
+
@dxfId = v
|
76
|
+
end
|
66
77
|
|
67
78
|
# Serializes the object
|
68
79
|
# @param [String] str
|
69
80
|
# @return [String]
|
70
|
-
def to_xml_string(str = '')
|
81
|
+
def to_xml_string(str = +'')
|
71
82
|
serialized_tag('tableStyleElement', str)
|
72
83
|
end
|
73
84
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
4
|
# TableStyles represents a collection of style definitions for table styles and pivot table styles.
|
3
5
|
# @note Support for custom table styles does not exist in this version. Many of the classes required are defined in preparation for future release. Please do not attempt to add custom table styles.
|
@@ -10,7 +12,7 @@ module Axlsx
|
|
10
12
|
def initialize(options = {})
|
11
13
|
@defaultTableStyle = options[:defaultTableStyle] || "TableStyleMedium9"
|
12
14
|
@defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
|
13
|
-
super
|
15
|
+
super(TableStyle)
|
14
16
|
end
|
15
17
|
|
16
18
|
serializable_attributes :defaultTableStyle, :defaultPivotStyle
|
@@ -24,16 +26,23 @@ module Axlsx
|
|
24
26
|
attr_reader :defaultPivotStyle
|
25
27
|
|
26
28
|
# @see defaultTableStyle
|
27
|
-
def defaultTableStyle=(v)
|
29
|
+
def defaultTableStyle=(v)
|
30
|
+
Axlsx.validate_string(v)
|
31
|
+
@defaultTableStyle = v
|
32
|
+
end
|
33
|
+
|
28
34
|
# @see defaultPivotStyle
|
29
|
-
def defaultPivotStyle=(v)
|
35
|
+
def defaultPivotStyle=(v)
|
36
|
+
Axlsx.validate_string(v)
|
37
|
+
@defaultPivotStyle = v
|
38
|
+
end
|
30
39
|
|
31
40
|
# Serializes the object
|
32
41
|
# @param [String] str
|
33
42
|
# @return [String]
|
34
|
-
def to_xml_string(str = '')
|
43
|
+
def to_xml_string(str = +'')
|
35
44
|
str << '<tableStyles '
|
36
|
-
serialized_attributes str, { :
|
45
|
+
serialized_attributes str, { count: size }
|
37
46
|
str << '>'
|
38
47
|
each { |table_style| table_style.to_xml_string(str) }
|
39
48
|
str << '</tableStyles>'
|