caxlsx 2.0.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +41 -33
  4. data/Rakefile +9 -11
  5. data/examples/auto_filter.rb +10 -1
  6. data/examples/conditional_formatting/example_conditional_formatting.rb +18 -3
  7. data/examples/data_validation.rb +57 -40
  8. data/examples/example.rb +115 -7
  9. data/examples/merge_cells.rb +17 -0
  10. data/examples/no_grid_with_borders.rb +18 -0
  11. data/examples/pivot_test.rb +63 -0
  12. data/examples/split.rb +16 -0
  13. data/lib/axlsx.rb +34 -15
  14. data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
  15. data/lib/axlsx/content_type/content_type.rb +1 -1
  16. data/lib/axlsx/doc_props/app.rb +1 -1
  17. data/lib/axlsx/doc_props/core.rb +5 -5
  18. data/lib/axlsx/drawing/area_chart.rb +99 -0
  19. data/lib/axlsx/drawing/area_series.rb +110 -0
  20. data/lib/axlsx/drawing/axes.rb +1 -1
  21. data/lib/axlsx/drawing/axis.rb +12 -9
  22. data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
  23. data/lib/axlsx/drawing/bar_chart.rb +143 -0
  24. data/lib/axlsx/drawing/bar_series.rb +9 -9
  25. data/lib/axlsx/drawing/bubble_chart.rb +59 -0
  26. data/lib/axlsx/drawing/bubble_series.rb +63 -0
  27. data/lib/axlsx/drawing/cat_axis.rb +5 -5
  28. data/lib/axlsx/drawing/chart.rb +52 -8
  29. data/lib/axlsx/drawing/d_lbls.rb +3 -3
  30. data/lib/axlsx/drawing/drawing.rb +6 -1
  31. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  32. data/lib/axlsx/drawing/hyperlink.rb +1 -3
  33. data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
  34. data/lib/axlsx/drawing/line_chart.rb +10 -10
  35. data/lib/axlsx/drawing/line_series.rb +32 -3
  36. data/lib/axlsx/drawing/marker.rb +1 -1
  37. data/lib/axlsx/drawing/num_data.rb +4 -4
  38. data/lib/axlsx/drawing/num_data_source.rb +6 -6
  39. data/lib/axlsx/drawing/num_val.rb +3 -1
  40. data/lib/axlsx/drawing/one_cell_anchor.rb +3 -2
  41. data/lib/axlsx/drawing/pic.rb +25 -19
  42. data/lib/axlsx/drawing/picture_locking.rb +1 -3
  43. data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
  44. data/lib/axlsx/drawing/pie_series.rb +6 -6
  45. data/lib/axlsx/drawing/scaling.rb +6 -6
  46. data/lib/axlsx/drawing/scatter_chart.rb +10 -10
  47. data/lib/axlsx/drawing/scatter_series.rb +40 -7
  48. data/lib/axlsx/drawing/ser_axis.rb +2 -2
  49. data/lib/axlsx/drawing/series.rb +3 -3
  50. data/lib/axlsx/drawing/series_title.rb +2 -2
  51. data/lib/axlsx/drawing/str_data.rb +3 -3
  52. data/lib/axlsx/drawing/str_val.rb +3 -1
  53. data/lib/axlsx/drawing/title.rb +22 -4
  54. data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
  55. data/lib/axlsx/drawing/val_axis.rb +1 -1
  56. data/lib/axlsx/drawing/view_3D.rb +2 -2
  57. data/lib/axlsx/drawing/vml_drawing.rb +1 -1
  58. data/lib/axlsx/package.rb +33 -31
  59. data/lib/axlsx/rels/relationship.rb +1 -1
  60. data/lib/axlsx/rels/relationships.rb +7 -4
  61. data/lib/axlsx/stylesheet/border_pr.rb +2 -2
  62. data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
  63. data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
  64. data/lib/axlsx/stylesheet/cell_style.rb +1 -3
  65. data/lib/axlsx/stylesheet/color.rb +1 -3
  66. data/lib/axlsx/stylesheet/font.rb +1 -1
  67. data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
  68. data/lib/axlsx/stylesheet/num_fmt.rb +10 -3
  69. data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
  70. data/lib/axlsx/stylesheet/styles.rb +7 -7
  71. data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
  72. data/lib/axlsx/util/accessors.rb +6 -6
  73. data/lib/axlsx/util/constants.rb +107 -99
  74. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  75. data/lib/axlsx/util/options_parser.rb +2 -1
  76. data/lib/axlsx/util/parser.rb +4 -4
  77. data/lib/axlsx/util/serialized_attributes.rb +16 -6
  78. data/lib/axlsx/util/simple_typed_list.rb +28 -52
  79. data/lib/axlsx/util/storage.rb +4 -4
  80. data/lib/axlsx/util/validators.rb +29 -17
  81. data/lib/axlsx/version.rb +1 -1
  82. data/lib/axlsx/workbook/defined_name.rb +11 -12
  83. data/lib/axlsx/workbook/defined_names.rb +2 -2
  84. data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
  85. data/lib/axlsx/workbook/workbook.rb +36 -11
  86. data/lib/axlsx/workbook/workbook_view.rb +80 -0
  87. data/lib/axlsx/workbook/workbook_views.rb +22 -0
  88. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
  89. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
  90. data/lib/axlsx/workbook/worksheet/break.rb +1 -3
  91. data/lib/axlsx/workbook/worksheet/cell.rb +136 -74
  92. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +63 -43
  93. data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
  94. data/lib/axlsx/workbook/worksheet/cfvos.rb +4 -1
  95. data/lib/axlsx/workbook/worksheet/col.rb +7 -10
  96. data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
  97. data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
  98. data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
  99. data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
  100. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
  101. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
  102. data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
  103. data/lib/axlsx/workbook/worksheet/data_validation.rb +6 -4
  104. data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
  105. data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
  106. data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
  107. data/lib/axlsx/workbook/worksheet/merged_cells.rb +4 -2
  108. data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
  109. data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
  110. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
  111. data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
  112. data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
  113. data/lib/axlsx/workbook/worksheet/pivot_table.rb +44 -28
  114. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
  115. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
  116. data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
  117. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -2
  118. data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -0
  119. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -0
  120. data/lib/axlsx/workbook/worksheet/row.rb +40 -51
  121. data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
  122. data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
  123. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  124. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
  125. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
  126. data/lib/axlsx/workbook/worksheet/table.rb +6 -6
  127. data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
  128. data/lib/axlsx/workbook/worksheet/tables.rb +4 -1
  129. data/lib/axlsx/workbook/worksheet/worksheet.rb +64 -78
  130. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
  131. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
  132. data/test/drawing/tc_area_chart.rb +39 -0
  133. data/test/drawing/tc_area_series.rb +71 -0
  134. data/test/drawing/tc_axis.rb +27 -0
  135. data/test/drawing/tc_bar_chart.rb +71 -0
  136. data/test/drawing/tc_bubble_chart.rb +44 -0
  137. data/test/drawing/tc_bubble_series.rb +21 -0
  138. data/test/drawing/tc_chart.rb +23 -10
  139. data/test/drawing/tc_data_source.rb +6 -0
  140. data/test/drawing/tc_drawing.rb +2 -2
  141. data/test/drawing/tc_line_chart.rb +5 -5
  142. data/test/drawing/tc_line_series.rb +47 -6
  143. data/test/drawing/tc_pic.rb +11 -15
  144. data/test/drawing/tc_scatter_series.rb +36 -1
  145. data/test/drawing/tc_str_val.rb +9 -0
  146. data/test/drawing/tc_title.rb +5 -0
  147. data/test/stylesheet/tc_styles.rb +2 -2
  148. data/test/tc_axlsx.rb +31 -0
  149. data/test/tc_helper.rb +2 -0
  150. data/test/tc_package.rb +19 -1
  151. data/test/util/tc_mime_type_utils.rb +13 -0
  152. data/test/util/tc_simple_typed_list.rb +2 -3
  153. data/test/util/tc_validators.rb +34 -10
  154. data/test/workbook/tc_defined_name.rb +12 -4
  155. data/test/workbook/tc_shared_strings_table.rb +16 -1
  156. data/test/workbook/tc_workbook.rb +38 -3
  157. data/test/workbook/tc_workbook_view.rb +50 -0
  158. data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
  159. data/test/workbook/worksheet/tc_break.rb +1 -1
  160. data/test/workbook/worksheet/tc_cell.rb +76 -8
  161. data/test/workbook/worksheet/tc_col.rb +2 -2
  162. data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
  163. data/test/workbook/worksheet/tc_data_bar.rb +1 -1
  164. data/test/workbook/worksheet/tc_data_validation.rb +11 -11
  165. data/test/workbook/worksheet/tc_header_footer.rb +2 -2
  166. data/test/workbook/worksheet/tc_icon_set.rb +1 -1
  167. data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
  168. data/test/workbook/worksheet/tc_page_setup.rb +3 -3
  169. data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
  170. data/test/workbook/worksheet/tc_print_options.rb +1 -1
  171. data/test/workbook/worksheet/tc_rich_text.rb +44 -0
  172. data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
  173. data/test/workbook/worksheet/tc_row.rb +7 -2
  174. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
  175. data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
  176. data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
  177. data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
  178. data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
  179. data/test/workbook/worksheet/tc_table.rb +2 -3
  180. data/test/workbook/worksheet/tc_worksheet.rb +99 -45
  181. metadata +89 -16
@@ -49,7 +49,7 @@ module Axlsx
49
49
  # @see d_lbl_pos= for a list of allowed values
50
50
  # @return [Symbol]
51
51
  def d_lbl_pos
52
- return unless @chart_type == Pie3DChart
52
+ return unless [Pie3DChart, LineChart].include? @chart_type
53
53
  @d_lbl_pos ||= :bestFit
54
54
  end
55
55
 
@@ -60,7 +60,7 @@ module Axlsx
60
60
  # The default is :bestFit
61
61
  # @param [Symbol] label_position the postion you want to use.
62
62
  def d_lbl_pos=(label_position)
63
- return unless @chart_type == Pie3DChart
63
+ return unless [Pie3DChart, LineChart].include? @chart_type
64
64
  Axlsx::RestrictionValidator.validate 'DLbls#d_lbl_pos', [:bestFit, :b, :ctr, :inBase, :inEnd, :l, :outEnd, :r, :t], label_position
65
65
  @d_lbl_pos = label_position
66
66
  end
@@ -80,7 +80,7 @@ module Axlsx
80
80
 
81
81
  # nills out d_lbl_pos and show_leader_lines as these attributes, while valid in the spec actually chrash excel for any chart type other than pie charts.
82
82
  def validate_attributes_for_chart_type
83
- return if @chart_type == Pie3DChart
83
+ return if [Pie3DChart, LineChart].include? @chart_type
84
84
  @d_lbl_pos = nil
85
85
  @show_leader_lines = nil
86
86
  end
@@ -8,6 +8,8 @@ module Axlsx
8
8
  require 'axlsx/drawing/bar_series.rb'
9
9
  require 'axlsx/drawing/line_series.rb'
10
10
  require 'axlsx/drawing/scatter_series.rb'
11
+ require 'axlsx/drawing/bubble_series.rb'
12
+ require 'axlsx/drawing/area_series.rb'
11
13
 
12
14
  require 'axlsx/drawing/scaling.rb'
13
15
  require 'axlsx/drawing/axis.rb'
@@ -34,9 +36,12 @@ module Axlsx
34
36
  require 'axlsx/drawing/chart.rb'
35
37
  require 'axlsx/drawing/pie_3D_chart.rb'
36
38
  require 'axlsx/drawing/bar_3D_chart.rb'
39
+ require 'axlsx/drawing/bar_chart.rb'
37
40
  require 'axlsx/drawing/line_chart.rb'
38
41
  require 'axlsx/drawing/line_3D_chart.rb'
39
42
  require 'axlsx/drawing/scatter_chart.rb'
43
+ require 'axlsx/drawing/bubble_chart.rb'
44
+ require 'axlsx/drawing/area_chart.rb'
40
45
 
41
46
  require 'axlsx/drawing/picture_locking.rb'
42
47
  require 'axlsx/drawing/pic.rb'
@@ -153,7 +158,7 @@ module Axlsx
153
158
  # @return [String]
154
159
  def to_xml_string(str = '')
155
160
  str << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
156
- str << '<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '">'
161
+ str << ('<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '">')
157
162
  anchors.each { |anchor| anchor.to_xml_string(str) }
158
163
  str << '</xdr:wsDr>'
159
164
  end
@@ -35,7 +35,7 @@ module Axlsx
35
35
  # macro attribute should be optional!
36
36
  str << '<xdr:graphicFrame>'
37
37
  str << '<xdr:nvGraphicFramePr>'
38
- str << '<xdr:cNvPr id="' << @anchor.drawing.index.to_s << '" name="' << 'item_' << @anchor.drawing.index.to_s << '"/>'
38
+ str << ('<xdr:cNvPr id="' << @anchor.drawing.index.to_s << '" name="' << 'item_' << @anchor.drawing.index.to_s << '"/>')
39
39
  str << '<xdr:cNvGraphicFramePr/>'
40
40
  str << '</xdr:nvGraphicFramePr>'
41
41
  str << '<xdr:xfrm>'
@@ -43,8 +43,8 @@ module Axlsx
43
43
  str << '<a:ext cx="0" cy="0"/>'
44
44
  str << '</xdr:xfrm>'
45
45
  str << '<a:graphic>'
46
- str << '<a:graphicData uri="' << XML_NS_C << '">'
47
- str << '<c:chart xmlns:c="' << XML_NS_C << '" xmlns:r="' << XML_NS_R << '" r:id="' << rId << '"/>'
46
+ str << ('<a:graphicData uri="' << XML_NS_C << '">')
47
+ str << ('<c:chart xmlns:c="' << XML_NS_C << '" xmlns:r="' << XML_NS_R << '" r:id="' << rId << '"/>')
48
48
  str << '</a:graphicData>'
49
49
  str << '</a:graphic>'
50
50
  str << '</xdr:graphicFrame>'
@@ -93,9 +93,7 @@ module Axlsx
93
93
  # @param [String] str
94
94
  # @return [String]
95
95
  def to_xml_string(str = '')
96
- str << '<a:hlinkClick '
97
- serialized_attributes str, {:'r:id' => relationship.Id, :'xmlns:r' => XML_NS_R }
98
- str << '/>'
96
+ serialized_tag 'a:hlinkClick', str, {:'r:id' => relationship.Id, :'xmlns:r' => XML_NS_R }
99
97
  end
100
98
 
101
99
  end
@@ -60,8 +60,8 @@ module Axlsx
60
60
  # @param [String] str
61
61
  # @return [String]
62
62
  def to_xml_string(str = '')
63
- super(str) do |str_inner|
64
- str_inner << '<c:gapDepth val="' << @gap_depth.to_s << '"/>' unless @gap_depth.nil?
63
+ super(str) do
64
+ str << ('<c:gapDepth val="' << @gap_depth.to_s << '"/>') unless @gap_depth.nil?
65
65
  end
66
66
  end
67
67
  end
@@ -76,16 +76,16 @@ module Axlsx
76
76
  # @param [String] str
77
77
  # @return [String]
78
78
  def to_xml_string(str = '')
79
- super(str) do |str_inner|
80
- str_inner << "<c:" << node_name << ">"
81
- str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
82
- str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
83
- @series.each { |ser| ser.to_xml_string(str_inner) }
84
- @d_lbls.to_xml_string(str_inner) if @d_lbls
85
- yield str_inner if block_given?
86
- axes.to_xml_string(str_inner, :ids => true)
87
- str_inner << "</c:" << node_name << ">"
88
- axes.to_xml_string(str_inner)
79
+ super(str) do
80
+ str << ("<c:" << node_name << ">")
81
+ str << ('<c:grouping val="' << grouping.to_s << '"/>')
82
+ str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
83
+ @series.each { |ser| ser.to_xml_string(str) }
84
+ @d_lbls.to_xml_string(str) if @d_lbls
85
+ yield if block_given?
86
+ axes.to_xml_string(str, :ids => true)
87
+ str << ("</c:" << node_name << ">")
88
+ axes.to_xml_string(str)
89
89
  end
90
90
  end
91
91
 
@@ -23,12 +23,22 @@ module Axlsx
23
23
  # @return [Boolean]
24
24
  attr_reader :show_marker
25
25
 
26
+ # custom marker symbol
27
+ # @return [String]
28
+ attr_reader :marker_symbol
29
+
30
+ # line smoothing on values
31
+ # @return [Boolean]
32
+ attr_reader :smooth
33
+
26
34
  # Creates a new series
27
35
  # @option options [Array, SimpleTypedList] data
28
36
  # @option options [Array, SimpleTypedList] labels
29
37
  # @param [Chart] chart
30
38
  def initialize(chart, options={})
31
39
  @show_marker = false
40
+ @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default
41
+ @smooth = false
32
42
  @labels, @data = nil, nil
33
43
  super(chart, options)
34
44
  @labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
@@ -46,6 +56,18 @@ module Axlsx
46
56
  @show_marker = v
47
57
  end
48
58
 
59
+ # @see marker_symbol
60
+ def marker_symbol=(v)
61
+ Axlsx::validate_marker_symbol(v)
62
+ @marker_symbol = v
63
+ end
64
+
65
+ # @see smooth
66
+ def smooth=(v)
67
+ Axlsx::validate_boolean(v)
68
+ @smooth = v
69
+ end
70
+
49
71
  # Serializes the object
50
72
  # @param [String] str
51
73
  # @return [String]
@@ -53,19 +75,26 @@ module Axlsx
53
75
  super(str) do
54
76
  if color
55
77
  str << '<c:spPr><a:solidFill>'
56
- str << '<a:srgbClr val="' << color << '"/>'
78
+ str << ('<a:srgbClr val="' << color << '"/>')
57
79
  str << '</a:solidFill>'
58
80
  str << '<a:ln w="28800">'
59
81
  str << '<a:solidFill>'
60
- str << '<a:srgbClr val="' << color << '"/>'
82
+ str << ('<a:srgbClr val="' << color << '"/>')
61
83
  str << '</a:solidFill>'
62
84
  str << '</a:ln>'
63
85
  str << '<a:round/>'
64
86
  str << '</c:spPr>'
65
87
  end
66
- str << '<c:marker><c:symbol val="none"/></c:marker>' unless @show_marker
88
+
89
+ if !@show_marker
90
+ str << '<c:marker><c:symbol val="none"/></c:marker>'
91
+ elsif @marker_symbol != :default
92
+ str << '<c:marker><c:symbol val="' + @marker_symbol.to_s + '"/></c:marker>'
93
+ end
94
+
67
95
  @labels.to_xml_string(str) unless @labels.nil?
68
96
  @data.to_xml_string(str) unless @data.nil?
97
+ str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
69
98
  end
70
99
  end
71
100
 
@@ -58,7 +58,7 @@ module Axlsx
58
58
  # @return [String]
59
59
  def to_xml_string(str = '')
60
60
  [:col, :colOff, :row, :rowOff].each do |k|
61
- str << '<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>'
61
+ str << ('<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>')
62
62
  end
63
63
  end
64
64
  private
@@ -38,13 +38,13 @@ module Axlsx
38
38
 
39
39
  # serialize the object
40
40
  def to_xml_string(str = "")
41
- str << '<c:' << @tag_name.to_s << '>'
42
- str << '<c:formatCode>' << format_code.to_s << '</c:formatCode>'
43
- str << '<c:ptCount val="' << @pt.size.to_s << '"/>'
41
+ str << ('<c:' << @tag_name.to_s << '>')
42
+ str << ('<c:formatCode>' << format_code.to_s << '</c:formatCode>')
43
+ str << ('<c:ptCount val="' << @pt.size.to_s << '"/>')
44
44
  @pt.each_with_index do |num_val, index|
45
45
  num_val.to_xml_string index, str
46
46
  end
47
- str << '</c:' << @tag_name.to_s << '>'
47
+ str << ('</c:' << @tag_name.to_s << '>')
48
48
  end
49
49
 
50
50
  end
@@ -33,7 +33,7 @@ module Axlsx
33
33
  # allowed element tag names
34
34
  # @return [Array]
35
35
  def self.allowed_tag_names
36
- [:yVal, :val]
36
+ [:yVal, :val, :bubbleSize]
37
37
  end
38
38
 
39
39
  # sets the tag name for this data source
@@ -46,16 +46,16 @@ module Axlsx
46
46
  # serialize the object
47
47
  # @param [String] str
48
48
  def to_xml_string(str="")
49
- str << '<c:' << tag_name.to_s << '>'
49
+ str << ('<c:' << tag_name.to_s << '>')
50
50
  if @f
51
- str << '<c:' << @ref_tag_name.to_s << '>'
52
- str << '<c:f>' << @f.to_s << '</c:f>'
51
+ str << ('<c:' << @ref_tag_name.to_s << '>')
52
+ str << ('<c:f>' << @f.to_s << '</c:f>')
53
53
  end
54
54
  @data.to_xml_string str
55
55
  if @f
56
- str << '</c:' << @ref_tag_name.to_s << '>'
56
+ str << ('</c:' << @ref_tag_name.to_s << '>')
57
57
  end
58
- str << '</c:' << tag_name.to_s << '>'
58
+ str << ('</c:' << tag_name.to_s << '>')
59
59
  end
60
60
  end
61
61
  end
@@ -26,7 +26,9 @@ module Axlsx
26
26
  # serialize the object
27
27
  def to_xml_string(idx, str = "")
28
28
  Axlsx::validate_unsigned_int(idx)
29
- str << '<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>'
29
+ if !v.to_s.empty?
30
+ str << ('<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>')
31
+ end
30
32
  end
31
33
  end
32
34
  end
@@ -7,7 +7,7 @@ module Axlsx
7
7
  class OneCellAnchor
8
8
 
9
9
  include Axlsx::OptionsParser
10
-
10
+
11
11
  # Creates a new OneCellAnchor object and an Pic associated with it.
12
12
  # @param [Drawing] drawing
13
13
  # @option options [Array] start_at the col, row to start at
@@ -23,6 +23,7 @@ module Axlsx
23
23
  drawing.anchors << self
24
24
  @from = Marker.new
25
25
  parse_options options
26
+ start_at(*options[:start_at]) if options[:start_at]
26
27
  @object = Pic.new(self, options)
27
28
  end
28
29
 
@@ -77,7 +78,7 @@ module Axlsx
77
78
  str << '<xdr:from>'
78
79
  from.to_xml_string(str)
79
80
  str << '</xdr:from>'
80
- str << '<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>'
81
+ str << ('<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>')
81
82
  @object.to_xml_string(str)
82
83
  str << '<xdr:clientData/>'
83
84
  str << '</xdr:oneCellAnchor>'
@@ -9,12 +9,13 @@ module Axlsx
9
9
 
10
10
  # Creates a new Pic(ture) object
11
11
  # @param [Anchor] anchor the anchor that holds this image
12
- # @option options [String] name
13
- # @option options [String] descr
14
- # @option options [String] image_src
15
- # @option options [Array] start_at
16
- # @option options [Intger] width
17
- # @option options [Intger] height
12
+ # @option options [String] :name
13
+ # @option options [String] :descr
14
+ # @option options [String] :image_src
15
+ # @option options [Array] :start_at
16
+ # @option options [Integer] :width
17
+ # @option options [Integer] :height
18
+ # @option options [Float] :opacity - set the picture opacity, accepts a value between 0.0 and 1.0
18
19
  def initialize(anchor, options={})
19
20
  @anchor = anchor
20
21
  @hyperlink = nil
@@ -23,10 +24,11 @@ module Axlsx
23
24
  start_at(*options[:start_at]) if options[:start_at]
24
25
  yield self if block_given?
25
26
  @picture_locking = PictureLocking.new(options)
27
+ @opacity = (options[:opacity] * 100000).round if options[:opacity]
26
28
  end
27
29
 
28
- # allowed file extenstions
29
- ALLOWED_EXTENSIONS = ['gif', 'jpeg', 'png', 'jpg']
30
+ # allowed mime types
31
+ ALLOWED_MIME_TYPES = %w(image/jpeg image/png image/gif)
30
32
 
31
33
  # The name to use for this picture
32
34
  # @return [String]
@@ -50,24 +52,28 @@ module Axlsx
50
52
 
51
53
  attr_reader :hyperlink
52
54
 
55
+ # Picture opacity
56
+ # @return [Integer]
57
+ attr_reader :opacity
58
+
53
59
  # sets or updates a hyperlink for this image.
54
60
  # @param [String] v The href value for the hyper link
55
61
  # @option options @see Hyperlink#initialize All options available to the Hyperlink class apply - however href will be overridden with the v parameter value.
56
62
  def hyperlink=(v, options={})
57
63
  options[:href] = v
58
- if @hyperlink.is_a?(Hyperlink)
64
+ if hyperlink.is_a?(Hyperlink)
59
65
  options.each do |o|
60
- @hyperlink.send("#{o[0]}=", o[1]) if @hyperlink.respond_to? "#{o[0]}="
66
+ hyperlink.send("#{o[0]}=", o[1]) if hyperlink.respond_to? "#{o[0]}="
61
67
  end
62
68
  else
63
69
  @hyperlink = Hyperlink.new(self, options)
64
70
  end
65
- @hyperlink
71
+ hyperlink
66
72
  end
67
73
 
68
74
  def image_src=(v)
69
75
  Axlsx::validate_string(v)
70
- RestrictionValidator.validate 'Pic.image_src', ALLOWED_EXTENSIONS, File.extname(v.downcase).delete('.')
76
+ RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeTypeUtils.get_mime_type(v)
71
77
  raise ArgumentError, "File does not exist" unless File.exist?(v)
72
78
  @image_src = v
73
79
  end
@@ -78,7 +84,6 @@ module Axlsx
78
84
  # @see descr
79
85
  def descr=(v) Axlsx::validate_string(v); @descr = v; end
80
86
 
81
-
82
87
  # The file name of image_src without any path information
83
88
  # @return [String]
84
89
  def file_name
@@ -110,7 +115,6 @@ module Axlsx
110
115
  end
111
116
 
112
117
  # providing access to the anchor's width attribute
113
- # @param [Integer] v
114
118
  # @see OneCellAnchor.width
115
119
  def width
116
120
  return unless @anchor.is_a?(OneCellAnchor)
@@ -124,7 +128,6 @@ module Axlsx
124
128
  end
125
129
 
126
130
  # providing access to update the anchor's height attribute
127
- # @param [Integer] v
128
131
  # @see OneCellAnchor.width
129
132
  # @note this is a noop if you are using a TwoCellAnchor
130
133
  def height
@@ -165,17 +168,20 @@ module Axlsx
165
168
  def to_xml_string(str = '')
166
169
  str << '<xdr:pic>'
167
170
  str << '<xdr:nvPicPr>'
168
- str << '<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">'
169
- @hyperlink.to_xml_string(str) if @hyperlink.is_a?(Hyperlink)
171
+ str << ('<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">')
172
+ hyperlink.to_xml_string(str) if hyperlink.is_a?(Hyperlink)
170
173
  str << '</xdr:cNvPr><xdr:cNvPicPr>'
171
174
  picture_locking.to_xml_string(str)
172
175
  str << '</xdr:cNvPicPr></xdr:nvPicPr>'
173
176
  str << '<xdr:blipFill>'
174
- str << '<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '"/>'
177
+ str << ('<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '">')
178
+ if opacity
179
+ str << "<a:alphaModFix amt=\"#{opacity}\"/>"
180
+ end
181
+ str << '</a:blip>'
175
182
  str << '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr>'
176
183
  str << '<a:xfrm><a:off x="0" y="0"/><a:ext cx="2336800" cy="2161540"/></a:xfrm>'
177
184
  str << '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>'
178
-
179
185
  end
180
186
 
181
187
  private
@@ -35,9 +35,7 @@ module Axlsx
35
35
  # @param [String] str
36
36
  # @return [String]
37
37
  def to_xml_string(str = '')
38
- str << '<a:picLocks '
39
- serialized_attributes str
40
- str << '/>'
38
+ serialized_tag('a:picLocks', str)
41
39
  end
42
40
 
43
41
  end
@@ -34,13 +34,12 @@ module Axlsx
34
34
  # @param [String] str
35
35
  # @return [String]
36
36
  def to_xml_string(str = '')
37
- super(str) do |str_inner|
38
-
39
- str_inner << '<c:pie3DChart>'
40
- str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
41
- @series.each { |ser| ser.to_xml_string(str_inner) }
37
+ super(str) do
38
+ str << '<c:pie3DChart>'
39
+ str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
40
+ @series.each { |ser| ser.to_xml_string(str) }
42
41
  d_lbls.to_xml_string(str) if @d_lbls
43
- str_inner << '</c:pie3DChart>'
42
+ str << '</c:pie3DChart>'
44
43
  end
45
44
  end
46
45
 
@@ -46,17 +46,17 @@ module Axlsx
46
46
  # @param [String] str
47
47
  # @return [String]
48
48
  def to_xml_string(str = '')
49
- super(str) do |str_inner|
50
- str_inner << '<c:explosion val="' << @explosion << '"/>' unless @explosion.nil?
49
+ super(str) do
50
+ str << '<c:explosion val="' + @explosion + '"/>' unless @explosion.nil?
51
51
  colors.each_with_index do |c, index|
52
52
  str << '<c:dPt>'
53
- str << '<c:idx val="' << index.to_s << '"/>'
53
+ str << ('<c:idx val="' << index.to_s << '"/>')
54
54
  str << '<c:spPr><a:solidFill>'
55
- str << '<a:srgbClr val="' << c << '"/>'
55
+ str << ('<a:srgbClr val="' << c << '"/>')
56
56
  str << '</a:solidFill></c:spPr></c:dPt>'
57
57
  end
58
- @labels.to_xml_string str_inner unless @labels.nil?
59
- @data.to_xml_string str_inner unless @data.nil?
58
+ @labels.to_xml_string str unless @labels.nil?
59
+ @data.to_xml_string str unless @data.nil?
60
60
  end
61
61
  str
62
62
  end