caxlsx 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +24 -5
  4. data/Rakefile +0 -1
  5. data/lib/axlsx/content_type/abstract_content_type.rb +2 -5
  6. data/lib/axlsx/content_type/content_type.rb +0 -4
  7. data/lib/axlsx/content_type/default.rb +1 -5
  8. data/lib/axlsx/content_type/override.rb +0 -4
  9. data/lib/axlsx/doc_props/app.rb +1 -6
  10. data/lib/axlsx/doc_props/core.rb +1 -6
  11. data/lib/axlsx/drawing/area_chart.rb +3 -6
  12. data/lib/axlsx/drawing/area_series.rb +1 -4
  13. data/lib/axlsx/drawing/ax_data_source.rb +1 -6
  14. data/lib/axlsx/drawing/axes.rb +5 -6
  15. data/lib/axlsx/drawing/axis.rb +7 -12
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +7 -10
  17. data/lib/axlsx/drawing/bar_chart.rb +6 -9
  18. data/lib/axlsx/drawing/bar_series.rb +2 -8
  19. data/lib/axlsx/drawing/bubble_chart.rb +2 -5
  20. data/lib/axlsx/drawing/bubble_series.rb +3 -6
  21. data/lib/axlsx/drawing/cat_axis.rb +2 -7
  22. data/lib/axlsx/drawing/chart.rb +7 -12
  23. data/lib/axlsx/drawing/d_lbls.rb +23 -22
  24. data/lib/axlsx/drawing/drawing.rb +4 -8
  25. data/lib/axlsx/drawing/graphic_frame.rb +0 -3
  26. data/lib/axlsx/drawing/hyperlink.rb +4 -7
  27. data/lib/axlsx/drawing/line_3D_chart.rb +10 -14
  28. data/lib/axlsx/drawing/line_chart.rb +3 -6
  29. data/lib/axlsx/drawing/line_series.rb +1 -4
  30. data/lib/axlsx/drawing/marker.rb +5 -9
  31. data/lib/axlsx/drawing/num_data.rb +4 -9
  32. data/lib/axlsx/drawing/num_data_source.rb +3 -7
  33. data/lib/axlsx/drawing/num_val.rb +2 -5
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +4 -6
  35. data/lib/axlsx/drawing/pic.rb +46 -13
  36. data/lib/axlsx/drawing/picture_locking.rb +3 -6
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -7
  38. data/lib/axlsx/drawing/pie_series.rb +1 -6
  39. data/lib/axlsx/drawing/scaling.rb +2 -5
  40. data/lib/axlsx/drawing/scatter_chart.rb +2 -5
  41. data/lib/axlsx/drawing/scatter_series.rb +2 -5
  42. data/lib/axlsx/drawing/ser_axis.rb +2 -6
  43. data/lib/axlsx/drawing/series.rb +3 -5
  44. data/lib/axlsx/drawing/series_title.rb +0 -2
  45. data/lib/axlsx/drawing/str_data.rb +3 -8
  46. data/lib/axlsx/drawing/str_val.rb +2 -5
  47. data/lib/axlsx/drawing/title.rb +12 -15
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +5 -7
  49. data/lib/axlsx/drawing/val_axis.rb +1 -4
  50. data/lib/axlsx/drawing/view_3D.rb +24 -24
  51. data/lib/axlsx/drawing/vml_drawing.rb +2 -5
  52. data/lib/axlsx/drawing/vml_shape.rb +4 -7
  53. data/lib/axlsx/package.rb +35 -36
  54. data/lib/axlsx/rels/relationship.rb +21 -24
  55. data/lib/axlsx/rels/relationships.rb +3 -6
  56. data/lib/axlsx/stylesheet/border.rb +1 -4
  57. data/lib/axlsx/stylesheet/border_pr.rb +3 -5
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +2 -10
  59. data/lib/axlsx/stylesheet/cell_protection.rb +1 -4
  60. data/lib/axlsx/stylesheet/cell_style.rb +3 -7
  61. data/lib/axlsx/stylesheet/color.rb +6 -5
  62. data/lib/axlsx/stylesheet/dxf.rb +2 -6
  63. data/lib/axlsx/stylesheet/fill.rb +0 -4
  64. data/lib/axlsx/stylesheet/font.rb +7 -6
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +4 -6
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +2 -3
  67. data/lib/axlsx/stylesheet/num_fmt.rb +1 -4
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +3 -5
  69. data/lib/axlsx/stylesheet/styles.rb +53 -45
  70. data/lib/axlsx/stylesheet/table_style.rb +5 -8
  71. data/lib/axlsx/stylesheet/table_style_element.rb +1 -4
  72. data/lib/axlsx/stylesheet/table_styles.rb +3 -7
  73. data/lib/axlsx/stylesheet/xf.rb +3 -6
  74. data/lib/axlsx/util/accessors.rb +2 -4
  75. data/lib/axlsx/util/constants.rb +3 -5
  76. data/lib/axlsx/util/mime_type_utils.rb +13 -0
  77. data/lib/axlsx/util/options_parser.rb +1 -2
  78. data/lib/axlsx/util/serialized_attributes.rb +4 -5
  79. data/lib/axlsx/util/simple_typed_list.rb +18 -17
  80. data/lib/axlsx/util/storage.rb +32 -36
  81. data/lib/axlsx/util/validators.rb +7 -4
  82. data/lib/axlsx/util/zip_command.rb +0 -2
  83. data/lib/axlsx/version.rb +1 -2
  84. data/lib/axlsx/workbook/defined_name.rb +6 -5
  85. data/lib/axlsx/workbook/defined_names.rb +1 -2
  86. data/lib/axlsx/workbook/shared_strings_table.rb +3 -6
  87. data/lib/axlsx/workbook/workbook.rb +96 -91
  88. data/lib/axlsx/workbook/workbook_view.rb +5 -10
  89. data/lib/axlsx/workbook/workbook_views.rb +1 -3
  90. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +9 -8
  91. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +6 -6
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +13 -14
  93. data/lib/axlsx/workbook/worksheet/border_creator.rb +29 -26
  94. data/lib/axlsx/workbook/worksheet/break.rb +2 -5
  95. data/lib/axlsx/workbook/worksheet/cell.rb +46 -26
  96. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +11 -11
  97. data/lib/axlsx/workbook/worksheet/cfvo.rb +2 -2
  98. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -5
  99. data/lib/axlsx/workbook/worksheet/col.rb +4 -7
  100. data/lib/axlsx/workbook/worksheet/col_breaks.rb +4 -5
  101. data/lib/axlsx/workbook/worksheet/color_scale.rb +10 -12
  102. data/lib/axlsx/workbook/worksheet/cols.rb +6 -6
  103. data/lib/axlsx/workbook/worksheet/comment.rb +4 -5
  104. data/lib/axlsx/workbook/worksheet/comments.rb +6 -10
  105. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +4 -5
  106. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +2 -6
  107. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +2 -4
  108. data/lib/axlsx/workbook/worksheet/data_bar.rb +20 -22
  109. data/lib/axlsx/workbook/worksheet/data_validation.rb +4 -5
  110. data/lib/axlsx/workbook/worksheet/data_validations.rb +2 -5
  111. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -3
  112. data/lib/axlsx/workbook/worksheet/dimension.rb +5 -4
  113. data/lib/axlsx/workbook/worksheet/header_footer.rb +0 -1
  114. data/lib/axlsx/workbook/worksheet/icon_set.rb +2 -3
  115. data/lib/axlsx/workbook/worksheet/merged_cells.rb +8 -8
  116. data/lib/axlsx/workbook/worksheet/outline_pr.rb +0 -1
  117. data/lib/axlsx/workbook/worksheet/page_margins.rb +2 -2
  118. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -3
  119. data/lib/axlsx/workbook/worksheet/page_setup.rb +117 -120
  120. data/lib/axlsx/workbook/worksheet/pane.rb +16 -17
  121. data/lib/axlsx/workbook/worksheet/pivot_table.rb +8 -11
  122. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -11
  123. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -4
  124. data/lib/axlsx/workbook/worksheet/print_options.rb +0 -1
  125. data/lib/axlsx/workbook/worksheet/protected_range.rb +4 -5
  126. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +9 -9
  127. data/lib/axlsx/workbook/worksheet/rich_text.rb +4 -6
  128. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +21 -5
  129. data/lib/axlsx/workbook/worksheet/row.rb +24 -15
  130. data/lib/axlsx/workbook/worksheet/row_breaks.rb +3 -4
  131. data/lib/axlsx/workbook/worksheet/selection.rb +7 -9
  132. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +5 -6
  133. data/lib/axlsx/workbook/worksheet/sheet_data.rb +4 -6
  134. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +18 -18
  135. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +4 -4
  136. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +12 -13
  137. data/lib/axlsx/workbook/worksheet/sheet_view.rb +35 -42
  138. data/lib/axlsx/workbook/worksheet/table.rb +7 -9
  139. data/lib/axlsx/workbook/worksheet/table_style_info.rb +2 -3
  140. data/lib/axlsx/workbook/worksheet/tables.rb +4 -4
  141. data/lib/axlsx/workbook/worksheet/worksheet.rb +63 -35
  142. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -6
  143. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +3 -2
  144. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +5 -6
  145. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +4 -4
  146. data/lib/axlsx.rb +23 -9
  147. data/lib/caxlsx.rb +0 -1
  148. metadata +3 -3
@@ -1,8 +1,6 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # The color class represents a color used for borders, fills an fonts
4
3
  class Color
5
-
6
4
  include Axlsx::OptionsParser
7
5
  include Axlsx::SerializedAttributes
8
6
 
@@ -10,7 +8,7 @@ module Axlsx
10
8
  # @option options [Boolean] auto
11
9
  # @option options [String] rgb
12
10
  # @option options [Float] tint
13
- def initialize(options={})
11
+ def initialize(options = {})
14
12
  @rgb = "FF000000"
15
13
  parse_options options
16
14
  end
@@ -39,15 +37,16 @@ module Axlsx
39
37
 
40
38
  # no support for theme just yet
41
39
  # @return [Integer]
42
- #attr_reader :theme
40
+ # attr_reader :theme
43
41
 
44
42
  # The tint value.
45
43
  # @note valid values are between -1.0 and 1.0
46
44
  # @return [Float]
47
45
  attr_reader :tint
48
46
 
49
- # @see auto
47
+ # @see auto
50
48
  def auto=(v) Axlsx::validate_boolean v; @auto = v end
49
+
51
50
  # @see color
52
51
  def rgb=(v)
53
52
  Axlsx::validate_string(v)
@@ -55,8 +54,10 @@ module Axlsx
55
54
  v = v * 3 if v.size == 2
56
55
  v = v.rjust(8, 'FF')
57
56
  raise ArgumentError, "Invalid color rgb value: #{v}." unless v.match(/[0-9A-F]{8}/)
57
+
58
58
  @rgb = v
59
59
  end
60
+
60
61
  # @see tint
61
62
  def tint=(v) Axlsx::validate_float v; @tint = v end
62
63
 
@@ -1,15 +1,13 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # The Dxf class defines an incremental formatting record for use in Styles. The recommended way to manage styles for your workbook is with Styles#add_style
4
3
  # @see Styles#add_style
5
4
  class Dxf
6
-
7
5
  include Axlsx::OptionsParser
8
6
 
9
7
  # The order in which the child elements is put in the XML seems to
10
8
  # be important for Excel
11
9
  CHILD_ELEMENTS = [:font, :numFmt, :fill, :alignment, :border, :protection]
12
- #does not support extList (ExtensionList)
10
+ # does not support extList (ExtensionList)
13
11
 
14
12
  # The cell alignment for this style
15
13
  # @return [CellAlignment]
@@ -44,7 +42,7 @@ module Axlsx
44
42
  # @option options [Font] font
45
43
  # @option options [CellAlignment] alignment
46
44
  # @option options [CellProtection] protection
47
- def initialize(options={})
45
+ def initialize(options = {})
48
46
  parse_options options
49
47
  end
50
48
 
@@ -73,7 +71,5 @@ module Axlsx
73
71
  end
74
72
  str << '</dxf>'
75
73
  end
76
-
77
74
  end
78
-
79
75
  end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # The Fill is a formatting object that manages the background color, and pattern for cells.
4
3
  # @note The recommended way to manage styles in your workbook is to use Styles#add_style.
@@ -6,7 +5,6 @@ module Axlsx
6
5
  # @see PatternFill
7
6
  # @see GradientFill
8
7
  class Fill
9
-
10
8
  # The type of fill
11
9
  # @return [PatternFill, GradientFill]
12
10
  attr_reader :fill_type
@@ -29,7 +27,5 @@ module Axlsx
29
27
 
30
28
  # @see fill_type
31
29
  def fill_type=(v) DataTypeValidator.validate "Fill.fill_type", [PatternFill, GradientFill], v; @fill_type = v; end
32
-
33
-
34
30
  end
35
31
  end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # The Font class details a font instance for use in styling cells.
4
3
  # @note The recommended way to manage fonts, and other styles is Styles#add_style
@@ -21,7 +20,7 @@ module Axlsx
21
20
  # @option options [Boolean] extend
22
21
  # @option options [Color] color
23
22
  # @option options [Integer] sz
24
- def initialize(options={})
23
+ def initialize(options = {})
25
24
  parse_options options
26
25
  end
27
26
 
@@ -100,7 +99,7 @@ module Axlsx
100
99
 
101
100
  # The font's extend property
102
101
  # @return [Boolean]
103
- attr_reader :extend
102
+ attr_reader :extend
104
103
 
105
104
  # The color of the font
106
105
  # @return [Color]
@@ -110,7 +109,7 @@ module Axlsx
110
109
  # @return [Integer]
111
110
  attr_reader :sz
112
111
 
113
- # @see name
112
+ # @see name
114
113
  def name=(v) Axlsx::validate_string v; @name = v end
115
114
  # @see charset
116
115
  def charset=(v) Axlsx::validate_unsigned_int v; @charset = v end
@@ -120,6 +119,7 @@ module Axlsx
120
119
  def b=(v) Axlsx::validate_boolean v; @b = v end
121
120
  # @see i
122
121
  def i=(v) Axlsx::validate_boolean v; @i = v end
122
+
123
123
  # @see u
124
124
  def u=(v)
125
125
  v = :single if (v == true || v == 1 || v == :true || v == 'true')
@@ -127,6 +127,7 @@ module Axlsx
127
127
  Axlsx::validate_cell_u v
128
128
  @u = v
129
129
  end
130
+
130
131
  # @see strike
131
132
  def strike=(v) Axlsx::validate_boolean v; @strike = v end
132
133
  # @see outline
@@ -138,9 +139,9 @@ module Axlsx
138
139
  # @see extend
139
140
  def extend=(v) Axlsx::validate_boolean v; @extend = v end
140
141
  # @see color
141
- def color=(v) DataTypeValidator.validate "Font.color", Color, v; @color=v end
142
+ def color=(v) DataTypeValidator.validate "Font.color", Color, v; @color = v end
142
143
  # @see sz
143
- def sz=(v) Axlsx::validate_unsigned_int v; @sz=v end
144
+ def sz=(v) Axlsx::validate_unsigned_int v; @sz = v end
144
145
 
145
146
  # Serializes the object
146
147
  # @param [String] str
@@ -1,9 +1,7 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # A GradientFill defines the color and positioning for gradiant cell fill.
4
3
  # @see Open Office XML Part 1 §18.8.24
5
4
  class GradientFill
6
-
7
5
  include Axlsx::OptionsParser
8
6
  include Axlsx::SerializedAttributes
9
7
 
@@ -14,7 +12,7 @@ module Axlsx
14
12
  # @option options [Float] right
15
13
  # @option options [Float] top
16
14
  # @option options [Float] bottom
17
- def initialize(options={})
15
+ def initialize(options = {})
18
16
  options[:type] ||= :linear
19
17
  parse_options options
20
18
  @stop = SimpleTypedList.new GradientStop
@@ -68,8 +66,8 @@ module Axlsx
68
66
 
69
67
  # @see right
70
68
  def right=(v)
71
- validate_format_percentage "GradientFill.right", v
72
- @right = v
69
+ validate_format_percentage "GradientFill.right", v
70
+ @right = v
73
71
  end
74
72
 
75
73
  # @see top
@@ -86,7 +84,7 @@ module Axlsx
86
84
 
87
85
  # validates that the value provided is between 0.0 and 1.0
88
86
  def validate_format_percentage(name, value)
89
- DataTypeValidator.validate name, Float, value, lambda { |arg| arg >= 0.0 && arg <= 1.0}
87
+ DataTypeValidator.validate name, Float, value, lambda { |arg| arg >= 0.0 && arg <= 1.0 }
90
88
  end
91
89
 
92
90
  # Serializes the object
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # The GradientStop object represents a color point in a gradient.
4
3
  # @see Open Office XML Part 1 §18.8.24
@@ -21,9 +20,9 @@ module Axlsx
21
20
  end
22
21
 
23
22
  # @see color
24
- def color=(v) DataTypeValidator.validate "GradientStop.color", Color, v; @color=v end
23
+ def color=(v) DataTypeValidator.validate "GradientStop.color", Color, v; @color = v end
25
24
  # @see position
26
- def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1}; @position = v end
25
+ def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1 }; @position = v end
27
26
 
28
27
  # Serializes the object
29
28
  # @param [String] str
@@ -1,9 +1,7 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # A NumFmt object defines an identifier and formatting code for data in cells.
4
3
  # @note The recommended way to manage styles is Styles#add_style
5
4
  class NumFmt
6
-
7
5
  include Axlsx::OptionsParser
8
6
  include Axlsx::SerializedAttributes
9
7
 
@@ -11,7 +9,7 @@ module Axlsx
11
9
  # @param [Hash] options Options for the number format object
12
10
  # @option [Integer] numFmtId The predefined format id or new format id for this format
13
11
  # @option [String] formatCode The format code for this number format
14
- def initialize(options={})
12
+ def initialize(options = {})
15
13
  @numFmtId = 0
16
14
  @formatCode = ""
17
15
  parse_options options
@@ -81,6 +79,5 @@ module Axlsx
81
79
  end
82
80
  str
83
81
  end
84
-
85
82
  end
86
83
  end
@@ -1,16 +1,14 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # A PatternFill is the pattern and solid fill styling for a cell.
4
3
  # @note The recommended way to manage styles is with Styles#add_style
5
4
  # @see Style#add_style
6
5
  class PatternFill
7
-
8
6
  include Axlsx::OptionsParser
9
7
  # Creates a new PatternFill Object
10
8
  # @option options [Symbol] patternType
11
9
  # @option options [Color] fgColor
12
10
  # @option options [Color] bgColor
13
- def initialize(options={})
11
+ def initialize(options = {})
14
12
  @patternType = :none
15
13
  parse_options options
16
14
  end
@@ -49,9 +47,9 @@ module Axlsx
49
47
  attr_reader :patternType
50
48
 
51
49
  # @see fgColor
52
- def fgColor=(v) DataTypeValidator.validate "PatternFill.fgColor", Color, v; @fgColor=v end
50
+ def fgColor=(v) DataTypeValidator.validate "PatternFill.fgColor", Color, v; @fgColor = v end
53
51
  # @see bgColor
54
- def bgColor=(v) DataTypeValidator.validate "PatternFill.bgColor", Color, v; @bgColor=v end
52
+ def bgColor=(v) DataTypeValidator.validate "PatternFill.bgColor", Color, v; @bgColor = v end
55
53
  # @see patternType
56
54
  def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
57
55
 
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  require 'axlsx/stylesheet/border.rb'
4
3
  require 'axlsx/stylesheet/border_pr.rb'
@@ -18,7 +17,7 @@ module Axlsx
18
17
  require 'axlsx/stylesheet/xf.rb'
19
18
  require 'axlsx/stylesheet/cell_protection.rb'
20
19
 
21
- #The Styles class manages worksheet styles
20
+ # The Styles class manages worksheet styles
22
21
  # 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.
23
22
  # All portions of the stylesheet are implemented here exception colors, which specify legacy and modified pallete colors, and exLst, whic is used as a future feature data storage area.
24
23
  # @see Office Open XML Part 1 18.8.11 for gory details on how this stuff gets put together
@@ -137,7 +136,7 @@ module Axlsx
137
136
  # @option options [Integer] family The font family to use.
138
137
  # @option options [String] font_name The name of the font to use
139
138
  # @option options [Integer] num_fmt The number format to apply
140
- # @option options [String] format_code The formatting to apply.
139
+ # @option options [String] format_code The formatting to apply.
141
140
  # @option options [Integer|Hash] border The border style to use.
142
141
  # borders support style, color and edges options @see parse_border_options
143
142
  # @option options [String] bg_color The background color to apply to the cell
@@ -225,22 +224,26 @@ module Axlsx
225
224
  #
226
225
  # An index for cell styles where keys are styles codes as per Axlsx::Style and values are Cell#raw_style
227
226
  # The reason for the backward key/value ordering is that style lookup must be most efficient, while `add_style` can be less efficient
228
- def add_style(options={})
227
+ def add_style(options = {})
229
228
  # Default to :xf
230
229
  options[:type] ||= :xf
231
230
 
232
- raise ArgumentError, "Type must be one of [:xf, :dxf]" unless [:xf, :dxf].include?(options[:type] )
231
+ raise ArgumentError, "Type must be one of [:xf, :dxf]" unless [:xf, :dxf].include?(options[:type])
233
232
 
234
- if options[:border].is_a?(Hash) && options[:border][:edges] == :all
235
- options[:border][:edges] = Axlsx::Border::EDGES
233
+ if options[:border].is_a?(Hash)
234
+ if options[:border][:edges] == :all
235
+ options[:border][:edges] = Axlsx::Border::EDGES
236
+ elsif options[:border][:edges]
237
+ options[:border][:edges] = options[:border][:edges].map(&:to_sym) ### normalize for style caching
238
+ end
236
239
  end
237
240
 
238
241
  if options[:type] == :xf
239
242
  # Check to see if style in cache already
240
-
241
- font_defaults = {name: @fonts.first.name, sz: @fonts.first.sz, family: @fonts.first.family}
242
243
 
243
- raw_style = {type: :xf}.merge(font_defaults).merge(options)
244
+ font_defaults = { name: @fonts.first.name, sz: @fonts.first.sz, family: @fonts.first.family }
245
+
246
+ raw_style = { type: :xf }.merge(font_defaults).merge(options)
244
247
 
245
248
  if raw_style[:format_code]
246
249
  raw_style.delete(:num_fmt)
@@ -264,7 +267,7 @@ module Axlsx
264
267
  when :dxf
265
268
  style = Dxf.new :fill => fill, :font => font, :numFmt => numFmt, :border => border, :alignment => alignment, :protection => protection
266
269
  else
267
- style = 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?
270
+ style = 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?
268
271
  end
269
272
 
270
273
  if options[:type] == :xf
@@ -287,8 +290,9 @@ module Axlsx
287
290
  # @option options [Boolean] hide boolean value defining cell protection attribute for hiding.
288
291
  # @option options [Boolean] locked boolean value defining cell protection attribute for locking.
289
292
  # @return [CellProtection]
290
- def parse_protection_options(options={})
293
+ def parse_protection_options(options = {})
291
294
  return if (options.keys & [:hidden, :locked]).empty?
295
+
292
296
  CellProtection.new(options)
293
297
  end
294
298
 
@@ -297,8 +301,9 @@ module Axlsx
297
301
  # @option options [Hash] alignment A hash of options to prive the CellAlignment intializer
298
302
  # @return [CellAlignment]
299
303
  # @see CellAlignment
300
- def parse_alignment_options(options={})
304
+ def parse_alignment_options(options = {})
301
305
  return unless options[:alignment]
306
+
302
307
  CellAlignment.new options[:alignment]
303
308
  end
304
309
 
@@ -317,8 +322,9 @@ module Axlsx
317
322
  # @option options [Integer] family The font family to use.
318
323
  # @option options [String] font_name The name of the font to use
319
324
  # @return [Font|Integer]
320
- def parse_font_options(options={})
325
+ def parse_font_options(options = {})
321
326
  return if (options.keys & [:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name]).empty?
327
+
322
328
  Axlsx.instance_values_for(fonts.first).each do |key, value|
323
329
  # Thanks for that 1.8.7 - cant do a simple merge...
324
330
  options[key.to_sym] = value unless options.keys.include?(key.to_sym)
@@ -333,31 +339,32 @@ module Axlsx
333
339
  # @note noop if :bg_color is not specified in options
334
340
  # @option options [String] bg_color The rgb color to apply to the fill
335
341
  # @return [Fill|Integer]
336
- def parse_fill_options(options={})
342
+ def parse_fill_options(options = {})
337
343
  return unless options[:bg_color]
338
- color = Color.new(:rgb=>options[:bg_color])
344
+
345
+ color = Color.new(:rgb => options[:bg_color])
339
346
  dxf = options[:type] == :dxf
340
347
  color_key = dxf ? :bgColor : :fgColor
341
- pattern = PatternFill.new(:patternType =>:solid, color_key=>color)
348
+ pattern = PatternFill.new(:patternType => :solid, color_key => color)
342
349
  fill = Fill.new(pattern)
343
350
  dxf ? fill : fills << fill
344
351
  end
345
352
 
346
353
  # parses Style#add_style options for borders.
347
354
  # @note noop if :border is not specified in options
348
- # @option options [Hash|Integer] A border style definition hash or the index of an existing border.
349
- # Border style definition hashes must include :style and :color key-value entries and
350
- # may include an :edges entry that references an array of symbols identifying which border edges
355
+ # @option options [Hash|Integer] A border style definition hash or the index of an existing border.
356
+ # Border style definition hashes must include :style and :color key-value entries and
357
+ # may include an :edges entry that references an array of symbols identifying which border edges
351
358
  # you wish to apply the style or any other valid Border initializer options.
352
359
  # If the :edges entity is not provided the style is applied to all edges of cells that reference this style.
353
- # Also available :border_top, :border_right, :border_bottom and :border_left options with :style and/or :color
360
+ # Also available :border_top, :border_right, :border_bottom and :border_left options with :style and/or :color
354
361
  # key-value entries, which override :border values.
355
362
  # @example
356
363
  # #apply a thick red border to the top and bottom
357
364
  # { :border => { :style => :thick, :color => "FFFF0000", :edges => [:top, :bottom] }
358
365
  # @return [Border|Integer]
359
- def parse_border_options(options={})
360
- if options[:border].nil? && Border::EDGES.all?{|x| options["border_#{x}".to_sym].nil? }
366
+ def parse_border_options(options = {})
367
+ if options[:border].nil? && Border::EDGES.all? { |x| options["border_#{x}".to_sym].nil? }
361
368
  return nil
362
369
  end
363
370
 
@@ -373,7 +380,7 @@ module Axlsx
373
380
  end
374
381
  end
375
382
 
376
- validate_border_hash = ->(val){
383
+ validate_border_hash = ->(val) {
377
384
  if !(val.keys.include?(:style) && val.keys.include?(:color))
378
385
  raise ArgumentError, (ERR_INVALID_BORDER_OPTIONS % options[:border])
379
386
  end
@@ -440,10 +447,10 @@ module Axlsx
440
447
  end
441
448
 
442
449
  border.prs << BorderPr.new({
443
- :name => edge,
444
- :style => edge_b_opts[:style],
445
- :color => Color.new(:rgb => edge_b_opts[:color]) },
446
- )
450
+ :name => edge,
451
+ :style => edge_b_opts[:style],
452
+ :color => Color.new(:rgb => edge_b_opts[:color])
453
+ })
447
454
  end
448
455
  end
449
456
 
@@ -458,15 +465,15 @@ module Axlsx
458
465
  # noop if neither :format_code or :num_format options are set.
459
466
  # @option options [Hash] A hash describing the :format_code and/or :num_fmt integer for the style.
460
467
  # @return [NumFmt|Integer]
461
- def parse_num_fmt_options(options={})
468
+ def parse_num_fmt_options(options = {})
462
469
  return if (options.keys & [:format_code, :num_fmt]).empty?
463
470
 
464
- #When the user provides format_code - we always need to create a new numFmt object
465
- #When the type is :dxf we always need to create a new numFmt object
471
+ # When the user provides format_code - we always need to create a new numFmt object
472
+ # When the type is :dxf we always need to create a new numFmt object
466
473
  if options[:format_code] || options[:type] == :dxf
467
- #If this is a standard xf we pull from numFmts the highest current and increment for num_fmt
468
- options[:num_fmt] ||= (@numFmts.map{ |num_fmt| num_fmt.numFmtId }.max + 1) if options[:type] != :dxf
469
- numFmt = NumFmt.new(:numFmtId => options[:num_fmt] || 0, :formatCode=> options[:format_code].to_s)
474
+ # If this is a standard xf we pull from numFmts the highest current and increment for num_fmt
475
+ options[:num_fmt] ||= (@numFmts.map { |num_fmt| num_fmt.numFmtId }.max + 1) if options[:type] != :dxf
476
+ numFmt = NumFmt.new(:numFmtId => options[:num_fmt] || 0, :formatCode => options[:format_code].to_s)
470
477
  options[:type] == :dxf ? numFmt : (numFmts << numFmt; numFmt.numFmtId)
471
478
  else
472
479
  options[:num_fmt]
@@ -486,46 +493,47 @@ module Axlsx
486
493
  end
487
494
 
488
495
  private
496
+
489
497
  # Creates the default set of styles the exel requires to be valid as well as setting up the
490
498
  # Axlsx::STYLE_THIN_BORDER
491
499
  def load_default_styles
492
500
  @numFmts = SimpleTypedList.new NumFmt, 'numFmts'
493
- @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode=> "yyyy/mm/dd")
494
- @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDDHHMMSS, :formatCode=> "yyyy/mm/dd hh:mm:ss")
501
+ @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode => "yyyy/mm/dd")
502
+ @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDDHHMMSS, :formatCode => "yyyy/mm/dd hh:mm:ss")
495
503
 
496
504
  @numFmts.lock
497
505
 
498
506
  @fonts = SimpleTypedList.new Font, 'fonts'
499
- @fonts << Font.new(:name => "Arial", :sz => 11, :family=>1)
507
+ @fonts << Font.new(:name => "Arial", :sz => 11, :family => 1)
500
508
  @fonts.lock
501
509
 
502
510
  @fills = SimpleTypedList.new Fill, 'fills'
503
- @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:none))
504
- @fills << Fill.new(Axlsx::PatternFill.new(:patternType=>:gray125))
511
+ @fills << Fill.new(Axlsx::PatternFill.new(:patternType => :none))
512
+ @fills << Fill.new(Axlsx::PatternFill.new(:patternType => :gray125))
505
513
  @fills.lock
506
514
 
507
515
  @borders = SimpleTypedList.new Border, 'borders'
508
516
  @borders << Border.new
509
517
  black_border = Border.new
510
518
  [:left, :right, :top, :bottom].each do |item|
511
- black_border.prs << BorderPr.new(:name=>item, :style=>:thin, :color=>Color.new(:rgb=>"FF000000"))
519
+ black_border.prs << BorderPr.new(:name => item, :style => :thin, :color => Color.new(:rgb => "FF000000"))
512
520
  end
513
521
  @borders << black_border
514
522
  @borders.lock
515
523
 
516
524
  @cellStyleXfs = SimpleTypedList.new Xf, "cellStyleXfs"
517
- @cellStyleXfs << Xf.new(:borderId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
525
+ @cellStyleXfs << Xf.new(:borderId => 0, :numFmtId => 0, :fontId => 0, :fillId => 0)
518
526
  @cellStyleXfs.lock
519
527
 
520
528
  @cellStyles = SimpleTypedList.new CellStyle, 'cellStyles'
521
- @cellStyles << CellStyle.new(:name =>"Normal", :builtinId =>0, :xfId=>0)
529
+ @cellStyles << CellStyle.new(:name => "Normal", :builtinId => 0, :xfId => 0)
522
530
  @cellStyles.lock
523
531
 
524
532
  @cellXfs = SimpleTypedList.new Xf, "cellXfs"
525
- @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
526
- @cellXfs << Xf.new(:borderId=>1, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
533
+ @cellXfs << Xf.new(:borderId => 0, :xfId => 0, :numFmtId => 0, :fontId => 0, :fillId => 0)
534
+ @cellXfs << Xf.new(:borderId => 1, :xfId => 0, :numFmtId => 0, :fontId => 0, :fillId => 0)
527
535
  # default date formatting
528
- @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>14, :fontId=>0, :fillId=>0, :applyNumberFormat=>1)
536
+ @cellXfs << Xf.new(:borderId => 0, :xfId => 0, :numFmtId => 14, :fontId => 0, :fillId => 0, :applyNumberFormat => 1)
529
537
  @cellXfs.lock
530
538
 
531
539
  @dxfs = SimpleTypedList.new(Dxf, "dxfs"); @dxfs.lock
@@ -1,9 +1,7 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # A single table style definition and is a collection for tableStyleElements
4
3
  # @note Table are not supported in this version and only the defaults required for a valid workbook are created.
5
4
  class TableStyle < SimpleTypedList
6
-
7
5
  include Axlsx::OptionsParser
8
6
  include Axlsx::SerializedAttributes
9
7
 
@@ -12,7 +10,7 @@ module Axlsx
12
10
  # @param [String] name
13
11
  # @option options [Boolean] pivot
14
12
  # @option options [Boolean] table
15
- def initialize(name, options={})
13
+ def initialize(name, options = {})
16
14
  self.name = name
17
15
  parse_options options
18
16
  super TableStyleElement
@@ -33,22 +31,21 @@ module Axlsx
33
31
  attr_reader :table
34
32
 
35
33
  # @see name
36
- def name=(v) Axlsx::validate_string v; @name=v end
34
+ def name=(v) Axlsx::validate_string v; @name = v end
37
35
  # @see pivot
38
- def pivot=(v) Axlsx::validate_boolean v; @pivot=v end
36
+ def pivot=(v) Axlsx::validate_boolean v; @pivot = v end
39
37
  # @see table
40
- def table=(v) Axlsx::validate_boolean v; @table=v end
38
+ def table=(v) Axlsx::validate_boolean v; @table = v end
41
39
 
42
40
  # Serializes the object
43
41
  # @param [String] str
44
42
  # @return [String]
45
43
  def to_xml_string(str = '')
46
44
  str << '<tableStyle '
47
- serialized_attributes str, {:count => self.size}
45
+ serialized_attributes str, { :count => self.size }
48
46
  str << '>'
49
47
  each { |table_style_el| table_style_el.to_xml_string(str) }
50
48
  str << '</tableStyle>'
51
49
  end
52
-
53
50
  end
54
51
  end
@@ -1,9 +1,7 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # an element of style that belongs to a table style.
4
3
  # @note tables and table styles are not supported in this version. This class exists in preparation for that support.
5
4
  class TableStyleElement
6
-
7
5
  include Axlsx::OptionsParser
8
6
  include Axlsx::SerializedAttributes
9
7
 
@@ -11,7 +9,7 @@ module Axlsx
11
9
  # @option options [Symbol] type
12
10
  # @option options [Integer] size
13
11
  # @option options [Integer] dxfId
14
- def initialize(options={})
12
+ def initialize(options = {})
15
13
  parse_options options
16
14
  end
17
15
 
@@ -72,6 +70,5 @@ module Axlsx
72
70
  def to_xml_string(str = '')
73
71
  serialized_tag('tableStyleElement', str)
74
72
  end
75
-
76
73
  end
77
74
  end
@@ -1,15 +1,13 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # TableStyles represents a collection of style definitions for table styles and pivot table styles.
4
3
  # @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.
5
4
  class TableStyles < SimpleTypedList
6
-
7
5
  include Axlsx::SerializedAttributes
8
6
 
9
7
  # Creates a new TableStyles object that is a container for TableStyle objects
10
8
  # @option options [String] defaultTableStyle
11
9
  # @option options [String] defaultPivotStyle
12
- def initialize(options={})
10
+ def initialize(options = {})
13
11
  @defaultTableStyle = options[:defaultTableStyle] || "TableStyleMedium9"
14
12
  @defaultPivotStyle = options[:defaultPivotStyle] || "PivotStyleLight16"
15
13
  super TableStyle
@@ -25,7 +23,7 @@ module Axlsx
25
23
  # @return [String]
26
24
  attr_reader :defaultPivotStyle
27
25
 
28
- # @see defaultTableStyle
26
+ # @see defaultTableStyle
29
27
  def defaultTableStyle=(v) Axlsx::validate_string(v); @defaultTableStyle = v; end
30
28
  # @see defaultPivotStyle
31
29
  def defaultPivotStyle=(v) Axlsx::validate_string(v); @defaultPivotStyle = v; end
@@ -35,12 +33,10 @@ module Axlsx
35
33
  # @return [String]
36
34
  def to_xml_string(str = '')
37
35
  str << '<tableStyles '
38
- serialized_attributes str, {:count => self.size }
36
+ serialized_attributes str, { :count => self.size }
39
37
  str << '>'
40
38
  each { |table_style| table_style.to_xml_string(str) }
41
39
  str << '</tableStyles>'
42
40
  end
43
-
44
41
  end
45
-
46
42
  end
@@ -1,9 +1,8 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # The Xf class defines a formatting record for use in Styles. The recommended way to manage styles for your workbook is with Styles#add_style
4
3
  # @see Styles#add_style
5
4
  class Xf
6
- #does not support extList (ExtensionList)
5
+ # does not support extList (ExtensionList)
7
6
 
8
7
  include Axlsx::SerializedAttributes
9
8
  include Axlsx::OptionsParser
@@ -23,7 +22,7 @@ module Axlsx
23
22
  # @option options [Boolean] applyProtection
24
23
  # @option options [CellAlignment] alignment
25
24
  # @option options [CellProtection] protection
26
- def initialize(options={})
25
+ def initialize(options = {})
27
26
  parse_options options
28
27
  end
29
28
 
@@ -93,7 +92,7 @@ module Axlsx
93
92
  # @return [Boolean]
94
93
  attr_reader :applyProtection
95
94
 
96
- # @see Xf#alignment
95
+ # @see Xf#alignment
97
96
  def alignment=(v) DataTypeValidator.validate "Xf.alignment", CellAlignment, v; @alignment = v end
98
97
 
99
98
  # @see protection
@@ -141,7 +140,5 @@ module Axlsx
141
140
  protection.to_xml_string(str) if self.protection
142
141
  str << '</xf>'
143
142
  end
144
-
145
-
146
143
  end
147
144
  end