axlsx 1.2.0 → 2.0.0

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 (208) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +3 -2
  3. data/.yardopts_guide +19 -0
  4. data/CHANGELOG.md +64 -1
  5. data/README.md +105 -87
  6. data/Rakefile +0 -5
  7. data/examples/2010_comments.rb +17 -0
  8. data/examples/anchor_swapping.rb +28 -0
  9. data/examples/auto_filter.rb +16 -0
  10. data/examples/basic_charts.rb +4 -0
  11. data/examples/colored_links.rb +59 -0
  12. data/examples/conditional_formatting/example_conditional_formatting.rb +4 -2
  13. data/examples/example.rb +569 -258
  14. data/examples/ios_preview.rb +14 -0
  15. data/examples/page_setup.rb +11 -0
  16. data/examples/pivot_table.rb +39 -0
  17. data/examples/skydrive/real_example.rb +8 -8
  18. data/examples/styles.rb +66 -0
  19. data/examples/underline.rb +13 -0
  20. data/examples/wrap_text.rb +21 -0
  21. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  22. data/lib/axlsx/content_type/content_type.rb +1 -1
  23. data/lib/axlsx/content_type/default.rb +6 -37
  24. data/lib/axlsx/content_type/override.rb +6 -38
  25. data/lib/axlsx/doc_props/app.rb +10 -7
  26. data/lib/axlsx/doc_props/core.rb +6 -1
  27. data/lib/axlsx/drawing/axes.rb +61 -0
  28. data/lib/axlsx/drawing/axis.rb +20 -17
  29. data/lib/axlsx/drawing/bar_3D_chart.rb +31 -22
  30. data/lib/axlsx/drawing/cat_axis.rb +2 -10
  31. data/lib/axlsx/drawing/chart.rb +33 -6
  32. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  33. data/lib/axlsx/drawing/drawing.rb +11 -17
  34. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  35. data/lib/axlsx/drawing/hyperlink.rb +42 -36
  36. data/lib/axlsx/drawing/line_3D_chart.rb +28 -70
  37. data/lib/axlsx/drawing/line_chart.rb +99 -0
  38. data/lib/axlsx/drawing/line_series.rb +20 -2
  39. data/lib/axlsx/drawing/marker.rb +38 -18
  40. data/lib/axlsx/drawing/num_data.rb +6 -6
  41. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  42. data/lib/axlsx/drawing/one_cell_anchor.rb +28 -21
  43. data/lib/axlsx/drawing/pic.rb +43 -45
  44. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  45. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -1
  46. data/lib/axlsx/drawing/scaling.rb +13 -13
  47. data/lib/axlsx/drawing/scatter_chart.rb +32 -21
  48. data/lib/axlsx/drawing/ser_axis.rb +15 -16
  49. data/lib/axlsx/drawing/series.rb +3 -6
  50. data/lib/axlsx/drawing/str_data.rb +3 -3
  51. data/lib/axlsx/drawing/str_val.rb +7 -8
  52. data/lib/axlsx/drawing/two_cell_anchor.rb +7 -27
  53. data/lib/axlsx/drawing/val_axis.rb +14 -13
  54. data/lib/axlsx/drawing/view_3D.rb +52 -38
  55. data/lib/axlsx/drawing/vml_shape.rb +20 -79
  56. data/lib/axlsx/package.rb +58 -28
  57. data/lib/axlsx/rels/relationship.rb +75 -9
  58. data/lib/axlsx/rels/relationships.rb +8 -1
  59. data/lib/axlsx/stylesheet/border.rb +29 -20
  60. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  61. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  62. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  63. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  64. data/lib/axlsx/stylesheet/color.rb +20 -17
  65. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  66. data/lib/axlsx/stylesheet/font.rb +22 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  68. data/lib/axlsx/stylesheet/num_fmt.rb +23 -14
  69. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  70. data/lib/axlsx/stylesheet/styles.rb +37 -22
  71. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  72. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  73. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  74. data/lib/axlsx/stylesheet/xf.rb +28 -26
  75. data/lib/axlsx/util/accessors.rb +64 -0
  76. data/lib/axlsx/util/constants.rb +127 -6
  77. data/lib/axlsx/util/options_parser.rb +15 -0
  78. data/lib/axlsx/util/serialized_attributes.rb +79 -0
  79. data/lib/axlsx/util/simple_typed_list.rb +50 -15
  80. data/lib/axlsx/util/validators.rb +51 -16
  81. data/lib/axlsx/version.rb +2 -2
  82. data/lib/axlsx/workbook/defined_name.rb +14 -59
  83. data/lib/axlsx/workbook/shared_strings_table.rb +13 -4
  84. data/lib/axlsx/workbook/workbook.rb +85 -6
  85. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  86. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
  87. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
  88. data/lib/axlsx/workbook/worksheet/break.rb +37 -0
  89. data/lib/axlsx/workbook/worksheet/cell.rb +109 -107
  90. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +144 -0
  91. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  92. data/lib/axlsx/workbook/worksheet/cfvos.rb +15 -0
  93. data/lib/axlsx/workbook/worksheet/col.rb +43 -29
  94. data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
  95. data/lib/axlsx/workbook/worksheet/color_scale.rb +62 -28
  96. data/lib/axlsx/workbook/worksheet/comment.rb +28 -37
  97. data/lib/axlsx/workbook/worksheet/comments.rb +3 -3
  98. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  99. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +31 -27
  100. data/lib/axlsx/workbook/worksheet/data_bar.rb +75 -41
  101. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  102. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +6 -5
  103. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  104. data/lib/axlsx/workbook/worksheet/header_footer.rb +54 -0
  105. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  106. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  107. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
  108. data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
  109. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  110. data/lib/axlsx/workbook/worksheet/pivot_table.rb +273 -0
  111. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -0
  112. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -0
  113. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  114. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  115. data/lib/axlsx/workbook/worksheet/row.rb +59 -83
  116. data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
  117. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  118. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
  119. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +60 -0
  120. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
  121. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  122. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  123. data/lib/axlsx/workbook/worksheet/table.rb +25 -19
  124. data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
  125. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  126. data/lib/axlsx/workbook/worksheet/worksheet.rb +174 -35
  127. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -5
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +4 -10
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -0
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  131. data/lib/axlsx.rb +55 -5
  132. data/lib/schema/sml.xsd +4 -0
  133. data/test/axlsx.qcachegrind +2226 -0
  134. data/test/benchmark.rb +2 -3
  135. data/test/content_type/tc_default.rb +0 -11
  136. data/test/content_type/tc_override.rb +0 -13
  137. data/test/doc_props/tc_core.rb +7 -0
  138. data/test/drawing/tc_axes.rb +8 -0
  139. data/test/drawing/tc_axis.rb +15 -17
  140. data/test/drawing/tc_bar_3D_chart.rb +6 -0
  141. data/test/drawing/tc_cat_axis.rb +9 -9
  142. data/test/drawing/tc_chart.rb +20 -0
  143. data/test/drawing/tc_d_lbls.rb +14 -4
  144. data/test/drawing/tc_drawing.rb +0 -5
  145. data/test/drawing/tc_graphic_frame.rb +5 -3
  146. data/test/drawing/tc_hyperlink.rb +0 -4
  147. data/test/drawing/tc_line_chart.rb +39 -0
  148. data/test/drawing/tc_line_series.rb +8 -2
  149. data/test/drawing/tc_pic.rb +14 -3
  150. data/test/drawing/tc_ser_axis.rb +13 -12
  151. data/test/drawing/tc_two_cell_anchor.rb +3 -3
  152. data/test/drawing/tc_val_axis.rb +6 -6
  153. data/test/drawing/tc_vml_shape.rb +9 -3
  154. data/test/profile.rb +11 -21
  155. data/test/rels/tc_relationship.rb +32 -9
  156. data/test/rels/tc_relationships.rb +12 -1
  157. data/test/stylesheet/tc_color.rb +6 -0
  158. data/test/stylesheet/tc_styles.rb +15 -2
  159. data/test/tc_axlsx.rb +35 -2
  160. data/test/tc_helper.rb +7 -1
  161. data/test/tc_package.rb +44 -5
  162. data/test/util/tc_serialized_attributes.rb +19 -0
  163. data/test/util/tc_validators.rb +26 -1
  164. data/test/workbook/tc_defined_name.rb +2 -2
  165. data/test/workbook/tc_shared_strings_table.rb +6 -0
  166. data/test/workbook/tc_workbook.rb +38 -1
  167. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  168. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  169. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  170. data/test/workbook/worksheet/tc_break.rb +49 -0
  171. data/test/workbook/worksheet/tc_cell.rb +40 -6
  172. data/test/workbook/worksheet/tc_col.rb +11 -1
  173. data/test/workbook/worksheet/tc_color_scale.rb +31 -2
  174. data/test/workbook/worksheet/tc_comment.rb +21 -6
  175. data/test/workbook/worksheet/tc_comments.rb +2 -2
  176. data/test/workbook/worksheet/tc_conditional_formatting.rb +7 -0
  177. data/test/workbook/worksheet/tc_data_bar.rb +7 -0
  178. data/test/workbook/worksheet/tc_date_time_converter.rb +3 -11
  179. data/test/workbook/worksheet/tc_header_footer.rb +151 -0
  180. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  181. data/test/workbook/worksheet/tc_page_setup.rb +6 -1
  182. data/test/workbook/worksheet/tc_pane.rb +5 -45
  183. data/test/workbook/worksheet/tc_pivot_table.rb +120 -0
  184. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +54 -0
  185. data/test/workbook/worksheet/tc_row.rb +4 -4
  186. data/test/workbook/worksheet/tc_selection.rb +9 -48
  187. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  188. data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -0
  189. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  190. data/test/workbook/worksheet/tc_sheet_view.rb +39 -39
  191. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +8 -3
  192. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  193. data/test/workbook/worksheet/tc_worksheet.rb +131 -16
  194. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -0
  195. metadata +97 -64
  196. data/examples/example.xlsx +0 -0
  197. data/examples/example_streamed.xlsx +0 -0
  198. data/examples/extractive.pdf +0 -0
  199. data/examples/image1.gif +0 -0
  200. data/examples/image1.jpg +0 -0
  201. data/examples/image1.png +0 -0
  202. data/examples/no-use_autowidth.xlsx +0 -0
  203. data/examples/sample.png +0 -0
  204. data/examples/scraping_html.rb +0 -91
  205. data/examples/shared_strings_example.xlsx +0 -0
  206. data/examples/sheet_view.rb +0 -34
  207. data/examples/two_cell_anchor_image.rb +0 -11
  208. data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
@@ -0,0 +1,99 @@
1
+ # encoding: UTF-8
2
+ module Axlsx
3
+
4
+ # The LineChart is a two dimentional line chart (who would have guessed?) that you can add to your worksheet.
5
+ # @example Creating a chart
6
+ # # This example creates a line in a single sheet.
7
+ # require "rubygems" # if that is your preferred way to manage gems!
8
+ # require "axlsx"
9
+ #
10
+ # p = Axlsx::Package.new
11
+ # ws = p.workbook.add_worksheet
12
+ # ws.add_row ["This is a chart with no data in the sheet"]
13
+ #
14
+ # chart = ws.add_chart(Axlsx::LineChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
15
+ # chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]
16
+ #
17
+ # @see Worksheet#add_chart
18
+ # @see Worksheet#add_row
19
+ # @see Chart#add_series
20
+ # @see Series
21
+ # @see Package#serialize
22
+ class LineChart < Chart
23
+
24
+ # the category axis
25
+ # @return [CatAxis]
26
+ def cat_axis
27
+ axes[:cat_axis]
28
+ end
29
+ alias :catAxis :cat_axis
30
+
31
+ # the category axis
32
+ # @return [ValAxis]
33
+ def val_axis
34
+ axes[:val_axis]
35
+ end
36
+ alias :valAxis :val_axis
37
+
38
+ # must be one of [:percentStacked, :clustered, :standard, :stacked]
39
+ # @return [Symbol]
40
+ attr_reader :grouping
41
+
42
+ # Creates a new line chart object
43
+ # @param [GraphicFrame] frame The workbook that owns this chart.
44
+ # @option options [Cell, String] title
45
+ # @option options [Boolean] show_legend
46
+ # @option options [Symbol] grouping
47
+ # @see Chart
48
+ def initialize(frame, options={})
49
+ @vary_colors = false
50
+ @grouping = :standard
51
+ super(frame, options)
52
+ @series_type = LineSeries
53
+ @d_lbls = nil
54
+ end
55
+
56
+ # @see grouping
57
+ def grouping=(v)
58
+ RestrictionValidator.validate "LineChart.grouping", [:percentStacked, :standard, :stacked], v
59
+ @grouping = v
60
+ end
61
+
62
+ # The node name to use in serialization. As LineChart is used as the
63
+ # base class for Liine3DChart we need to be sure to serialize the
64
+ # chart based on the actual class type and not a fixed node name.
65
+ # @return [String]
66
+ def node_name
67
+ path = self.class.to_s
68
+ if i = path.rindex('::')
69
+ path = path[(i+2)..-1]
70
+ end
71
+ path[0] = path[0].chr.downcase
72
+ path
73
+ end
74
+
75
+ # Serializes the object
76
+ # @param [String] str
77
+ # @return [String]
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)
89
+ end
90
+ end
91
+
92
+ # The axes for this chart. LineCharts have a category and value
93
+ # axis.
94
+ # @return [Axes]
95
+ def axes
96
+ @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
97
+ end
98
+ end
99
+ end
@@ -19,11 +19,16 @@ module Axlsx
19
19
  # @return [String]
20
20
  attr_reader :color
21
21
 
22
+ # show markers on values
23
+ # @return [Boolean]
24
+ attr_reader :show_marker
25
+
22
26
  # Creates a new series
23
27
  # @option options [Array, SimpleTypedList] data
24
28
  # @option options [Array, SimpleTypedList] labels
25
29
  # @param [Chart] chart
26
30
  def initialize(chart, options={})
31
+ @show_marker = false
27
32
  @labels, @data = nil, nil
28
33
  super(chart, options)
29
34
  @labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
@@ -35,6 +40,12 @@ module Axlsx
35
40
  @color = v
36
41
  end
37
42
 
43
+ # @see show_marker
44
+ def show_marker=(v)
45
+ Axlsx::validate_boolean(v)
46
+ @show_marker = v
47
+ end
48
+
38
49
  # Serializes the object
39
50
  # @param [String] str
40
51
  # @return [String]
@@ -43,9 +54,16 @@ module Axlsx
43
54
  if color
44
55
  str << '<c:spPr><a:solidFill>'
45
56
  str << '<a:srgbClr val="' << color << '"/>'
46
- str << '</a:solidFill></c:spPr>'
57
+ str << '</a:solidFill>'
58
+ str << '<a:ln w="28800">'
59
+ str << '<a:solidFill>'
60
+ str << '<a:srgbClr val="' << color << '"/>'
61
+ str << '</a:solidFill>'
62
+ str << '</a:ln>'
63
+ str << '<a:round/>'
64
+ str << '</c:spPr>'
47
65
  end
48
-
66
+ str << '<c:marker><c:symbol val="none"/></c:marker>' unless @show_marker
49
67
  @labels.to_xml_string(str) unless @labels.nil?
50
68
  @data.to_xml_string(str) unless @data.nil?
51
69
  end
@@ -5,6 +5,18 @@ module Axlsx
5
5
  # @see Worksheet#add_chart
6
6
  class Marker
7
7
 
8
+ include Axlsx::OptionsParser
9
+
10
+ # Creates a new Marker object
11
+ # @option options [Integer] col
12
+ # @option options [Integer] colOff
13
+ # @option options [Integer] row
14
+ # @option options [Integer] rowOff
15
+ def initialize(options={})
16
+ @col, @colOff, @row, @rowOff = 0, 0, 0, 0
17
+ parse_options options
18
+ end
19
+
8
20
  # The column this marker anchors to
9
21
  # @return [Integer]
10
22
  attr_reader :col
@@ -21,19 +33,7 @@ module Axlsx
21
33
  # @return [Integer]
22
34
  attr_reader :rowOff
23
35
 
24
- # Creates a new Marker object
25
- # @option options [Integer] col
26
- # @option options [Integer] colOff
27
- # @option options [Integer] row
28
- # @option options [Integer] rowOff
29
- def initialize(options={})
30
- @col, @colOff, @row, @rowOff = 0, 0, 0, 0
31
- options.each do |o|
32
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
33
- end
34
- end
35
-
36
- # @see col
36
+ # @see col
37
37
  def col=(v) Axlsx::validate_unsigned_int v; @col = v end
38
38
  # @see colOff
39
39
  def colOff=(v) Axlsx::validate_int v; @colOff = v end
@@ -43,11 +43,14 @@ module Axlsx
43
43
  def rowOff=(v) Axlsx::validate_int v; @rowOff = v end
44
44
 
45
45
  # shortcut to set the column, row position for this marker
46
- # @param col the column for the marker
47
- # @param row the row of the marker
48
- def coord(col, row)
49
- self.col = col
50
- self.row = row
46
+ # @param col the column for the marker, a Cell object or a string reference like "B7"
47
+ # or an Array.
48
+ # @param row the row of the marker. This is ignored if the col parameter is a Cell or
49
+ # String or Array.
50
+ def coord(col, row=0)
51
+ coordinates = parse_coord_args(col, row)
52
+ self.col = coordinates[0]
53
+ self.row = coordinates[1]
51
54
  end
52
55
 
53
56
  # Serializes the object
@@ -58,6 +61,23 @@ module Axlsx
58
61
  str << '<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>'
59
62
  end
60
63
  end
64
+ private
65
+
66
+ # handles multiple inputs for setting the position of a marker
67
+ # @see Chart#start_at
68
+ def parse_coord_args(x, y=0)
69
+ if x.is_a?(String)
70
+ x, y = *Axlsx::name_to_indices(x)
71
+ end
72
+ if x.is_a?(Cell)
73
+ x, y = *x.pos
74
+ end
75
+ if x.is_a?(Array)
76
+ x, y = *x
77
+ end
78
+ [x, y]
79
+ end
80
+
61
81
 
62
82
  end
63
83
 
@@ -4,9 +4,7 @@ module Axlsx
4
4
  #This class specifies data for a particular data point. It is used for both numCache and numLit object
5
5
  class NumData
6
6
 
7
- # A string representing the format code to apply. For more information see see the SpreadsheetML numFmt element's (§18.8.30) formatCode attribute.
8
- # @return [String]
9
- attr_reader :format_code
7
+ include Axlsx::OptionsParser
10
8
 
11
9
  # creates a new NumVal object
12
10
  # @option options [String] formatCode
@@ -15,11 +13,13 @@ module Axlsx
15
13
  def initialize(options={})
16
14
  @format_code = "General"
17
15
  @pt = SimpleTypedList.new NumVal
18
- options.each do |o|
19
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
20
- end
16
+ parse_options options
21
17
  end
22
18
 
19
+ # A string representing the format code to apply. For more information see see the SpreadsheetML numFmt element's (§18.8.30) formatCode attribute.
20
+ # @return [String]
21
+ attr_reader :format_code
22
+
23
23
  # Creates the val objects for this data set. I am not overly confident this is going to play nicely with time and data types.
24
24
  # @param [Array] values An array of cells or values.
25
25
  def data=(values=[])
@@ -3,18 +3,7 @@ module Axlsx
3
3
  # A numeric data source for use by charts.
4
4
  class NumDataSource
5
5
 
6
- # The tag name to use when serializing this data source.
7
- # Only items defined in allowed_tag_names are allowed
8
- # @return [Symbol]
9
- attr_reader :tag_name
10
-
11
- attr_reader :data
12
-
13
- # allowed element tag names
14
- # @return [Array]
15
- def self.allowed_tag_names
16
- [:yVal, :val]
17
- end
6
+ include Axlsx::OptionsParser
18
7
 
19
8
  # creates a new NumDataSource object
20
9
  # @option options [Array] data An array of Cells or Numeric objects
@@ -30,12 +19,24 @@ module Axlsx
30
19
  if options[:data] && options[:data].first.is_a?(Cell)
31
20
  @f = Axlsx::cell_range(options[:data])
32
21
  end
33
- options.each do |o|
34
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
35
- end
22
+ parse_options options
23
+ end
24
+
25
+
26
+ # The tag name to use when serializing this data source.
27
+ # Only items defined in allowed_tag_names are allowed
28
+ # @return [Symbol]
29
+ attr_reader :tag_name
30
+
31
+ attr_reader :data
32
+
33
+ # allowed element tag names
34
+ # @return [Array]
35
+ def self.allowed_tag_names
36
+ [:yVal, :val]
36
37
  end
37
38
 
38
- # sets the tag name for this data source
39
+ # sets the tag name for this data source
39
40
  # @param [Symbol] v One of the allowed_tag_names
40
41
  def tag_name=(v)
41
42
  Axlsx::RestrictionValidator.validate "#{self.class.name}.tag_name", self.class.allowed_tag_names, v
@@ -6,6 +6,26 @@ module Axlsx
6
6
  # @see Worksheet#add_image
7
7
  class OneCellAnchor
8
8
 
9
+ include Axlsx::OptionsParser
10
+
11
+ # Creates a new OneCellAnchor object and an Pic associated with it.
12
+ # @param [Drawing] drawing
13
+ # @option options [Array] start_at the col, row to start at
14
+ # @option options [Integer] width
15
+ # @option options [Integer] height
16
+ # @option options [String] image_src the file location of the image you will render
17
+ # @option options [String] name the name attribute for the rendered image
18
+ # @option options [String] descr the description of the image rendered
19
+ def initialize(drawing, options={})
20
+ @drawing = drawing
21
+ @width = 0
22
+ @height = 0
23
+ drawing.anchors << self
24
+ @from = Marker.new
25
+ parse_options options
26
+ @object = Pic.new(self, options)
27
+ end
28
+
9
29
  # A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively
10
30
  # @return [Marker]
11
31
  attr_reader :from
@@ -28,27 +48,15 @@ module Axlsx
28
48
  # @return [Integer]
29
49
  attr_reader :height
30
50
 
31
-
32
- # Creates a new OneCellAnchor object and an Pic associated with it.
33
- # @param [Drawing] drawing
34
- # @option options [Array] start_at the col, row to start at
35
- # @option options [Integer] width
36
- # @option options [Integer] height
37
- # @option options [String] image_src the file location of the image you will render
38
- # @option options [String] name the name attribute for the rendered image
39
- # @option options [String] descr the description of the image rendered
40
- def initialize(drawing, options={})
41
- @drawing = drawing
42
- @width = 0
43
- @height = 0
44
- drawing.anchors << self
45
- @from = Marker.new
46
- options.each do |o|
47
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
48
- end
49
- @object = Pic.new(self, options)
51
+ # sets the starting position for the anchor.
52
+ # You can provide a String like "A1", an array like [0,0] or a cell object for the x parameter.
53
+ # We just 'figure it out' for you.
54
+ # @param [Array, String, Cell, Integer] x Accepts many inputs for defining the starting position of the cell.
55
+ # @param [Integer] y When x is an integer, this value is used for the row index at which the anchor starts.
56
+ def start_at(x, y=0)
57
+ from.coord x, y
50
58
  end
51
-
59
+ #
52
60
  # @see height
53
61
  def height=(v) Axlsx::validate_unsigned_int(v); @height = v; end
54
62
 
@@ -61,7 +69,6 @@ module Axlsx
61
69
  @drawing.anchors.index(self)
62
70
  end
63
71
 
64
-
65
72
  # Serializes the object
66
73
  # @param [String] str
67
74
  # @return [String]
@@ -5,6 +5,26 @@ module Axlsx
5
5
  # @see Worksheet#add_image
6
6
  class Pic
7
7
 
8
+ include Axlsx::OptionsParser
9
+
10
+ # Creates a new Pic(ture) object
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
18
+ def initialize(anchor, options={})
19
+ @anchor = anchor
20
+ @hyperlink = nil
21
+ @anchor.drawing.worksheet.workbook.images << self
22
+ parse_options options
23
+ start_at(*options[:start_at]) if options[:start_at]
24
+ yield self if block_given?
25
+ @picture_locking = PictureLocking.new(options)
26
+ end
27
+
8
28
  # allowed file extenstions
9
29
  ALLOWED_EXTENSIONS = ['gif', 'jpeg', 'png', 'jpg']
10
30
 
@@ -12,13 +32,12 @@ module Axlsx
12
32
  # @return [String]
13
33
  attr_reader :name
14
34
 
15
-
16
35
  # A description of the picture
17
36
  # @return [String]
18
37
  attr_reader :descr
19
38
 
20
39
  # The path to the image you want to include
21
- # Only local images are supported at this time and only jpg support
40
+ # Only local images are supported at this time.
22
41
  # @return [String]
23
42
  attr_reader :image_src
24
43
 
@@ -29,26 +48,6 @@ module Axlsx
29
48
  # The picture locking attributes for this picture
30
49
  attr_reader :picture_locking
31
50
 
32
- # Creates a new Pic(ture) object
33
- # @param [Anchor] anchor the anchor that holds this image
34
- # @option options [String] name
35
- # @option options [String] descr
36
- # @option options [String] image_src
37
- # @option options [Array] start_at
38
- # @option options [Intger] width
39
- # @option options [Intger] height
40
- def initialize(anchor, options={})
41
- @anchor = anchor
42
- @hyperlink = nil
43
- @anchor.drawing.worksheet.workbook.images << self
44
- options.each do |o|
45
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
46
- end
47
- start_at(*options[:start_at]) if options[:start_at]
48
- yield self if block_given?
49
- @picture_locking = PictureLocking.new(options)
50
- end
51
-
52
51
  attr_reader :hyperlink
53
52
 
54
53
  # sets or updates a hyperlink for this image.
@@ -68,7 +67,7 @@ module Axlsx
68
67
 
69
68
  def image_src=(v)
70
69
  Axlsx::validate_string(v)
71
- RestrictionValidator.validate 'Pic.image_src', ALLOWED_EXTENSIONS, File.extname(v).delete('.')
70
+ RestrictionValidator.validate 'Pic.image_src', ALLOWED_EXTENSIONS, File.extname(v.downcase).delete('.')
72
71
  raise ArgumentError, "File does not exist" unless File.exist?(v)
73
72
  @image_src = v
74
73
  end
@@ -90,7 +89,8 @@ module Axlsx
90
89
  # @return [String]
91
90
  def extname
92
91
  File.extname(image_src).delete('.') unless image_src.nil?
93
- end
92
+ end
93
+
94
94
  # The index of this image in the workbooks images collections
95
95
  # @return [Index]
96
96
  def index
@@ -103,9 +103,10 @@ module Axlsx
103
103
  "#{IMAGE_PN % [(index+1), extname]}"
104
104
  end
105
105
 
106
- # The relational id withing the drawing's relationships
107
- def id
108
- @anchor.drawing.charts.size + @anchor.drawing.images.index(self) + 1
106
+ # The relationship object for this pic.
107
+ # @return [Relationship]
108
+ def relationship
109
+ Relationship.new(self, IMAGE_R, "../#{pn}")
109
110
  end
110
111
 
111
112
  # providing access to the anchor's width attribute
@@ -136,27 +137,25 @@ module Axlsx
136
137
  use_one_cell_anchor unless @anchor.is_a?(OneCellAnchor)
137
138
  @anchor.height = v
138
139
  end
139
-
140
- # This is a short cut method to set the start anchor position
140
+
141
+ # This is a short cut method to set the start anchor position
141
142
  # If you need finer granularity in positioning use
142
143
  # graphic_frame.anchor.from.colOff / rowOff
143
144
  # @param [Integer] x The column
144
145
  # @param [Integer] y The row
145
146
  # @return [Marker]
146
- def start_at(x, y)
147
- @anchor.from.col = x
148
- @anchor.from.row = y
147
+ def start_at(x, y=nil)
148
+ @anchor.start_at x, y
149
149
  @anchor.from
150
150
  end
151
-
151
+
152
152
  # noop if not using a two cell anchor
153
153
  # @param [Integer] x The column
154
154
  # @param [Integer] y The row
155
155
  # @return [Marker]
156
- def end_at(x, y)
156
+ def end_at(x, y=nil)
157
157
  use_two_cell_anchor unless @anchor.is_a?(TwoCellAnchor)
158
- @anchor.to.col = x
159
- @anchor.to.row = y
158
+ @anchor.end_at x, y
160
159
  @anchor.to
161
160
  end
162
161
 
@@ -172,36 +171,35 @@ module Axlsx
172
171
  picture_locking.to_xml_string(str)
173
172
  str << '</xdr:cNvPicPr></xdr:nvPicPr>'
174
173
  str << '<xdr:blipFill>'
175
- str << '<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="rId' << id.to_s << '"/>'
174
+ str << '<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '"/>'
176
175
  str << '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr>'
177
176
  str << '<a:xfrm><a:off x="0" y="0"/><a:ext cx="2336800" cy="2161540"/></a:xfrm>'
178
177
  str << '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>'
179
178
 
180
179
  end
181
-
180
+
182
181
  private
183
182
 
184
183
  # Changes the anchor to a one cell anchor.
185
184
  def use_one_cell_anchor
186
185
  return if @anchor.is_a?(OneCellAnchor)
187
- swap_anchor(OneCellAnchor.new(@anchor.drawing, :from => @anchor.from))
186
+ new_anchor = OneCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row])
187
+ swap_anchor(new_anchor)
188
188
  end
189
-
189
+
190
190
  #changes the anchor type to a two cell anchor
191
191
  def use_two_cell_anchor
192
192
  return if @anchor.is_a?(TwoCellAnchor)
193
- swap_anchor(TwoCellAnchor.new(@anchor.drawing)).tap do |new_anchor|
194
- new_anchor.from.col = @anchor.from.col
195
- new_anchor.from.row = @anchor.from.row
196
- end
193
+ new_anchor = TwoCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row])
194
+ swap_anchor(new_anchor)
197
195
  end
198
196
 
199
197
  # refactoring of swapping code, law of demeter be damned!
200
198
  def swap_anchor(new_anchor)
201
199
  new_anchor.drawing.anchors.delete(new_anchor)
202
200
  @anchor.drawing.anchors[@anchor.drawing.anchors.index(@anchor)] = new_anchor
201
+ new_anchor.instance_variable_set "@object", @anchor.object
203
202
  @anchor = new_anchor
204
203
  end
205
-
206
204
  end
207
205
  end
@@ -3,17 +3,17 @@ module Axlsx
3
3
  # The picture locking class defines the locking properties for pictures in your workbook.
4
4
  class PictureLocking
5
5
 
6
+ include Axlsx::OptionsParser
7
+ include Axlsx::SerializedAttributes
8
+ include Axlsx::Accessors
6
9
 
7
- attr_reader :noGrp
8
- attr_reader :noSelect
9
- attr_reader :noRot
10
- attr_reader :noChangeAspect
11
- attr_reader :noMove
12
- attr_reader :noResize
13
- attr_reader :noEditPoints
14
- attr_reader :noAdjustHandles
15
- attr_reader :noChangeArrowheads
16
- attr_reader :noChangeShapeType
10
+ boolean_attr_accessor :noGrp, :noSelect, :noRot, :noChangeAspect,
11
+ :noMove, :noResize, :noEditPoints, :noAdjustHandles,
12
+ :noChangeArrowheads, :noChangeShapeType
13
+
14
+ serializable_attributes :noGrp, :noSelect, :noRot, :noChangeAspect,
15
+ :noMove, :noResize, :noEditPoints, :noAdjustHandles,
16
+ :noChangeArrowheads, :noChangeShapeType
17
17
 
18
18
  # Creates a new PictureLocking object
19
19
  # @option options [Boolean] noGrp
@@ -28,47 +28,15 @@ module Axlsx
28
28
  # @option options [Boolean] noChangeShapeType
29
29
  def initialize(options={})
30
30
  @noChangeAspect = true
31
- options.each do |o|
32
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
33
- end
31
+ parse_options options
34
32
  end
35
33
 
36
- # @see noGrp
37
- def noGrp=(v) Axlsx::validate_boolean v; @noGrp = v end
38
-
39
- # @see noSelect
40
- def noSelect=(v) Axlsx::validate_boolean v; @noSelect = v end
41
-
42
- # @see noRot
43
- def noRot=(v) Axlsx::validate_boolean v; @noRot = v end
44
-
45
- # @see noChangeAspect
46
- def noChangeAspect=(v) Axlsx::validate_boolean v; @noChangeAspect = v end
47
-
48
- # @see noMove
49
- def noMove=(v) Axlsx::validate_boolean v; @noMove = v end
50
-
51
- # @see noResize
52
- def noResize=(v) Axlsx::validate_boolean v; @noResize = v end
53
-
54
- # @see noEditPoints
55
- def noEditPoints=(v) Axlsx::validate_boolean v; @noEditPoints = v end
56
-
57
- # @see noAdjustHandles
58
- def noAdjustHandles=(v) Axlsx::validate_boolean v; @noAdjustHandles = v end
59
-
60
- # @see noChangeArrowheads
61
- def noChangeArrowheads=(v) Axlsx::validate_boolean v; @noChangeArrowheads = v end
62
-
63
- # @see noChangeShapeType
64
- def noChangeShapeType=(v) Axlsx::validate_boolean v; @noChangeShapeType = v end
65
-
66
34
  # Serializes the object
67
35
  # @param [String] str
68
36
  # @return [String]
69
37
  def to_xml_string(str = '')
70
38
  str << '<a:picLocks '
71
- str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
39
+ serialized_attributes str
72
40
  str << '/>'
73
41
  end
74
42
 
@@ -23,6 +23,7 @@ module Axlsx
23
23
  # @see Chart
24
24
  # @see View3D
25
25
  def initialize(frame, options={})
26
+ @vary_colors = true
26
27
  super(frame, options)
27
28
  @series_type = PieSeries
28
29
  @view_3D = View3D.new({:rot_x =>30, :perspective=>30}.merge(options))
@@ -36,7 +37,7 @@ module Axlsx
36
37
  super(str) do |str_inner|
37
38
 
38
39
  str_inner << '<c:pie3DChart>'
39
- str_inner << '<c:varyColors val="1"/>'
40
+ str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
40
41
  @series.each { |ser| ser.to_xml_string(str_inner) }
41
42
  d_lbls.to_xml_string(str) if @d_lbls
42
43
  str_inner << '</c:pie3DChart>'