caxlsx 3.3.0 → 3.4.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 +9 -0
- data/README.md +24 -5
- 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 +46 -26
- 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
@@ -6,14 +6,12 @@ module Axlsx
|
|
6
6
|
# @see Worksheet#add_conditional_formatting
|
7
7
|
# @see ConditionalFormattingRule#initialize
|
8
8
|
class ColorScale
|
9
|
-
|
10
9
|
class << self
|
11
|
-
|
12
10
|
# These are the default conditional formatting value objects
|
13
11
|
# that define a two tone color gradient.
|
14
12
|
def default_cfvos
|
15
|
-
[{:type => :min, :val => 0, :color => 'FFFF7128'},
|
16
|
-
{:type => :max, :val => 0, :color => 'FFFFEF9C'}]
|
13
|
+
[{ :type => :min, :val => 0, :color => 'FFFF7128' },
|
14
|
+
{ :type => :max, :val => 0, :color => 'FFFFEF9C' }]
|
17
15
|
end
|
18
16
|
|
19
17
|
# A builder for two tone color gradient
|
@@ -28,12 +26,12 @@ module Axlsx
|
|
28
26
|
# A builder for three tone color gradient
|
29
27
|
# @example
|
30
28
|
# #this creates a three tone color scale
|
31
|
-
# color_scale = Axlsx::ColorScale.three_tone
|
29
|
+
# color_scale = Axlsx::ColorScale.three_tone
|
32
30
|
# @see examples/example.rb conditional formatting examples.
|
33
31
|
def three_tone
|
34
|
-
self.new({:type => :min, :val => 0, :color => 'FFF8696B'},
|
35
|
-
{:type => :percent, :val => '50', :color => 'FFFFEB84'},
|
36
|
-
{:type => :max, :val => 0, :color => 'FF63BE7B'})
|
32
|
+
self.new({ :type => :min, :val => 0, :color => 'FFF8696B' },
|
33
|
+
{ :type => :percent, :val => '50', :color => 'FFFFEB84' },
|
34
|
+
{ :type => :max, :val => 0, :color => 'FF63BE7B' })
|
37
35
|
end
|
38
36
|
end
|
39
37
|
# A simple typed list of cfvos
|
@@ -67,17 +65,16 @@ module Axlsx
|
|
67
65
|
# @option [Symbol] type The type of cfvo you to add
|
68
66
|
# @option [Any] val The value of the cfvo to add
|
69
67
|
# @option [String] The rgb color for the cfvo
|
70
|
-
def add(options={})
|
68
|
+
def add(options = {})
|
71
69
|
value_objects << Cfvo.new(:type => options[:type] || :min, :val => options[:val] || 0)
|
72
70
|
colors << Color.new(:rgb => options[:color] || "FF000000")
|
73
|
-
{:cfvo => value_objects.last, :color => colors.last}
|
71
|
+
{ :cfvo => value_objects.last, :color => colors.last }
|
74
72
|
end
|
75
73
|
|
76
|
-
|
77
74
|
# removes the cfvo and color pair at the index specified.
|
78
75
|
# @param [Integer] index The index of the cfvo and color object to delete
|
79
76
|
# @note you cannot remove the first two cfvo and color pairs
|
80
|
-
def delete_at(index=2)
|
77
|
+
def delete_at(index = 2)
|
81
78
|
value_objects.delete_at index
|
82
79
|
colors.delete_at index
|
83
80
|
end
|
@@ -93,6 +90,7 @@ module Axlsx
|
|
93
90
|
end
|
94
91
|
|
95
92
|
private
|
93
|
+
|
96
94
|
# There has got to be cleaner way of merging these arrays.
|
97
95
|
def initialize_default_cfvos(user_cfvos)
|
98
96
|
defaults = self.class.default_cfvos
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Axlsx
|
2
|
-
|
3
2
|
# The cols class manages the col object used to manage column widths.
|
4
3
|
# This is where the magic happens with autowidth
|
5
4
|
class Cols < SimpleTypedList
|
6
|
-
|
7
5
|
def initialize(worksheet)
|
8
6
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
7
|
+
|
9
8
|
super Col
|
10
9
|
@worksheet = worksheet
|
11
10
|
end
|
@@ -14,10 +13,11 @@ module Axlsx
|
|
14
13
|
# @param [String] str
|
15
14
|
# @return [String]
|
16
15
|
def to_xml_string(str = '')
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
return if empty?
|
17
|
+
|
18
|
+
str << '<cols>'
|
19
|
+
each { |item| item.to_xml_string(str) }
|
20
|
+
str << '</cols>'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module Axlsx
|
2
|
-
|
3
2
|
# A comment is the text data for a comment
|
4
3
|
class Comment
|
5
|
-
|
6
4
|
include Axlsx::OptionsParser
|
7
5
|
include Axlsx::Accessors
|
8
6
|
|
@@ -13,8 +11,9 @@ module Axlsx
|
|
13
11
|
# @option [String] text The text for the comment
|
14
12
|
# @option [String] ref The refence (e.g. 'A3' where this comment will be anchored.
|
15
13
|
# @option [Boolean] visible This controls the visiblity of the associated vml_shape.
|
16
|
-
def initialize(comments, options={})
|
14
|
+
def initialize(comments, options = {})
|
17
15
|
raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
|
16
|
+
|
18
17
|
@visible = true
|
19
18
|
@comments = comments
|
20
19
|
parse_options options
|
@@ -82,9 +81,9 @@ module Axlsx
|
|
82
81
|
pos = Axlsx::name_to_indices(ref)
|
83
82
|
@vml_shape = VmlShape.new(:row => pos[1], :column => pos[0], :visible => @visible) do |vml|
|
84
83
|
vml.left_column = vml.column
|
85
|
-
vml.right_column = vml.column + 2
|
84
|
+
vml.right_column = vml.column + 2
|
86
85
|
vml.top_row = vml.row
|
87
|
-
|
86
|
+
vml.bottom_row = vml.row + 4
|
88
87
|
end
|
89
88
|
end
|
90
89
|
end
|
@@ -1,9 +1,6 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
module Axlsx
|
3
|
-
|
4
2
|
# Comments is a collection of Comment objects for a worksheet
|
5
3
|
class Comments < SimpleTypedList
|
6
|
-
|
7
4
|
# the vml_drawing that holds the shapes for comments
|
8
5
|
# @return [VmlDrawing]
|
9
6
|
attr_reader :vml_drawing
|
@@ -21,13 +18,14 @@ module Axlsx
|
|
21
18
|
# The part name for this object
|
22
19
|
# @return [String]
|
23
20
|
def pn
|
24
|
-
"#{COMMENT_PN % (index+1)}"
|
21
|
+
"#{COMMENT_PN % (index + 1)}"
|
25
22
|
end
|
26
23
|
|
27
24
|
# Creates a new Comments object
|
28
25
|
# @param [Worksheet] worksheet The sheet that these comments belong to.
|
29
26
|
def initialize(worksheet)
|
30
27
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
28
|
+
|
31
29
|
super(Comment)
|
32
30
|
@worksheet = worksheet
|
33
31
|
@vml_drawing = VmlDrawing.new(self)
|
@@ -38,10 +36,11 @@ module Axlsx
|
|
38
36
|
# @option options [String] author The name of the author for this comment
|
39
37
|
# @option options [String] text The text for this comment
|
40
38
|
# @option options [Stirng|Cell] ref The cell that this comment is attached to.
|
41
|
-
def add_comment(options={})
|
39
|
+
def add_comment(options = {})
|
42
40
|
raise ArgumentError, "Comment require an author" unless options[:author]
|
43
41
|
raise ArgumentError, "Comment requires text" unless options[:text]
|
44
42
|
raise ArgumentError, "Comment requires ref" unless options[:ref]
|
43
|
+
|
45
44
|
self << Comment.new(self, options)
|
46
45
|
yield last if block_given?
|
47
46
|
last
|
@@ -63,10 +62,10 @@ module Axlsx
|
|
63
62
|
# serialize the object
|
64
63
|
# @param [String] str
|
65
64
|
# @return [String]
|
66
|
-
def to_xml_string(str="")
|
65
|
+
def to_xml_string(str = "")
|
67
66
|
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
68
67
|
str << ('<comments xmlns="' << XML_NS << '"><authors>')
|
69
|
-
authors.each do
|
68
|
+
authors.each do |author|
|
70
69
|
str << ('<author>' << author.to_s << '</author>')
|
71
70
|
end
|
72
71
|
str << '</authors><commentList>'
|
@@ -74,9 +73,6 @@ module Axlsx
|
|
74
73
|
comment.to_xml_string str
|
75
74
|
end
|
76
75
|
str << '</commentList></comments>'
|
77
|
-
|
78
76
|
end
|
79
|
-
|
80
77
|
end
|
81
|
-
|
82
78
|
end
|
@@ -5,13 +5,12 @@ module Axlsx
|
|
5
5
|
# @see Worksheet#add_conditional_formatting
|
6
6
|
# @see ConditionalFormattingRule
|
7
7
|
class ConditionalFormatting
|
8
|
+
include Axlsx::OptionsParser
|
8
9
|
|
9
|
-
include Axlsx::OptionsParser
|
10
|
-
|
11
10
|
# Creates a new {ConditionalFormatting} object
|
12
11
|
# @option options [Array] rules The rules to apply
|
13
12
|
# @option options [String] sqref The range to apply the rules to
|
14
|
-
def initialize(options={})
|
13
|
+
def initialize(options = {})
|
15
14
|
@rules = []
|
16
15
|
parse_options options
|
17
16
|
end
|
@@ -28,7 +27,7 @@ module Axlsx
|
|
28
27
|
# @return [Array]
|
29
28
|
attr_reader :rules
|
30
29
|
|
31
|
-
|
30
|
+
# Add Conditional Formatting Rules to this object. Rules can either
|
32
31
|
# be already created {ConditionalFormattingRule} elements or
|
33
32
|
# hashes of options for automatic creation. If rules is a hash
|
34
33
|
# instead of an array, assume only one rule being added.
|
@@ -75,7 +74,7 @@ module Axlsx
|
|
75
74
|
# @return [String]
|
76
75
|
def to_xml_string(str = '')
|
77
76
|
str << ('<conditionalFormatting sqref="' << sqref << '">')
|
78
|
-
str << rules.collect{ |rule| rule.to_xml_string }.join(' ')
|
77
|
+
str << rules.collect { |rule| rule.to_xml_string }.join(' ')
|
79
78
|
str << '</conditionalFormatting>'
|
80
79
|
end
|
81
80
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
module Axlsx
|
3
2
|
# Conditional formatting rules specify formulas whose evaluations
|
4
3
|
# format cells
|
@@ -7,7 +6,6 @@ module Axlsx
|
|
7
6
|
# @see Worksheet#add_conditional_formatting
|
8
7
|
# @see ConditionalFormattingRule#initialize
|
9
8
|
class ConditionalFormattingRule
|
10
|
-
|
11
9
|
include Axlsx::OptionsParser
|
12
10
|
include Axlsx::SerializedAttributes
|
13
11
|
|
@@ -26,7 +24,7 @@ module Axlsx
|
|
26
24
|
# @option options [Boolean] stopIfTrue Stop evaluating rules after this rule matches
|
27
25
|
# @option options [Symbol] timePeriod The time period in a date occuring... rule
|
28
26
|
# @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
|
-
def initialize(options={})
|
27
|
+
def initialize(options = {})
|
30
28
|
@color_scale = @data_bar = @icon_set = @formula = nil
|
31
29
|
parse_options options
|
32
30
|
end
|
@@ -133,7 +131,6 @@ module Axlsx
|
|
133
131
|
# thisMonth, lastMonth, nextMonth, thisWeek, lastWeek, nextWeek
|
134
132
|
attr_reader :timePeriod
|
135
133
|
|
136
|
-
|
137
134
|
# colorScale (Color Scale)
|
138
135
|
# The color scale to apply to this conditional formatting
|
139
136
|
# @return [ColorScale]
|
@@ -182,7 +179,7 @@ module Axlsx
|
|
182
179
|
# @see timePeriod
|
183
180
|
def timePeriod=(v); Axlsx::validate_time_period_type(v); @timePeriod = v end
|
184
181
|
# @see formula
|
185
|
-
def formula=(v); [*v].each {|x| Axlsx::validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
|
182
|
+
def formula=(v); [*v].each { |x| Axlsx::validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
|
186
183
|
|
187
184
|
# @see color_scale
|
188
185
|
def color_scale=(v)
|
@@ -202,7 +199,6 @@ module Axlsx
|
|
202
199
|
@icon_set = v
|
203
200
|
end
|
204
201
|
|
205
|
-
|
206
202
|
# Serializes the conditional formatting rule
|
207
203
|
# @param [String] str
|
208
204
|
# @return [String]
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Axlsx
|
2
|
-
|
3
2
|
# A simple, self serializing class for storing conditional formattings
|
4
3
|
class ConditionalFormattings < SimpleTypedList
|
5
|
-
|
6
4
|
# creates a new Tables object
|
7
5
|
def initialize(worksheet)
|
8
6
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
7
|
+
|
9
8
|
super ConditionalFormatting
|
10
9
|
@worksheet = worksheet
|
11
10
|
end
|
@@ -17,9 +16,8 @@ module Axlsx
|
|
17
16
|
# serialize the conditional formattings
|
18
17
|
def to_xml_string(str = "")
|
19
18
|
return if empty?
|
19
|
+
|
20
20
|
each { |item| item.to_xml_string(str) }
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
|
-
|
@@ -6,15 +6,14 @@ module Axlsx
|
|
6
6
|
# @see Worksheet#add_conditional_formatting
|
7
7
|
# @see ConditionalFormattingRule#initialize
|
8
8
|
class DataBar
|
9
|
-
|
10
9
|
include Axlsx::OptionsParser
|
11
10
|
include Axlsx::SerializedAttributes
|
12
11
|
|
13
12
|
class << self
|
14
13
|
# This differs from ColorScale. There must be exactly two cfvos one color
|
15
14
|
def default_cfvos
|
16
|
-
[{:type => :min, :val => "0"},
|
17
|
-
{:type => :max, :val => "0"}]
|
15
|
+
[{ :type => :min, :val => "0" },
|
16
|
+
{ :type => :max, :val => "0" }]
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
@@ -81,32 +80,32 @@ module Axlsx
|
|
81
80
|
end
|
82
81
|
alias :minLength= :min_length=
|
83
82
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
83
|
+
# @see maxLength
|
84
|
+
def max_length=(v)
|
85
|
+
Axlsx.validate_unsigned_int(v)
|
86
|
+
@max_length = v
|
87
|
+
end
|
89
88
|
alias :maxLength= :max_length=
|
90
89
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
# @see showValue
|
91
|
+
def show_value=(v)
|
92
|
+
Axlsx.validate_boolean(v)
|
93
|
+
@show_value = v
|
94
|
+
end
|
96
95
|
alias :showValue= :show_value=
|
97
96
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
97
|
+
# Sets the color for the data bars.
|
98
|
+
# @param [Color|String] v The color object, or rgb string value to apply
|
99
|
+
def color=(v)
|
100
|
+
@color = v if v.is_a? Color
|
101
|
+
self.color.rgb = v if v.is_a? String
|
102
|
+
@color
|
103
|
+
end
|
105
104
|
|
106
105
|
# Serialize this object to an xml string
|
107
106
|
# @param [String] str
|
108
107
|
# @return [String]
|
109
|
-
def to_xml_string(str="")
|
108
|
+
def to_xml_string(str = "")
|
110
109
|
serialized_tag('dataBar', str) do
|
111
110
|
value_objects.to_xml_string(str)
|
112
111
|
self.color.to_xml_string(str)
|
@@ -124,6 +123,5 @@ module Axlsx
|
|
124
123
|
end
|
125
124
|
end
|
126
125
|
end
|
127
|
-
|
128
126
|
end
|
129
127
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
module Axlsx
|
3
2
|
# Data validation allows the validation of cell data
|
4
3
|
#
|
@@ -23,7 +22,7 @@ module Axlsx
|
|
23
22
|
# @option options [Boolean] showInputMessage - A boolean value indicating whether to display the input prompt message.
|
24
23
|
# @option options [String] sqref - Range over which data validation is applied, in "A1:B2" format.
|
25
24
|
# @option options [Symbol] type - The type of data validation.
|
26
|
-
def initialize(options={})
|
25
|
+
def initialize(options = {})
|
27
26
|
# defaults
|
28
27
|
@formula1 = @formula2 = @error = @errorTitle = @operator = @prompt = @promptTitle = @sqref = nil
|
29
28
|
@allowBlank = @showErrorMessage = true
|
@@ -176,7 +175,6 @@ module Axlsx
|
|
176
175
|
# default none
|
177
176
|
attr_reader :type
|
178
177
|
|
179
|
-
|
180
178
|
# @see formula1
|
181
179
|
def formula1=(v); Axlsx::validate_string(v); @formula1 = v end
|
182
180
|
|
@@ -246,9 +244,10 @@ module Axlsx
|
|
246
244
|
str << '</dataValidation>'
|
247
245
|
end
|
248
246
|
|
249
|
-
|
247
|
+
private
|
248
|
+
|
250
249
|
def get_valid_attributes
|
251
|
-
attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type
|
250
|
+
attributes = [:allowBlank, :error, :errorStyle, :errorTitle, :prompt, :promptTitle, :showErrorMessage, :showInputMessage, :sqref, :type]
|
252
251
|
|
253
252
|
if [:whole, :decimal, :data, :time, :date, :textLength].include?(@type)
|
254
253
|
attributes << [:operator, :formula1]
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Axlsx
|
2
|
-
|
3
2
|
# A simple, self serializing class for storing conditional formattings
|
4
3
|
class DataValidations < SimpleTypedList
|
5
|
-
|
6
4
|
# creates a new Tables object
|
7
5
|
def initialize(worksheet)
|
8
6
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
7
|
+
|
9
8
|
super DataValidation
|
10
9
|
@worksheet = worksheet
|
11
10
|
end
|
@@ -17,12 +16,10 @@ module Axlsx
|
|
17
16
|
# serialize the conditional formattings
|
18
17
|
def to_xml_string(str = "")
|
19
18
|
return if empty?
|
19
|
+
|
20
20
|
str << "<dataValidations count='#{size}'>"
|
21
21
|
each { |item| item.to_xml_string(str) }
|
22
22
|
str << '</dataValidations>'
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
25
|
end
|
27
|
-
|
28
|
-
|
@@ -1,10 +1,8 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
require "date"
|
3
2
|
|
4
3
|
module Axlsx
|
5
4
|
# The DateTimeConverter class converts both data and time types to their apprpriate excel serializations
|
6
5
|
class DateTimeConverter
|
7
|
-
|
8
6
|
# The date_to_serial method converts Date objects to the equivelant excel serialized forms
|
9
7
|
# @param [Date] date the date to be serialized
|
10
8
|
# @return [Numeric]
|
@@ -24,7 +22,7 @@ module Axlsx
|
|
24
22
|
epoch1904 = -2082844800.0 # Time.utc(1904, 1, 1).to_i
|
25
23
|
seconds_per_day = 86400.0 # 60*60*24
|
26
24
|
epoch = Axlsx::Workbook::date1904 ? epoch1904 : epoch1900
|
27
|
-
(time.utc_offset + time.to_f - epoch)/seconds_per_day
|
25
|
+
(time.utc_offset + time.to_f - epoch) / seconds_per_day
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Axlsx
|
2
|
-
|
3
2
|
# This class manages the dimensions for a worksheet.
|
4
|
-
# While this node is optional in the specification some readers like
|
3
|
+
# While this node is optional in the specification some readers like
|
5
4
|
# LibraOffice require this node to render the sheet
|
6
5
|
class Dimension
|
7
|
-
|
8
6
|
# the default value for the first cell in the dimension
|
9
7
|
# @return [String]
|
10
8
|
def self.default_first
|
@@ -22,6 +20,7 @@ module Axlsx
|
|
22
20
|
# to.
|
23
21
|
def initialize(worksheet)
|
24
22
|
raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
|
23
|
+
|
25
24
|
@worksheet = worksheet
|
26
25
|
end
|
27
26
|
|
@@ -31,12 +30,13 @@ module Axlsx
|
|
31
30
|
# @return [String]
|
32
31
|
def sqref
|
33
32
|
"#{first_cell_reference}:#{last_cell_reference}"
|
34
|
-
end
|
33
|
+
end
|
35
34
|
|
36
35
|
# serialize the object
|
37
36
|
# @return [String]
|
38
37
|
def to_xml_string(str = '')
|
39
38
|
return if worksheet.rows.empty?
|
39
|
+
|
40
40
|
str << "<dimension ref=\"%s\"></dimension>" % sqref
|
41
41
|
end
|
42
42
|
|
@@ -58,6 +58,7 @@ module Axlsx
|
|
58
58
|
# @return [String]
|
59
59
|
def dimension_reference(cell, default)
|
60
60
|
return default unless cell.respond_to?(:r)
|
61
|
+
|
61
62
|
cell.r
|
62
63
|
end
|
63
64
|
end
|
@@ -6,7 +6,6 @@ module Axlsx
|
|
6
6
|
# @see Worksheet#add_conditional_formatting
|
7
7
|
# @see ConditionalFormattingRule#initialize
|
8
8
|
class IconSet
|
9
|
-
|
10
9
|
include Axlsx::OptionsParser
|
11
10
|
include Axlsx::SerializedAttributes
|
12
11
|
|
@@ -47,7 +46,7 @@ module Axlsx
|
|
47
46
|
# @return [Boolean]
|
48
47
|
attr_reader :showValue
|
49
48
|
|
50
|
-
|
49
|
+
# @see iconSet
|
51
50
|
def iconSet=(v); Axlsx::validate_icon_set(v); @iconSet = v end
|
52
51
|
|
53
52
|
# @see showValue
|
@@ -62,7 +61,7 @@ module Axlsx
|
|
62
61
|
# Serialize this object to an xml string
|
63
62
|
# @param [String] str
|
64
63
|
# @return [String]
|
65
|
-
def to_xml_string(str="")
|
64
|
+
def to_xml_string(str = "")
|
66
65
|
serialized_tag('iconSet', str) do
|
67
66
|
@value_objects.each { |cfvo| cfvo.to_xml_string(str) }
|
68
67
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module Axlsx
|
2
|
-
|
3
2
|
# A simple list of merged cells
|
4
3
|
class MergedCells < SimpleTypedList
|
5
|
-
|
6
4
|
# creates a new MergedCells object
|
7
5
|
# @param [Worksheet] worksheet
|
8
6
|
def initialize(worksheet)
|
9
7
|
raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
|
8
|
+
|
10
9
|
super String
|
11
10
|
end
|
12
11
|
|
@@ -16,12 +15,12 @@ module Axlsx
|
|
16
15
|
# range like 'A1:C1'
|
17
16
|
def add(cells)
|
18
17
|
self << if cells.is_a?(String)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
cells
|
19
|
+
elsif cells.is_a?(Array)
|
20
|
+
Axlsx::cell_range(cells, false)
|
21
|
+
elsif cells.is_a?(Row)
|
22
|
+
Axlsx::cell_range(cells, false)
|
23
|
+
end
|
25
24
|
end
|
26
25
|
|
27
26
|
# serialize the object
|
@@ -29,6 +28,7 @@ module Axlsx
|
|
29
28
|
# @return [String]
|
30
29
|
def to_xml_string(str = '')
|
31
30
|
return if empty?
|
31
|
+
|
32
32
|
str << "<mergeCells count='#{size}'>"
|
33
33
|
each { |merged_cell| str << "<mergeCell ref='#{merged_cell}'></mergeCell>" }
|
34
34
|
str << '</mergeCells>'
|
@@ -9,7 +9,6 @@ module Axlsx
|
|
9
9
|
# @see Worksheet#page_margins
|
10
10
|
# @see Worksheet#initialize
|
11
11
|
class PageMargins
|
12
|
-
|
13
12
|
include Axlsx::OptionsParser
|
14
13
|
include Axlsx::SerializedAttributes
|
15
14
|
|
@@ -20,7 +19,7 @@ module Axlsx
|
|
20
19
|
# @option options [Numeric] top The top margin in inches
|
21
20
|
# @option options [Numeric] header The header margin in inches
|
22
21
|
# @option options [Numeric] footer The footer margin in inches
|
23
|
-
def initialize(options={})
|
22
|
+
def initialize(options = {})
|
24
23
|
# Default values taken from MS Excel for Mac 2011
|
25
24
|
@left = @right = DEFAULT_LEFT_RIGHT
|
26
25
|
@top = @bottom = DEFAULT_TOP_BOTTOM
|
@@ -68,6 +67,7 @@ module Axlsx
|
|
68
67
|
def set(margins)
|
69
68
|
margins.select do |k, v|
|
70
69
|
next unless [:left, :right, :top, :bottom, :header, :footer].include? k
|
70
|
+
|
71
71
|
send("#{k}=", v)
|
72
72
|
end
|
73
73
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
module Axlsx
|
2
|
-
|
3
2
|
# Page setup properties of the worksheet
|
4
3
|
# This class name is not a typo, its spec.
|
5
4
|
class PageSetUpPr
|
6
|
-
|
7
5
|
include Axlsx::OptionsParser
|
8
6
|
include Axlsx::SerializedAttributes
|
9
7
|
|
@@ -37,7 +35,7 @@ module Axlsx
|
|
37
35
|
end
|
38
36
|
|
39
37
|
# serialize to xml
|
40
|
-
def to_xml_string(str='')
|
38
|
+
def to_xml_string(str = '')
|
41
39
|
str << ('<pageSetUpPr ' << serialized_attributes << '/>')
|
42
40
|
end
|
43
41
|
end
|