axlsx 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. data/README.md +13 -5
  2. data/examples/colored_links.rb +59 -0
  3. data/examples/example.rb +421 -266
  4. data/examples/example.xlsx +0 -0
  5. data/examples/example_streamed.xlsx +0 -0
  6. data/examples/finance.rb +82 -0
  7. data/examples/finance.xlsx +0 -0
  8. data/examples/financial.xlsx +0 -0
  9. data/examples/no-use_autowidth.xlsx +0 -0
  10. data/examples/shared_strings_example.xlsx +0 -0
  11. data/examples/where_is_my_color.xlsx +0 -0
  12. data/lib/axlsx.rb +11 -4
  13. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  14. data/lib/axlsx/content_type/content_type.rb +1 -1
  15. data/lib/axlsx/content_type/default.rb +6 -37
  16. data/lib/axlsx/content_type/override.rb +6 -38
  17. data/lib/axlsx/doc_props/app.rb +7 -4
  18. data/lib/axlsx/drawing/axis.rb +3 -3
  19. data/lib/axlsx/drawing/chart.rb +2 -3
  20. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  21. data/lib/axlsx/drawing/drawing.rb +6 -0
  22. data/lib/axlsx/drawing/hyperlink.rb +40 -32
  23. data/lib/axlsx/drawing/marker.rb +13 -13
  24. data/lib/axlsx/drawing/num_data.rb +6 -6
  25. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  26. data/lib/axlsx/drawing/one_cell_anchor.rb +20 -22
  27. data/lib/axlsx/drawing/pic.rb +25 -27
  28. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  29. data/lib/axlsx/drawing/scaling.rb +13 -13
  30. data/lib/axlsx/drawing/scatter_chart.rb +3 -3
  31. data/lib/axlsx/drawing/series.rb +3 -6
  32. data/lib/axlsx/drawing/str_data.rb +3 -3
  33. data/lib/axlsx/drawing/str_val.rb +7 -8
  34. data/lib/axlsx/drawing/view_3D.rb +51 -37
  35. data/lib/axlsx/drawing/vml_shape.rb +23 -23
  36. data/lib/axlsx/package.rb +14 -16
  37. data/lib/axlsx/stylesheet/border.rb +29 -20
  38. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  39. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  40. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  41. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  42. data/lib/axlsx/stylesheet/color.rb +19 -16
  43. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  44. data/lib/axlsx/stylesheet/font.rb +22 -22
  45. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  46. data/lib/axlsx/stylesheet/num_fmt.rb +22 -13
  47. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  48. data/lib/axlsx/stylesheet/styles.rb +1 -1
  49. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  50. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  51. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  52. data/lib/axlsx/stylesheet/xf.rb +28 -26
  53. data/lib/axlsx/util/accessors.rb +49 -0
  54. data/lib/axlsx/util/options_parser.rb +15 -0
  55. data/lib/axlsx/util/serialized_attributes.rb +46 -0
  56. data/lib/axlsx/util/simple_typed_list.rb +16 -4
  57. data/lib/axlsx/version.rb +1 -1
  58. data/lib/axlsx/workbook/defined_name.rb +13 -58
  59. data/lib/axlsx/workbook/workbook.rb +27 -1
  60. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -19
  61. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +20 -27
  62. data/lib/axlsx/workbook/worksheet/cell.rb +38 -39
  63. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  64. data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -0
  65. data/lib/axlsx/workbook/worksheet/col.rb +34 -27
  66. data/lib/axlsx/workbook/worksheet/color_scale.rb +7 -13
  67. data/lib/axlsx/workbook/worksheet/comment.rb +14 -11
  68. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  69. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +27 -25
  70. data/lib/axlsx/workbook/worksheet/data_bar.rb +44 -34
  71. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  72. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  73. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  74. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  75. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -9
  76. data/lib/axlsx/workbook/worksheet/page_setup.rb +20 -19
  77. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  78. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  79. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  80. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  81. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -26
  82. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +19 -57
  83. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  84. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  85. data/lib/axlsx/workbook/worksheet/table.rb +16 -18
  86. data/lib/axlsx/workbook/worksheet/table_style_info.rb +10 -27
  87. data/lib/axlsx/workbook/worksheet/worksheet.rb +6 -7
  88. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
  89. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +11 -33
  90. data/test/content_type/tc_default.rb +0 -11
  91. data/test/content_type/tc_override.rb +0 -13
  92. data/test/drawing/tc_d_lbls.rb +14 -4
  93. data/test/tc_axlsx.rb +20 -2
  94. data/test/workbook/tc_defined_name.rb +2 -2
  95. data/test/workbook/tc_workbook.rb +15 -0
  96. data/test/workbook/worksheet/tc_col.rb +11 -1
  97. data/test/workbook/worksheet/tc_pane.rb +5 -45
  98. data/test/workbook/worksheet/tc_selection.rb +9 -48
  99. metadata +13 -3
@@ -3,6 +3,19 @@ module Axlsx
3
3
  # The Scaling class defines axis scaling
4
4
  class Scaling
5
5
 
6
+ include Axlsx::OptionsParser
7
+
8
+ # creates a new Scaling object
9
+ # @option options [Integer, Fixnum] logBase
10
+ # @option options [Symbol] orientation
11
+ # @option options [Float] max
12
+ # @option options [Float] min
13
+ def initialize(options={})
14
+ @orientation = :minMax
15
+ @logBase, @min, @max = nil, nil, nil
16
+ parse_options options
17
+ end
18
+
6
19
  # logarithmic base for a logarithmic axis.
7
20
  # must be between 2 and 1000
8
21
  # @return [Integer]
@@ -21,19 +34,6 @@ module Axlsx
21
34
  # @return [Float]
22
35
  attr_reader :min
23
36
 
24
- # creates a new Scaling object
25
- # @option options [Integer, Fixnum] logBase
26
- # @option options [Symbol] orientation
27
- # @option options [Float] max
28
- # @option options [Float] min
29
- def initialize(options={})
30
- @orientation = :minMax
31
- @logBase, @min, @max = nil, nil, nil
32
- options.each do |o|
33
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
34
- end
35
- end
36
-
37
37
  # @see logBase
38
38
  def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer, Fixnum], v, lambda { |arg| arg >= 2 && arg <= 1000}; @logBase = v; end
39
39
  # @see orientation
@@ -7,6 +7,8 @@ module Axlsx
7
7
  # @see README for an example
8
8
  class ScatterChart < Chart
9
9
 
10
+ include Axlsx::OptionsParser
11
+
10
12
  # The Style for the scatter chart
11
13
  # must be one of :none | :line | :lineMarker | :marker | :smooth | :smoothMarker
12
14
  # return [Symbol]
@@ -30,9 +32,7 @@ module Axlsx
30
32
  super(frame, options)
31
33
  @series_type = ScatterSeries
32
34
  @d_lbls = nil
33
- options.each do |o|
34
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
35
- end
35
+ parse_options options
36
36
  end
37
37
 
38
38
  # see #scatterStyle
@@ -6,6 +6,8 @@ module Axlsx
6
6
  # @see Chart#add_series
7
7
  class Series
8
8
 
9
+ include Axlsx::OptionsParser
10
+
9
11
  # The chart that owns this series
10
12
  # @return [Chart]
11
13
  attr_reader :chart
@@ -22,19 +24,15 @@ module Axlsx
22
24
  @order = nil
23
25
  self.chart = chart
24
26
  @chart.series << self
25
- options.each do |o|
26
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
27
- end
27
+ parse_options options
28
28
  end
29
29
 
30
-
31
30
  # The index of this series in the chart's series.
32
31
  # @return [Integer]
33
32
  def index
34
33
  @chart.series.index(self)
35
34
  end
36
35
 
37
-
38
36
  # The order of this series in the chart's series. By default the order is the index of the series.
39
37
  # @return [Integer]
40
38
  def order
@@ -68,5 +66,4 @@ module Axlsx
68
66
  str << '</c:ser>'
69
67
  end
70
68
  end
71
-
72
69
  end
@@ -5,6 +5,8 @@ module Axlsx
5
5
  # This class is extended for NumData to include the formatCode attribute required for numLit and numCache
6
6
  class StrData
7
7
 
8
+ include Axlsx::OptionsParser
9
+
8
10
  # creates a new StrVal object
9
11
  # @option options [Array] :data
10
12
  # @option options [String] :tag_name
@@ -12,9 +14,7 @@ module Axlsx
12
14
  @tag_prefix = :str
13
15
  @type = StrVal
14
16
  @pt = SimpleTypedList.new(@type)
15
- options.each do |o|
16
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
17
- end
17
+ parse_options options
18
18
  end
19
19
 
20
20
  # Creates the val objects for this data set. I am not overly confident this is going to play nicely with time and data types.
@@ -4,19 +4,20 @@ module Axlsx
4
4
  #This class specifies data for a particular data point.
5
5
  class StrVal
6
6
 
7
- # a string value.
8
- # @return [String]
9
- attr_reader :v
7
+ include Axlsx::OptionsParser
10
8
 
11
9
  # creates a new StrVal object
12
10
  # @option options [String] v
13
11
  def initialize(options={})
14
12
  @v = ""
15
13
  @idx = 0
16
- options.each do |o|
17
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
18
- end
14
+ parse_options options
19
15
  end
16
+
17
+ # a string value.
18
+ # @return [String]
19
+ attr_reader :v
20
+
20
21
  # @see v
21
22
  def v=(v)
22
23
  @v = v.to_s
@@ -27,7 +28,5 @@ module Axlsx
27
28
  Axlsx::validate_unsigned_int(idx)
28
29
  str << '<c:pt idx="' << idx.to_s << '"><c:v>' << v.to_s << '</c:v></c:pt>'
29
30
  end
30
-
31
31
  end
32
-
33
32
  end
@@ -3,6 +3,20 @@ module Axlsx
3
3
  # 3D attributes for a chart.
4
4
  class View3D
5
5
 
6
+ include Axlsx::OptionsParser
7
+
8
+ # Creates a new View3D for charts
9
+ # @option options [Integer] rot_x
10
+ # @option options [String] h_percent
11
+ # @option options [Integer] rot_y
12
+ # @option options [String] depth_percent
13
+ # @option options [Boolean] r_ang_ax
14
+ # @option options [Integer] perspective
15
+ def initialize(options={})
16
+ @rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
17
+ parse_options options
18
+ end
19
+
6
20
  # Validation for hPercent
7
21
  H_PERCENT_REGEX = /0*(([5-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)/
8
22
 
@@ -14,7 +28,7 @@ module Axlsx
14
28
  # @return [Integer]
15
29
  attr_reader :rot_x
16
30
  alias :rotX :rot_x
17
-
31
+
18
32
  # height of chart as % of chart width
19
33
  # must be between 5% and 500%
20
34
  # @return [String]
@@ -26,7 +40,7 @@ module Axlsx
26
40
  # @return [Integer]
27
41
  attr_reader :rot_y
28
42
  alias :rotY :rot_y
29
-
43
+
30
44
  # depth or chart as % of chart width
31
45
  # must be between 20% and 2000%
32
46
  # @return [String]
@@ -42,60 +56,60 @@ module Axlsx
42
56
  # @return [Integer]
43
57
  attr_reader :perspective
44
58
 
45
- # Creates a new View3D for charts
46
- # @option options [Integer] rot_x
47
- # @option options [String] h_percent
48
- # @option options [Integer] rot_y
49
- # @option options [String] depth_percent
50
- # @option options [Boolean] r_ang_ax
51
- # @option options [Integer] perspective
52
- def initialize(options={})
53
- @rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
54
- options.each do |o|
55
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
56
- end
57
- end
58
-
59
59
  # @see rot_x
60
- def rot_x=(v) DataTypeValidator.validate "#{self.class}.rot_x", [Integer, Fixnum], v, lambda {|arg| arg >= -90 && arg <= 90 }; @rot_x = v; end
60
+ def rot_x=(v)
61
+ RangeValidator.validate "View3D.rot_x", -90, 90, v
62
+ @rot_x = v
63
+ end
61
64
  alias :rotX= :rot_x=
62
65
 
63
- # @see h_percent
64
- def h_percent=(v)
65
- RegexValidator.validate "#{self.class}.h_percent", H_PERCENT_REGEX, v
66
- @h_percent = v
67
- end
66
+ # @see h_percent
67
+ def h_percent=(v)
68
+ RegexValidator.validate "#{self.class}.h_percent", H_PERCENT_REGEX, v
69
+ @h_percent = v
70
+ end
68
71
  alias :hPercent= :h_percent=
69
72
 
70
- # @see rot_y
71
- def rot_y=(v) DataTypeValidator.validate "#{self.class}.rot_y", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 360 }; @rot_y = v; end
73
+ # @see rot_y
74
+ def rot_y=(v)
75
+ RangeValidator.validate "View3D.rot_y", 0, 360, v
76
+ @rot_y = v
77
+ end
72
78
  alias :rotY= :rot_y=
73
79
 
74
- # @see depth_percent
75
- def depth_percent=(v) RegexValidator.validate "#{self.class}.depth_percent", DEPTH_PERCENT_REGEX, v; @depth_percent = v; end
80
+ # @see depth_percent
81
+ def depth_percent=(v) RegexValidator.validate "#{self.class}.depth_percent", DEPTH_PERCENT_REGEX, v; @depth_percent = v; end
76
82
  alias :depthPercent= :depth_percent=
77
83
 
78
- # @see r_ang_ax
79
- def r_ang_ax=(v) Axlsx::validate_boolean(v); @r_ang_ax = v; end
84
+ # @see r_ang_ax
85
+ def r_ang_ax=(v) Axlsx::validate_boolean(v); @r_ang_ax = v; end
80
86
  alias :rAngAx= :r_ang_ax=
81
-
82
- # @see perspective
83
- def perspective=(v) DataTypeValidator.validate "#{self.class}.perspective", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
84
87
 
88
+ # @see perspective
89
+ def perspective=(v)
90
+ RangeValidator.validate "View3D.perspective", 0, 240, v
91
+ @perspective = v
92
+ end
93
+
94
+ # DataTypeValidator.validate "#{self.class}.perspective", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
85
95
 
86
96
  # Serializes the object
87
97
  # @param [String] str
88
98
  # @return [String]
89
99
  def to_xml_string(str = '')
90
100
  str << '<c:view3D>'
91
- str << '<c:rotX val="' << @rot_x.to_s << '"/>' unless @rot_x.nil?
92
- str << '<c:hPercent val="' << @h_percent.to_s << '"/>' unless @h_percent.nil?
93
- str << '<c:rotY val="' << @rot_y.to_s << '"/>' unless @rot_y.nil?
94
- str << '<c:depthPercent val="' << @depth_percent.to_s << '"/>' unless @depth_percent.nil?
95
- str << '<c:rAngAx val="' << @r_ang_ax.to_s << '"/>' unless @r_ang_ax.nil?
96
- str << '<c:perspective val="' << @perspective.to_s << '"/>' unless @perspective.nil?
101
+ %w(rot_x h_percent rot_y depth_percent r_ang_ax perspective).each do |key|
102
+ str << element_for_attribute(key, 'c')
103
+ end
97
104
  str << '</c:view3D>'
98
105
  end
99
106
 
107
+ private
108
+ # Note: move this to Axlsx module if we find the smae pattern elsewhere.
109
+ def element_for_attribute(name, namespace='')
110
+ val = instance_values[name]
111
+ return "" if val == nil
112
+ "<%s:%s val='%s'/>" % [namespace, Axlsx::camel(name, false), val]
113
+ end
100
114
  end
101
115
  end
@@ -3,6 +3,28 @@ module Axlsx
3
3
  # A VmlShape is used to position and render a comment.
4
4
  class VmlShape
5
5
 
6
+ include Axlsx::OptionsParser
7
+
8
+ # Creates a new VmlShape
9
+ # @option options [Integer|String] left_column
10
+ # @option options [Integer|String] left_offset
11
+ # @option options [Integer|String] top_row
12
+ # @option options [Integer|String] top_offset
13
+ # @option options [Integer|String] right_column
14
+ # @option options [Integer|String] right_offset
15
+ # @option options [Integer|String] bottom_row
16
+ # @option options [Integer|String] bottom_offset
17
+ def initialize(options={})
18
+ @row = @column = @left_column = @top_row = @right_column = @bottom_row = 0
19
+ @left_offset = 15
20
+ @top_offset = 2
21
+ @right_offset = 50
22
+ @bottom_offset = 5
23
+ @id = (0...8).map{65.+(rand(25)).chr}.join
24
+ parse_options options
25
+ yield self if block_given?
26
+ end
27
+
6
28
  # The row anchor position for this shape determined by the comment's ref value
7
29
  # @return [Integer]
8
30
  attr_reader :row
@@ -43,29 +65,7 @@ module Axlsx
43
65
  # @return [Integer]
44
66
  attr_reader :bottom_offset
45
67
 
46
- # Creates a new VmlShape
47
- # @option options [Integer|String] left_column
48
- # @option options [Integer|String] left_offset
49
- # @option options [Integer|String] top_row
50
- # @option options [Integer|String] top_offset
51
- # @option options [Integer|String] right_column
52
- # @option options [Integer|String] right_offset
53
- # @option options [Integer|String] bottom_row
54
- # @option options [Integer|String] bottom_offset
55
- def initialize(options={})
56
- @row = @column = @left_column = @top_row = @right_column = @bottom_row = 0
57
- @left_offset = 15
58
- @top_offset = 2
59
- @right_offset = 50
60
- @bottom_offset = 5
61
- @id = (0...8).map{65.+(rand(25)).chr}.join
62
- options.each do |o|
63
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
64
- end
65
- yield self if block_given?
66
- end
67
-
68
- # @see column
68
+ # @see column
69
69
  def column=(v); Axlsx::validate_integerish(v); @column = v.to_i end
70
70
 
71
71
  # @see row
@@ -3,7 +3,7 @@ module Axlsx
3
3
  # Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid
4
4
  # xlsx document including valdation and serialization.
5
5
  class Package
6
-
6
+ include Axlsx::OptionsParser
7
7
 
8
8
  # provides access to the app doc properties for this package
9
9
  # see App
@@ -23,9 +23,7 @@ module Axlsx
23
23
  @workbook = nil
24
24
  @core, @app = Core.new, App.new
25
25
  @core.creator = options[:author] || @core.creator
26
- options.each do |o|
27
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
28
- end
26
+ parse_options options
29
27
  yield self if block_given?
30
28
  end
31
29
 
@@ -175,7 +173,7 @@ module Axlsx
175
173
  # @return [Array] An array of hashes that define the entry, document and schema for each part of the package.
176
174
  # @private
177
175
  def parts
178
- @parts = [
176
+ parts = [
179
177
  {:entry => RELS_PN, :doc => relationships.to_xml_string, :schema => RELS_XSD},
180
178
  {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles.to_xml_string, :schema => SML_XSD},
181
179
  {:entry => CORE_PN, :doc => @core.to_xml_string, :schema => CORE_XSD},
@@ -186,39 +184,39 @@ module Axlsx
186
184
  ]
187
185
 
188
186
  workbook.drawings.each do |drawing|
189
- @parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships.to_xml_string, :schema => RELS_XSD}
190
- @parts << {:entry => "xl/#{drawing.pn}", :doc => drawing.to_xml_string, :schema => DRAWING_XSD}
187
+ parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships.to_xml_string, :schema => RELS_XSD}
188
+ parts << {:entry => "xl/#{drawing.pn}", :doc => drawing.to_xml_string, :schema => DRAWING_XSD}
191
189
  end
192
190
 
193
191
 
194
192
  workbook.tables.each do |table|
195
- @parts << {:entry => "xl/#{table.pn}", :doc => table.to_xml_string, :schema => SML_XSD}
193
+ parts << {:entry => "xl/#{table.pn}", :doc => table.to_xml_string, :schema => SML_XSD}
196
194
  end
197
195
 
198
196
  workbook.comments.each do|comment|
199
197
  if comment.size > 0
200
- @parts << { :entry => "xl/#{comment.pn}", :doc => comment.to_xml_string, :schema => SML_XSD }
201
- @parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing.to_xml_string, :schema => nil }
198
+ parts << { :entry => "xl/#{comment.pn}", :doc => comment.to_xml_string, :schema => SML_XSD }
199
+ parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing.to_xml_string, :schema => nil }
202
200
  end
203
201
  end
204
202
 
205
203
  workbook.charts.each do |chart|
206
- @parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml_string, :schema => DRAWING_XSD}
204
+ parts << {:entry => "xl/#{chart.pn}", :doc => chart.to_xml_string, :schema => DRAWING_XSD}
207
205
  end
208
206
 
209
207
  workbook.images.each do |image|
210
- @parts << {:entry => "xl/#{image.pn}", :path => image.image_src}
208
+ parts << {:entry => "xl/#{image.pn}", :path => image.image_src}
211
209
  end
212
210
 
213
211
  if use_shared_strings
214
- @parts << {:entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings.to_xml_string, :schema => SML_XSD}
212
+ parts << {:entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings.to_xml_string, :schema => SML_XSD}
215
213
  end
216
214
 
217
215
  workbook.worksheets.each do |sheet|
218
- @parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml_string, :schema => RELS_XSD}
219
- @parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml_string, :schema => SML_XSD}
216
+ parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships.to_xml_string, :schema => RELS_XSD}
217
+ parts << {:entry => "xl/#{sheet.pn}", :doc => sheet.to_xml_string, :schema => SML_XSD}
220
218
  end
221
- @parts
219
+ parts
222
220
  end
223
221
 
224
222
  # Performs xsd validation for a signle document
@@ -3,21 +3,12 @@ module Axlsx
3
3
  # This class details a border used in Office Open XML spreadsheet styles.
4
4
  class Border
5
5
 
6
- # @return [Boolean] The diagonal up property for the border that indicates if the border should include a diagonal line from the bottom left to the top right of the cell.
7
- attr_reader :diagonalUp
8
-
9
- # @return [Boolean] The diagonal down property for the border that indicates if the border should include a diagonal line from the top left to the top right of the cell.
10
- attr_reader :diagonalDown
11
-
12
- # @return [Boolean] The outline property for the border indicating that top, left, right and bottom borders should only be applied to the outside border of a range of cells.
13
- attr_reader :outline
14
-
15
- # @return [SimpleTypedList] A list of BorderPr objects for this border.
16
- attr_reader :prs
6
+ include Axlsx::SerializedAttributes
7
+ include Axlsx::OptionsParser
17
8
 
18
9
  # Creates a new Border object
19
- # @option options [Boolean] diagonalUp
20
- # @option options [Boolean] diagonalDown
10
+ # @option options [Boolean] diagonal_up
11
+ # @option options [Boolean] diagonal_down
21
12
  # @option options [Boolean] outline
22
13
  # @example - Making a border
23
14
  # p = Axlsx::Package.new
@@ -30,15 +21,33 @@ module Axlsx
30
21
  # @see Style#add_style
31
22
  def initialize(options={})
32
23
  @prs = SimpleTypedList.new BorderPr
33
- options.each do |o|
34
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
35
- end
24
+ parse_options options
36
25
  end
37
26
 
27
+ serializable_attributes :diagonal_up, :diagonal_down, :outline
28
+
29
+ # @return [Boolean] The diagonal up property for the border that indicates if the border should include a diagonal line from the bottom left to the top right of the cell.
30
+ attr_reader :diagonal_up
31
+ alias :diagonalUp :diagonal_up
32
+
33
+ # @return [Boolean] The diagonal down property for the border that indicates if the border should include a diagonal line from the top left to the top right of the cell.
34
+ attr_reader :diagonal_down
35
+ alias :diagonalDown :diagonal_down
36
+
37
+ # @return [Boolean] The outline property for the border indicating that top, left, right and bottom borders should only be applied to the outside border of a range of cells.
38
+ attr_reader :outline
39
+
40
+ # @return [SimpleTypedList] A list of BorderPr objects for this border.
41
+ attr_reader :prs
42
+
38
43
  # @see diagonalUp
39
- def diagonalUp=(v) Axlsx::validate_boolean v; @diagonalUp = v end
44
+ def diagonal_up=(v) Axlsx::validate_boolean v; @diagonal_up = v end
45
+ alias :diagonalUp= :diagonal_up=
46
+
40
47
  # @see diagonalDown
41
- def diagonalDown=(v) Axlsx::validate_boolean v; @diagonalDown = v end
48
+ def diagonal_down=(v) Axlsx::validate_boolean v; @diagonal_down = v end
49
+ alias :diagonalDown= :diagonal_down=
50
+
42
51
  # @see outline
43
52
  def outline=(v) Axlsx::validate_boolean v; @outline = v end
44
53
 
@@ -47,9 +56,9 @@ module Axlsx
47
56
  # @return [String]
48
57
  def to_xml_string(str = '')
49
58
  str << '<border '
50
- h = self.instance_values.select{ |k,v| [:diagonalUp, :diagonalDown, :outline].include? k }
51
- str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
59
+ serialized_attributes str
52
60
  str << '>'
61
+ # enforces order
53
62
  [:start, :end, :left, :right, :top, :bottom, :diagonal, :vertical, :horizontal].each do |k|
54
63
  @prs.select { |pr| pr.name == k }.each do |part|
55
64
  part.to_xml_string(str)