axlsx 1.1.4 → 1.3.1

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 (242) hide show
  1. data/.yardopts +6 -2
  2. data/CHANGELOG.md +72 -0
  3. data/README.md +114 -31
  4. data/Rakefile +11 -3
  5. data/examples/auto_filter.rb +16 -0
  6. data/examples/auto_filter.xlsx +0 -0
  7. data/examples/basic_charts.rb +58 -0
  8. data/examples/chart_colors.rb +17 -2
  9. data/examples/data_validation.rb +50 -0
  10. data/examples/example.rb +171 -60
  11. data/examples/example.xlsx +0 -0
  12. data/examples/example_streamed.xlsx +0 -0
  13. data/examples/extractive.pdf +0 -0
  14. data/examples/extractive.rb +3 -0
  15. data/examples/extractive.xlsx +0 -0
  16. data/examples/hyperlinks.rb +23 -0
  17. data/examples/hyperlinks.xlsx +0 -0
  18. data/examples/no-use_autowidth.xlsx +0 -0
  19. data/examples/page_setup.rb +11 -0
  20. data/examples/page_setup.xlsx +0 -0
  21. data/examples/scraping_html.rb +91 -0
  22. data/examples/shared_strings_example.xlsx +0 -0
  23. data/examples/sheet_protection.rb +10 -0
  24. data/examples/sheet_view.rb +34 -0
  25. data/examples/skydrive/axlsx.csv +1 -0
  26. data/examples/skydrive/axlsx.xlsx +0 -0
  27. data/examples/skydrive/real_example.rb +8 -8
  28. data/examples/sprk2012/Screen Shot 2012-09-11 at 10.42.06 PM.png +0 -0
  29. data/examples/sprk2012/Screen Shot 2012-09-11 at 11.07.48 PM.png +0 -0
  30. data/examples/sprk2012/Screen Shot 2012-09-11 at 8.31.50 PM.png +0 -0
  31. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.23.27 PM.png +0 -0
  32. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.32.06 PM.png +0 -0
  33. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.33.35 PM.png +0 -0
  34. data/examples/sprk2012/Screen Shot 2012-09-11 at 9.46.44 PM.png +0 -0
  35. data/examples/sprk2012/Screen Shot 2012-09-12 at 5.07.23 PM.png +0 -0
  36. data/examples/sprk2012/basics.rb +11 -0
  37. data/examples/sprk2012/basics.xlsx +0 -0
  38. data/examples/sprk2012/gravatar.jpeg +0 -0
  39. data/examples/sprk2012/hair_club.jpg +0 -0
  40. data/examples/sprk2012/images.rb +9 -0
  41. data/examples/sprk2012/images.xlsx +0 -0
  42. data/examples/sprk2012/line_chart.rb +56 -0
  43. data/examples/sprk2012/line_chart.xlsx +0 -0
  44. data/examples/sprk2012/sprk2012.key +0 -0
  45. data/examples/sprk2012/styles.rb +20 -0
  46. data/examples/sprk2012/styles.xlsx +0 -0
  47. data/examples/styles.rb +62 -0
  48. data/examples/styles.xlsx +0 -0
  49. data/examples/two_cell_anchor_image.rb +11 -0
  50. data/lib/axlsx/content_type/content_type.rb +2 -0
  51. data/lib/axlsx/content_type/default.rb +30 -15
  52. data/lib/axlsx/content_type/override.rb +29 -14
  53. data/lib/axlsx/doc_props/app.rb +161 -104
  54. data/lib/axlsx/doc_props/core.rb +9 -5
  55. data/lib/axlsx/drawing/ax_data_source.rb +7 -6
  56. data/lib/axlsx/drawing/axis.rb +82 -36
  57. data/lib/axlsx/drawing/bar_3D_chart.rb +49 -45
  58. data/lib/axlsx/drawing/bar_series.rb +2 -1
  59. data/lib/axlsx/drawing/cat_axis.rb +43 -39
  60. data/lib/axlsx/drawing/chart.rb +65 -54
  61. data/lib/axlsx/drawing/d_lbls.rb +100 -0
  62. data/lib/axlsx/drawing/drawing.rb +20 -8
  63. data/lib/axlsx/drawing/graphic_frame.rb +2 -1
  64. data/lib/axlsx/drawing/line_3D_chart.rb +3 -10
  65. data/lib/axlsx/drawing/num_data.rb +2 -2
  66. data/lib/axlsx/drawing/num_data_source.rb +4 -1
  67. data/lib/axlsx/drawing/pic.rb +44 -4
  68. data/lib/axlsx/drawing/pie_3D_chart.rb +10 -7
  69. data/lib/axlsx/drawing/scatter_chart.rb +2 -8
  70. data/lib/axlsx/drawing/title.rb +21 -9
  71. data/lib/axlsx/drawing/two_cell_anchor.rb +46 -9
  72. data/lib/axlsx/drawing/view_3D.rb +42 -32
  73. data/lib/axlsx/drawing/vml_drawing.rb +42 -0
  74. data/lib/axlsx/drawing/vml_shape.rb +125 -0
  75. data/lib/axlsx/package.rb +43 -16
  76. data/lib/axlsx/rels/relationship.rb +3 -3
  77. data/lib/axlsx/rels/relationships.rb +1 -11
  78. data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
  79. data/lib/axlsx/stylesheet/styles.rb +11 -2
  80. data/lib/axlsx/stylesheet/table_style.rb +3 -3
  81. data/lib/axlsx/util/constants.rb +131 -2
  82. data/lib/axlsx/util/simple_typed_list.rb +18 -22
  83. data/lib/axlsx/util/validators.rb +100 -9
  84. data/lib/axlsx/version.rb +2 -7
  85. data/lib/axlsx/workbook/defined_name.rb +174 -0
  86. data/lib/axlsx/workbook/defined_names.rb +21 -0
  87. data/lib/axlsx/workbook/workbook.rb +70 -13
  88. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  89. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +102 -0
  90. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +253 -0
  91. data/lib/axlsx/workbook/worksheet/cell.rb +41 -8
  92. data/lib/axlsx/workbook/worksheet/col.rb +15 -0
  93. data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
  94. data/lib/axlsx/workbook/worksheet/comment.rb +101 -0
  95. data/lib/axlsx/workbook/worksheet/comments.rb +85 -0
  96. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
  97. data/lib/axlsx/workbook/worksheet/data_bar.rb +1 -1
  98. data/lib/axlsx/workbook/worksheet/data_validation.rb +245 -0
  99. data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
  100. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -1
  101. data/lib/axlsx/workbook/worksheet/dimension.rb +65 -0
  102. data/lib/axlsx/workbook/worksheet/merged_cells.rb +35 -0
  103. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +47 -0
  104. data/lib/axlsx/workbook/worksheet/page_setup.rb +241 -0
  105. data/lib/axlsx/workbook/worksheet/pane.rb +144 -0
  106. data/lib/axlsx/workbook/worksheet/print_options.rb +63 -0
  107. data/lib/axlsx/workbook/worksheet/protected_range.rb +46 -0
  108. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
  109. data/lib/axlsx/workbook/worksheet/row.rb +36 -20
  110. data/lib/axlsx/workbook/worksheet/selection.rb +111 -0
  111. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +49 -0
  112. data/lib/axlsx/workbook/worksheet/sheet_data.rb +25 -0
  113. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +107 -0
  114. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +224 -0
  115. data/lib/axlsx/workbook/worksheet/sheet_view.rb +379 -0
  116. data/lib/axlsx/workbook/worksheet/table.rb +10 -3
  117. data/lib/axlsx/workbook/worksheet/table_style_info.rb +68 -0
  118. data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
  119. data/lib/axlsx/workbook/worksheet/worksheet.rb +414 -254
  120. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +57 -0
  121. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +64 -0
  122. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +101 -0
  123. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  124. data/lib/axlsx.rb +38 -16
  125. data/test/content_type/tc_content_type.rb +1 -6
  126. data/test/doc_props/tc_app.rb +31 -1
  127. data/test/doc_props/tc_core.rb +3 -1
  128. data/test/drawing/tc_axis.rb +38 -3
  129. data/test/drawing/tc_bar_3D_chart.rb +12 -12
  130. data/test/drawing/tc_bar_series.rb +1 -2
  131. data/test/drawing/tc_cat_axis.rb +3 -3
  132. data/test/drawing/tc_chart.rb +29 -9
  133. data/test/drawing/tc_d_lbls.rb +47 -0
  134. data/test/drawing/tc_drawing.rb +11 -5
  135. data/test/drawing/tc_hyperlink.rb +4 -5
  136. data/test/drawing/tc_line_series.rb +7 -3
  137. data/test/drawing/tc_num_data.rb +5 -1
  138. data/test/drawing/tc_pic.rb +22 -2
  139. data/test/drawing/tc_pie_3D_chart.rb +4 -8
  140. data/test/drawing/tc_pie_series.rb +7 -2
  141. data/test/drawing/tc_scatter_chart.rb +6 -1
  142. data/test/drawing/tc_scatter_series.rb +1 -1
  143. data/test/drawing/tc_series.rb +1 -1
  144. data/test/drawing/tc_title.rb +16 -0
  145. data/test/drawing/tc_two_cell_anchor.rb +1 -2
  146. data/test/drawing/tc_view_3D.rb +18 -18
  147. data/test/drawing/tc_vml_drawing.rb +25 -0
  148. data/test/drawing/tc_vml_shape.rb +100 -0
  149. data/test/rels/tc_relationship.rb +1 -0
  150. data/test/stylesheet/tc_gradient_fill.rb +8 -0
  151. data/test/stylesheet/tc_pattern_fill.rb +7 -1
  152. data/test/stylesheet/tc_styles.rb +16 -4
  153. data/test/stylesheet/tc_table_style.rb +8 -0
  154. data/test/stylesheet/tc_table_style_element.rb +10 -1
  155. data/test/tc_helper.rb +1 -0
  156. data/test/tc_package.rb +94 -17
  157. data/test/util/tc_simple_typed_list.rb +13 -0
  158. data/test/util/tc_validators.rb +101 -8
  159. data/test/workbook/tc_defined_name.rb +41 -0
  160. data/test/workbook/tc_workbook.rb +5 -3
  161. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  162. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  163. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  164. data/test/workbook/worksheet/tc_cell.rb +53 -7
  165. data/test/workbook/worksheet/tc_col.rb +9 -0
  166. data/test/workbook/worksheet/tc_comment.rb +57 -0
  167. data/test/workbook/worksheet/tc_comments.rb +57 -0
  168. data/test/workbook/worksheet/tc_conditional_formatting.rb +44 -0
  169. data/test/workbook/worksheet/tc_data_bar.rb +1 -1
  170. data/test/workbook/worksheet/tc_data_validation.rb +265 -0
  171. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  172. data/test/workbook/worksheet/tc_page_setup.rb +143 -0
  173. data/test/workbook/worksheet/tc_pane.rb +94 -0
  174. data/test/workbook/worksheet/tc_print_options.rb +72 -0
  175. data/test/workbook/worksheet/tc_protected_range.rb +17 -0
  176. data/test/workbook/worksheet/tc_row.rb +32 -14
  177. data/test/workbook/worksheet/tc_selection.rb +94 -0
  178. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  179. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  180. data/test/workbook/worksheet/tc_sheet_protection.rb +117 -0
  181. data/test/workbook/worksheet/tc_sheet_view.rb +214 -0
  182. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +9 -12
  183. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  184. data/test/workbook/worksheet/tc_worksheet.rb +155 -51
  185. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +64 -0
  186. metadata +194 -81
  187. data/examples/#extractive.csv# +0 -0
  188. data/examples/#extractive.rb# +0 -45
  189. data/examples/chart_colors.rb~ +0 -0
  190. data/examples/chart_colors.xlsx +0 -0
  191. data/examples/colored_series_data.xlsx +0 -0
  192. data/examples/conditional_formatting/getting_barred.xlsx +0 -0
  193. data/examples/example.csv +0 -1000
  194. data/examples/extractive.csv +0 -1
  195. data/examples/extractive.csv~ +0 -1
  196. data/examples/extractive.rb~ +0 -3
  197. data/examples/stack.rb +0 -21
  198. data/examples/stack.rb~ +0 -27
  199. data/examples/stack.xlsx +0 -0
  200. data/examples/~$chart_colors.xlsx +0 -0
  201. data/examples/~$extractive.xlsx +0 -0
  202. data/lib/axlsx/drawing/ax_data_source.rb~ +0 -55
  203. data/lib/axlsx/drawing/data_source.rb~ +0 -51
  204. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  205. data/lib/axlsx/drawing/hyperlink.rb~ +0 -64
  206. data/lib/axlsx/drawing/num_data.rb~ +0 -51
  207. data/lib/axlsx/drawing/num_data_source.rb~ +0 -54
  208. data/lib/axlsx/drawing/num_val.rb~ +0 -40
  209. data/lib/axlsx/drawing/picture_locking.rb~ +0 -36
  210. data/lib/axlsx/drawing/ref.rb~ +0 -41
  211. data/lib/axlsx/drawing/str_data.rb~ +0 -58
  212. data/lib/axlsx/drawing/str_val.rb~ +0 -35
  213. data/lib/axlsx/util/cbf.rb +0 -333
  214. data/lib/axlsx/util/cfb.rb~ +0 -201
  215. data/lib/axlsx/util/font_tables.rb~ +0 -0
  216. data/lib/axlsx/util/ms_off_crypto.rb +0 -189
  217. data/lib/axlsx/util/ms_off_crypto.rb~ +0 -3
  218. data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
  219. data/lib/axlsx/util/parser.rb~ +0 -6
  220. data/lib/axlsx/util/storage.rb~ +0 -0
  221. data/lib/axlsx/workbook/shared_strings_table.rb~ +0 -69
  222. data/lib/axlsx/workbook/worksheet/cfvo.rb~ +0 -0
  223. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  224. data/lib/axlsx/workbook/worksheet/color_scale.rb~ +0 -46
  225. data/lib/axlsx/workbook/worksheet/data_bar.rb~ +0 -0
  226. data/lib/axlsx/workbook/worksheet/icon_set.rb~ +0 -95
  227. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  228. data/lib/axlsx/workbook/worksheet/table.rb~ +0 -97
  229. data/lib/schema/dc.xsd~ +0 -118
  230. data/lib/schema/dcterms.xsd~ +0 -331
  231. data/lib/schema/opc-coreProperties.xsd~ +0 -50
  232. data/test/drawing/tc_data_source.rb~ +0 -30
  233. data/test/drawing/tc_num_data.rb~ +0 -35
  234. data/test/drawing/tc_num_val.rb~ +0 -29
  235. data/test/drawing/tc_str_data.rb~ +0 -30
  236. data/test/drawing/tc_str_val.rb~ +0 -26
  237. data/test/workbook/worksheet/table/tc_table.rb~ +0 -72
  238. data/test/workbook/worksheet/tc_cfvo.rb~ +0 -20
  239. data/test/workbook/worksheet/tc_col.rb~ +0 -10
  240. data/test/workbook/worksheet/tc_color_scale.rb~ +0 -0
  241. data/test/workbook/worksheet/tc_data_bar.rb~ +0 -0
  242. data/test/workbook/worksheet/tc_icon_set.rb~ +0 -0
@@ -70,7 +70,8 @@ module Axlsx
70
70
  @serAxis = SerAxis.new(@serAxId, @valAxId)
71
71
  super(frame, options)
72
72
  @series_type = LineSeries
73
- @view3D = View3D.new({:perspective=>30}.merge(options))
73
+ @view_3D = View3D.new({:perspective=>30}.merge(options))
74
+ @d_lbls = nil
74
75
  end
75
76
 
76
77
  # @see grouping
@@ -94,14 +95,7 @@ module Axlsx
94
95
  str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
95
96
  str_inner << '<c:varyColors val="1"/>'
96
97
  @series.each { |ser| ser.to_xml_string(str_inner) }
97
- str_inner << '<c:dLbls>'
98
- str_inner << '<c:showLegendKey val="0"/>'
99
- str_inner << '<c:showVal val="0"/>'
100
- str_inner << '<c:showCatName val="0"/>'
101
- str_inner << '<c:showSerName val="0"/>'
102
- str_inner << '<c:showPercent val="0"/>'
103
- str_inner << '<c:showBubbleSize val="0"/>'
104
- str_inner << '</c:dLbls>'
98
+ @d_lbls.to_xml_string(str) if @d_lbls
105
99
  str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
106
100
  str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
107
101
  str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
@@ -112,6 +106,5 @@ module Axlsx
112
106
  @serAxis.to_xml_string str_inner
113
107
  end
114
108
  end
115
-
116
109
  end
117
110
  end
@@ -25,8 +25,8 @@ module Axlsx
25
25
  def data=(values=[])
26
26
  @tag_name = values.first.is_a?(Cell) ? :numCache : :numLit
27
27
  values.each do |value|
28
- v = value.is_a?(Cell) ? value.value : value
29
- @pt << NumVal.new(:v => v)
28
+ value = value.is_formula? ? 0 : value.value if value.is_a?(Cell)
29
+ @pt << NumVal.new(:v => value)
30
30
  end
31
31
  end
32
32
 
@@ -1,4 +1,5 @@
1
1
  module Axlsx
2
+
2
3
  # A numeric data source for use by charts.
3
4
  class NumDataSource
4
5
 
@@ -35,12 +36,14 @@ module Axlsx
35
36
  end
36
37
 
37
38
  # sets the tag name for this data source
38
- # @param [Symbol] One of the allowed_tag_names
39
+ # @param [Symbol] v One of the allowed_tag_names
39
40
  def tag_name=(v)
40
41
  Axlsx::RestrictionValidator.validate "#{self.class.name}.tag_name", self.class.allowed_tag_names, v
41
42
  @tag_name = v
42
43
  end
43
44
 
45
+ # serialize the object
46
+ # @param [String] str
44
47
  def to_xml_string(str="")
45
48
  str << '<c:' << tag_name.to_s << '>'
46
49
  if @f
@@ -90,8 +90,7 @@ module Axlsx
90
90
  # @return [String]
91
91
  def extname
92
92
  File.extname(image_src).delete('.') unless image_src.nil?
93
- end
94
-
93
+ end
95
94
  # The index of this image in the workbooks images collections
96
95
  # @return [Index]
97
96
  def index
@@ -113,27 +112,32 @@ module Axlsx
113
112
  # @param [Integer] v
114
113
  # @see OneCellAnchor.width
115
114
  def width
115
+ return unless @anchor.is_a?(OneCellAnchor)
116
116
  @anchor.width
117
117
  end
118
118
 
119
119
  # @see width
120
120
  def width=(v)
121
+ use_one_cell_anchor unless @anchor.is_a?(OneCellAnchor)
121
122
  @anchor.width = v
122
123
  end
123
124
 
124
125
  # providing access to update the anchor's height attribute
125
126
  # @param [Integer] v
126
127
  # @see OneCellAnchor.width
128
+ # @note this is a noop if you are using a TwoCellAnchor
127
129
  def height
128
130
  @anchor.height
129
131
  end
130
132
 
131
133
  # @see height
134
+ # @note This is a noop if you are using a TwoCellAnchor
132
135
  def height=(v)
136
+ use_one_cell_anchor unless @anchor.is_a?(OneCellAnchor)
133
137
  @anchor.height = v
134
138
  end
135
-
136
- # This is a short cut method to set the start anchor position
139
+
140
+ # This is a short cut method to set the start anchor position
137
141
  # If you need finer granularity in positioning use
138
142
  # graphic_frame.anchor.from.colOff / rowOff
139
143
  # @param [Integer] x The column
@@ -142,6 +146,18 @@ module Axlsx
142
146
  def start_at(x, y)
143
147
  @anchor.from.col = x
144
148
  @anchor.from.row = y
149
+ @anchor.from
150
+ end
151
+
152
+ # noop if not using a two cell anchor
153
+ # @param [Integer] x The column
154
+ # @param [Integer] y The row
155
+ # @return [Marker]
156
+ def end_at(x, y)
157
+ use_two_cell_anchor unless @anchor.is_a?(TwoCellAnchor)
158
+ @anchor.to.col = x
159
+ @anchor.to.row = y
160
+ @anchor.to
145
161
  end
146
162
 
147
163
  # Serializes the object
@@ -162,6 +178,30 @@ module Axlsx
162
178
  str << '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>'
163
179
 
164
180
  end
181
+
182
+ private
183
+
184
+ # Changes the anchor to a one cell anchor.
185
+ def use_one_cell_anchor
186
+ return if @anchor.is_a?(OneCellAnchor)
187
+ swap_anchor(OneCellAnchor.new(@anchor.drawing, :from => @anchor.from))
188
+ end
189
+
190
+ #changes the anchor type to a two cell anchor
191
+ def use_two_cell_anchor
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
197
+ end
198
+
199
+ # refactoring of swapping code, law of demeter be damned!
200
+ def swap_anchor(new_anchor)
201
+ new_anchor.drawing.anchors.delete(new_anchor)
202
+ @anchor.drawing.anchors[@anchor.drawing.anchors.index(@anchor)] = new_anchor
203
+ @anchor = new_anchor
204
+ end
165
205
 
166
206
  end
167
207
  end
@@ -13,19 +13,20 @@ module Axlsx
13
13
  # @option options [Cell, String] title
14
14
  # @option options [Boolean] show_legend
15
15
  # @option options [Symbol] grouping
16
- # @option options [String] gapDepth
17
- # @option options [Integer] rotX
18
- # @option options [String] hPercent
19
- # @option options [Integer] rotY
20
- # @option options [String] depthPercent
21
- # @option options [Boolean] rAngAx
16
+ # @option options [String] gap_depth
17
+ # @option options [Integer] rot_x
18
+ # @option options [String] h_percent
19
+ # @option options [Integer] rot_y
20
+ # @option options [String] depth_percent
21
+ # @option options [Boolean] r_ang_ax
22
22
  # @option options [Integer] perspective
23
23
  # @see Chart
24
24
  # @see View3D
25
25
  def initialize(frame, options={})
26
26
  super(frame, options)
27
27
  @series_type = PieSeries
28
- @view3D = View3D.new({:rotX=>30, :perspective=>30}.merge(options))
28
+ @view_3D = View3D.new({:rot_x =>30, :perspective=>30}.merge(options))
29
+ @d_lbls = nil
29
30
  end
30
31
 
31
32
  # Serializes the object
@@ -33,9 +34,11 @@ module Axlsx
33
34
  # @return [String]
34
35
  def to_xml_string(str = '')
35
36
  super(str) do |str_inner|
37
+
36
38
  str_inner << '<c:pie3DChart>'
37
39
  str_inner << '<c:varyColors val="1"/>'
38
40
  @series.each { |ser| ser.to_xml_string(str_inner) }
41
+ d_lbls.to_xml_string(str) if @d_lbls
39
42
  str_inner << '</c:pie3DChart>'
40
43
  end
41
44
  end
@@ -29,6 +29,7 @@ module Axlsx
29
29
  @yValAxis = ValAxis.new(@yValAxId, @xValAxId)
30
30
  super(frame, options)
31
31
  @series_type = ScatterSeries
32
+ @d_lbls = nil
32
33
  options.each do |o|
33
34
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
34
35
  end
@@ -49,14 +50,7 @@ module Axlsx
49
50
  str_inner << '<c:scatterStyle val="' << scatterStyle.to_s << '"/>'
50
51
  str_inner << '<c:varyColors val="1"/>'
51
52
  @series.each { |ser| ser.to_xml_string(str_inner) }
52
- str_inner << '<c:dLbls>'
53
- str_inner << '<c:showLegendKey val="0"/>'
54
- str_inner << '<c:showVal val="0"/>'
55
- str_inner << '<c:showCatName val="0"/>'
56
- str_inner << '<c:showSerName val="0"/>'
57
- str_inner << '<c:showPercent val="0"/>'
58
- str_inner << '<c:showBubbleSize val="0"/>'
59
- str_inner << '</c:dLbls>'
53
+ d_lbls.to_xml_string(str) if @d_lbls
60
54
  str_inner << '<c:axId val="' << @xValAxId.to_s << '"/>'
61
55
  str_inner << '<c:axId val="' << @yValAxId.to_s << '"/>'
62
56
  str_inner << '</c:scatterChart>'
@@ -46,15 +46,27 @@ module Axlsx
46
46
  str << '<c:title>'
47
47
  unless @text.empty?
48
48
  str << '<c:tx>'
49
- str << '<c:strRef>'
50
- str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
51
- str << '<c:strCache>'
52
- str << '<c:ptCount val="1"/>'
53
- str << '<c:pt idx="0">'
54
- str << '<c:v>' << @text << '</c:v>'
55
- str << '</c:pt>'
56
- str << '</c:strCache>'
57
- str << '</c:strRef>'
49
+ if @cell.is_a?(Cell)
50
+ str << '<c:strRef>'
51
+ str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
52
+ str << '<c:strCache>'
53
+ str << '<c:ptCount val="1"/>'
54
+ str << '<c:pt idx="0">'
55
+ str << '<c:v>' << @text << '</c:v>'
56
+ str << '</c:pt>'
57
+ str << '</c:strCache>'
58
+ str << '</c:strRef>'
59
+ else
60
+ str << '<c:rich>'
61
+ str << '<a:bodyPr/>'
62
+ str << '<a:lstStyle/>'
63
+ str << '<a:p>'
64
+ str << '<a:r>'
65
+ str << '<a:t>' << @text.to_s << '</a:t>'
66
+ str << '</a:r>'
67
+ str << '</a:p>'
68
+ str << '</c:rich>'
69
+ end
58
70
  str << '</c:tx>'
59
71
  end
60
72
  str << '<c:layout/>'
@@ -25,23 +25,33 @@ module Axlsx
25
25
  # @return [Drawing]
26
26
  attr_reader :drawing
27
27
 
28
-
29
- # Creates a new TwoCellAnchor object and sets up a reference to the from and to markers in the
30
- # graphic_frame's chart. That means that you can do stuff like
31
- # c = worksheet.add_chart Axlsx::Chart
28
+ # Creates a new TwoCellAnchor object
32
29
  # c.start_at 5, 9
33
- # @note the chart_type parameter will be replaced with object in v. 2.0.0
34
30
  # @param [Drawing] drawing
35
- # @param [Class] chart_type This is passed to the graphic frame for instantiation. must be Chart or a subclass of Chart
36
- # @param object The object this anchor holds.
37
- # @option options [Array] start_at the col, row to start at
38
- # @option options [Array] end_at the col, row to end at
31
+ # @option options [Array] :start_at the col, row to start at THIS IS DOCUMENTED BUT NOT IMPLEMENTED HERE!
32
+ # @option options [Array] :end_at the col, row to end at
39
33
  def initialize(drawing, options={})
40
34
  @drawing = drawing
41
35
  drawing.anchors << self
42
36
  @from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
43
37
  end
44
38
 
39
+ # sets the col, row attributes for the from marker.
40
+ # @note The recommended way to set the start position for graphical
41
+ # objects is directly thru the object.
42
+ # @see Chart#start_at
43
+ def start_at(x, y)
44
+ set_marker_coords(x, y, from)
45
+ end
46
+
47
+ # sets the col, row attributes for the to marker
48
+ # @note the recommended way to set the to position for graphical
49
+ # objects is directly thru the object
50
+ # @see Char#end_at
51
+ def end_at(x, y)
52
+ set_marker_coords(x, y, to)
53
+ end
54
+
45
55
  # Creates a graphic frame and chart object associated with this anchor
46
56
  # @return [Chart]
47
57
  def add_chart(chart_type, options)
@@ -49,6 +59,11 @@ module Axlsx
49
59
  @object.chart
50
60
  end
51
61
 
62
+ # Creates an image associated with this anchor.
63
+ def add_pic(options={})
64
+ @object = Pic.new(self, options)
65
+ end
66
+
52
67
  # The index of this anchor in the drawing
53
68
  # @return [Integer]
54
69
  def index
@@ -70,6 +85,28 @@ module Axlsx
70
85
  str << '<xdr:clientData/>'
71
86
  str << '</xdr:twoCellAnchor>'
72
87
  end
88
+ private
89
+
90
+ # parses coordinates and sets up a marker's row/col propery
91
+ def set_marker_coords(x, y, marker)
92
+ marker.col, marker.row = *parse_coord_args(x, y)
93
+ end
94
+
95
+ # handles multiple inputs for setting the position of a marker
96
+ # @see Chart#start_at
97
+ def parse_coord_args(x, y=0)
98
+ if x.is_a?(String)
99
+ x, y = *Axlsx::name_to_indices(x)
100
+ end
101
+ if x.is_a?(Cell)
102
+ x, y = *x.pos
103
+ end
104
+ if x.is_a?(Array)
105
+ x, y = *x
106
+ end
107
+ [x, y]
108
+ end
109
+
73
110
 
74
111
  end
75
112
  end
@@ -12,63 +12,73 @@ module Axlsx
12
12
  # x rotation for the chart
13
13
  # must be between -90 and 90
14
14
  # @return [Integer]
15
- attr_reader :rotX
16
-
17
- # height of chart as % of chart
15
+ attr_reader :rot_x
16
+ alias :rotX :rot_x
17
+
18
+ # height of chart as % of chart width
18
19
  # must be between 5% and 500%
19
20
  # @return [String]
20
- attr_reader :hPercent
21
+ attr_reader :h_percent
22
+ alias :hPercent :h_percent
21
23
 
22
24
  # y rotation for the chart
23
25
  # must be between 0 and 360
24
26
  # @return [Integer]
25
- attr_reader :rotY
26
-
27
+ attr_reader :rot_y
28
+ alias :rotY :rot_y
29
+
27
30
  # depth or chart as % of chart width
28
31
  # must be between 20% and 2000%
29
32
  # @return [String]
30
- attr_reader :depthPercent
33
+ attr_reader :depth_percent
34
+ alias :depthPercent :depth_percent
31
35
 
32
36
  # Chart axis are at right angles
33
37
  # @return [Boolean]
34
- attr_reader :rAngAx
38
+ attr_reader :r_ang_ax
39
+ alias :rAngAx :r_ang_ax
35
40
 
36
41
  # field of view angle
37
42
  # @return [Integer]
38
43
  attr_reader :perspective
39
44
 
40
45
  # Creates a new View3D for charts
41
- # @option options [Integer] rotX
42
- # @option options [String] hPercent
43
- # @option options [Integer] rotY
44
- # @option options [String] depthPercent
45
- # @option options [Boolean] rAngAx
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
46
51
  # @option options [Integer] perspective
47
52
  def initialize(options={})
48
- @rotX, @hPercent, @rotY, @depthPercent, @rAngAx, @perspective = nil, nil, nil, nil, nil, nil
53
+ @rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
49
54
  options.each do |o|
50
55
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
51
56
  end
52
57
  end
53
58
 
54
- # @see rotX
55
- def rotX=(v) DataTypeValidator.validate "#{self.class}.rotX", [Integer, Fixnum], v, lambda {|arg| arg >= -90 && arg <= 90 }; @rotX = v; end
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
61
+ alias :rotX= :rot_x=
56
62
 
57
- # @see hPercent
58
- def hPercent=(v)
59
- RegexValidator.validate "#{self.class}.hPercent", H_PERCENT_REGEX, v
60
- @hPercent = v
63
+ # @see h_percent
64
+ def h_percent=(v)
65
+ RegexValidator.validate "#{self.class}.h_percent", H_PERCENT_REGEX, v
66
+ @h_percent = v
61
67
  end
68
+ alias :hPercent= :h_percent=
62
69
 
63
- # @see rotY
64
- def rotY=(v) DataTypeValidator.validate "#{self.class}.rotY", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 360 }; @rotY = v; end
65
-
66
- # @see depthPercent
67
- def depthPercent=(v) RegexValidator.validate "#{self.class}.depthPercent", DEPTH_PERCENT_REGEX, v; @depthPercent = v; end
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
72
+ alias :rotY= :rot_y=
68
73
 
69
- # @see rAngAx
70
- def rAngAx=(v) Axlsx::validate_boolean(v); @rAngAx = v; end
74
+ # @see depth_percent
75
+ def depth_percent=(v) RegexValidator.validate "#{self.class}.depth_percent", DEPTH_PERCENT_REGEX, v; @depth_percent = v; end
76
+ alias :depthPercent= :depth_percent=
71
77
 
78
+ # @see r_ang_ax
79
+ def r_ang_ax=(v) Axlsx::validate_boolean(v); @r_ang_ax = v; end
80
+ alias :rAngAx= :r_ang_ax=
81
+
72
82
  # @see perspective
73
83
  def perspective=(v) DataTypeValidator.validate "#{self.class}.perspective", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
74
84
 
@@ -78,11 +88,11 @@ module Axlsx
78
88
  # @return [String]
79
89
  def to_xml_string(str = '')
80
90
  str << '<c:view3D>'
81
- str << '<c:rotX val="' << @rotX.to_s << '"/>' unless @rotX.nil?
82
- str << '<c:hPercent val="' << @hPercent.to_s << '"/>' unless @hPercent.nil?
83
- str << '<c:rotY val="' << @rotY.to_s << '"/>' unless @rotY.nil?
84
- str << '<c:depthPercent val="' << @depthPercent.to_s << '"/>' unless @depthPercent.nil?
85
- str << '<c:rAngAx val="' << @rAngAx.to_s << '"/>' unless @rAngAx.nil?
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?
86
96
  str << '<c:perspective val="' << @perspective.to_s << '"/>' unless @perspective.nil?
87
97
  str << '</c:view3D>'
88
98
  end
@@ -0,0 +1,42 @@
1
+ module Axlsx
2
+
3
+ # a vml drawing used for comments in excel.
4
+ class VmlDrawing
5
+
6
+ # creates a new Vml Drawing object.
7
+ # @param [Comments] comments the comments object this drawing is associated with
8
+ def initialize(comments)
9
+ raise ArgumentError, "you must provide a comments object" unless comments.is_a?(Comments)
10
+ @comments = comments
11
+ end
12
+
13
+ # The part name for this vml drawing
14
+ # @return [String]
15
+ def pn
16
+ "#{VML_DRAWING_PN}" % (@comments.worksheet.index + 1)
17
+ end
18
+
19
+ # serialize the vml_drawing to xml.
20
+ # @param [String] str
21
+ # @return [String]
22
+ def to_xml_string(str = '')
23
+ str = <<BAD_PROGRAMMER
24
+ <xml xmlns:v="urn:schemas-microsoft-com:vml"
25
+ xmlns:o="urn:schemas-microsoft-com:office:office"
26
+ xmlns:x="urn:schemas-microsoft-com:office:excel">
27
+ <o:shapelayout v:ext="edit">
28
+ <o:idmap v:ext="edit" data="#{@comments.worksheet.index+1}"/>
29
+ </o:shapelayout>
30
+ <v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202"
31
+ path="m0,0l0,21600,21600,21600,21600,0xe">
32
+ <v:stroke joinstyle="miter"/>
33
+ <v:path gradientshapeok="t" o:connecttype="rect"/>
34
+ </v:shapetype>
35
+ BAD_PROGRAMMER
36
+ @comments.each { |comment| comment.vml_shape.to_xml_string str }
37
+ str << "</xml>"
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,125 @@
1
+ module Axlsx
2
+
3
+ # A VmlShape is used to position and render a comment.
4
+ class VmlShape
5
+
6
+ # The row anchor position for this shape determined by the comment's ref value
7
+ # @return [Integer]
8
+ attr_reader :row
9
+
10
+ # The column anchor position for this shape determined by the comment's ref value
11
+ # @return [Integer]
12
+ attr_reader :column
13
+
14
+ # The left column for this shape
15
+ # @return [Integer]
16
+ attr_reader :left_column
17
+
18
+ # The left offset for this shape
19
+ # @return [Integer]
20
+ attr_reader :left_offset
21
+
22
+ # The top row for this shape
23
+ # @return [Integer]
24
+ attr_reader :top_row
25
+
26
+ # The top offset for this shape
27
+ # @return [Integer]
28
+ attr_reader :top_offset
29
+
30
+ # The right column for this shape
31
+ # @return [Integer]
32
+ attr_reader :right_column
33
+
34
+ # The right offset for this shape
35
+ # @return [Integer]
36
+ attr_reader :right_offset
37
+
38
+ # The botttom row for this shape
39
+ # @return [Integer]
40
+ attr_reader :bottom_row
41
+
42
+ # The bottom offset for this shape
43
+ # @return [Integer]
44
+ attr_reader :bottom_offset
45
+
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
69
+ def column=(v); Axlsx::validate_integerish(v); @column = v.to_i end
70
+
71
+ # @see row
72
+ def row=(v); Axlsx::validate_integerish(v); @row = v.to_i end
73
+ # @see left_column
74
+ def left_column=(v); Axlsx::validate_integerish(v); @left_column = v.to_i end
75
+
76
+ # @see left_offset
77
+ def left_offset=(v); Axlsx::validate_integerish(v); @left_offset = v.to_i end
78
+
79
+ # @see top_row
80
+ def top_row=(v); Axlsx::validate_integerish(v); @top_row = v.to_i end
81
+
82
+ # @see top_offset
83
+ def top_offset=(v); Axlsx::validate_integerish(v); @top_offset = v.to_i end
84
+
85
+ # @see right_column
86
+ def right_column=(v); Axlsx::validate_integerish(v); @right_column = v.to_i end
87
+
88
+ # @see right_offset
89
+ def right_offset=(v); Axlsx::validate_integerish(v); @right_offset = v.to_i end
90
+
91
+ # @see bottom_row
92
+ def bottom_row=(v); Axlsx::validate_integerish(v); @bottom_row = v.to_i end
93
+
94
+ # @see bottom_offset
95
+ def bottom_offset=(v); Axlsx::validate_integerish(v); @bottom_offset = v.to_i end
96
+
97
+ # serialize the shape to a string
98
+ # @param [String] str
99
+ # @return [String]
100
+ def to_xml_string(str ='')
101
+ str << <<SHAME_ON_YOU
102
+
103
+ <v:shape id="#{@id}" type="#_x0000_t202" fillcolor="#ffffa1 [80]" o:insetmode="auto">
104
+ <v:fill color2="#ffffa1 [80]"/>
105
+ <v:shadow on="t" obscured="t"/>
106
+ <v:path o:connecttype="none"/>
107
+ <v:textbox style='mso-fit-text-with-word-wrap:t'>
108
+ <div style='text-align:left'></div>
109
+ </v:textbox>
110
+
111
+ <x:ClientData ObjectType="Note">
112
+ <x:MoveWithCells/>
113
+ <x:SizeWithCells/>
114
+ <x:Anchor>#{left_column}, #{left_offset}, #{top_row}, #{top_offset}, #{right_column}, #{right_offset}, #{bottom_row}, #{bottom_offset}</x:Anchor>
115
+ <x:AutoFill>False</x:AutoFill>
116
+ <x:Row>#{row}</x:Row>
117
+ <x:Column>#{column}</x:Column>
118
+ <x:Visible/>
119
+ </x:ClientData>
120
+ </v:shape>
121
+ SHAME_ON_YOU
122
+
123
+ end
124
+ end
125
+ end