write_xlsx 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. data/.document +5 -0
  2. data/.gitattributes +1 -0
  3. data/Gemfile +12 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +82 -0
  6. data/Rakefile +78 -0
  7. data/VERSION +1 -0
  8. data/examples/a_simple.rb +45 -0
  9. data/examples/array_formula.rb +33 -0
  10. data/examples/autofilter.rb +235 -0
  11. data/examples/chart_area.rb +59 -0
  12. data/examples/chart_bar.rb +59 -0
  13. data/examples/chart_column.rb +58 -0
  14. data/examples/chart_line.rb +59 -0
  15. data/examples/chart_pie.rb +49 -0
  16. data/examples/chart_scatter.rb +59 -0
  17. data/examples/chart_stock.rb +65 -0
  18. data/examples/colors.rb +130 -0
  19. data/examples/comments1.rb +12 -0
  20. data/examples/comments2.rb +335 -0
  21. data/examples/conditional_format.rb +67 -0
  22. data/examples/data_validate.rb +279 -0
  23. data/examples/defined_name.rb +28 -0
  24. data/examples/demo.rb +104 -0
  25. data/examples/diag_border.rb +26 -0
  26. data/examples/headers.rb +119 -0
  27. data/examples/hide_sheet.rb +30 -0
  28. data/examples/hyperlink1.rb +58 -0
  29. data/examples/indent.rb +28 -0
  30. data/examples/merge1.rb +38 -0
  31. data/examples/merge2.rb +48 -0
  32. data/examples/merge3.rb +43 -0
  33. data/examples/merge4.rb +82 -0
  34. data/examples/merge5.rb +70 -0
  35. data/examples/merge6.rb +48 -0
  36. data/examples/outline.rb +252 -0
  37. data/examples/properties.rb +33 -0
  38. data/examples/protection.rb +34 -0
  39. data/examples/rich_strings.rb +42 -0
  40. data/examples/right_to_left.rb +24 -0
  41. data/examples/tab_colors.rb +26 -0
  42. data/lib/write_xlsx.rb +77 -0
  43. data/lib/write_xlsx/chart.rb +3027 -0
  44. data/lib/write_xlsx/chart/area.rb +52 -0
  45. data/lib/write_xlsx/chart/bar.rb +126 -0
  46. data/lib/write_xlsx/chart/column.rb +132 -0
  47. data/lib/write_xlsx/chart/line.rb +51 -0
  48. data/lib/write_xlsx/chart/pie.rb +210 -0
  49. data/lib/write_xlsx/chart/scatter.rb +252 -0
  50. data/lib/write_xlsx/chart/stock.rb +134 -0
  51. data/lib/write_xlsx/chartsheet.rb +173 -0
  52. data/lib/write_xlsx/colors.rb +65 -0
  53. data/lib/write_xlsx/compatibility.rb +71 -0
  54. data/lib/write_xlsx/drawing.rb +547 -0
  55. data/lib/write_xlsx/format.rb +683 -0
  56. data/lib/write_xlsx/package/app.rb +218 -0
  57. data/lib/write_xlsx/package/comments.rb +221 -0
  58. data/lib/write_xlsx/package/content_types.rb +189 -0
  59. data/lib/write_xlsx/package/core.rb +196 -0
  60. data/lib/write_xlsx/package/packager.rb +510 -0
  61. data/lib/write_xlsx/package/relationships.rb +98 -0
  62. data/lib/write_xlsx/package/shared_strings.rb +96 -0
  63. data/lib/write_xlsx/package/styles.rb +705 -0
  64. data/lib/write_xlsx/package/theme.rb +45 -0
  65. data/lib/write_xlsx/package/vml.rb +386 -0
  66. data/lib/write_xlsx/package/xml_writer_simple.rb +90 -0
  67. data/lib/write_xlsx/utility.rb +113 -0
  68. data/lib/write_xlsx/workbook.rb +1488 -0
  69. data/lib/write_xlsx/worksheet.rb +6578 -0
  70. data/lib/write_xlsx/zip_file_utils.rb +98 -0
  71. data/test/chart/test_add_series.rb +113 -0
  72. data/test/chart/test_process_names.rb +27 -0
  73. data/test/chart/test_write_auto.rb +15 -0
  74. data/test/chart/test_write_ax_id.rb +15 -0
  75. data/test/chart/test_write_ax_pos.rb +15 -0
  76. data/test/chart/test_write_chart_space.rb +15 -0
  77. data/test/chart/test_write_cross_ax.rb +15 -0
  78. data/test/chart/test_write_crosses.rb +15 -0
  79. data/test/chart/test_write_format_code.rb +15 -0
  80. data/test/chart/test_write_idx.rb +15 -0
  81. data/test/chart/test_write_label_align.rb +15 -0
  82. data/test/chart/test_write_label_offset.rb +15 -0
  83. data/test/chart/test_write_lang.rb +15 -0
  84. data/test/chart/test_write_layout.rb +15 -0
  85. data/test/chart/test_write_legend.rb +16 -0
  86. data/test/chart/test_write_legend_pos.rb +15 -0
  87. data/test/chart/test_write_major_gridlines.rb +15 -0
  88. data/test/chart/test_write_marker.rb +17 -0
  89. data/test/chart/test_write_marker_size.rb +15 -0
  90. data/test/chart/test_write_marker_value.rb +16 -0
  91. data/test/chart/test_write_num_cache.rb +16 -0
  92. data/test/chart/test_write_num_fmt.rb +16 -0
  93. data/test/chart/test_write_number_format.rb +15 -0
  94. data/test/chart/test_write_order.rb +15 -0
  95. data/test/chart/test_write_orientation.rb +15 -0
  96. data/test/chart/test_write_page_margins.rb +15 -0
  97. data/test/chart/test_write_page_setup.rb +15 -0
  98. data/test/chart/test_write_plot_vis_only.rb +15 -0
  99. data/test/chart/test_write_pt.rb +16 -0
  100. data/test/chart/test_write_pt_count.rb +16 -0
  101. data/test/chart/test_write_series_formula.rb +16 -0
  102. data/test/chart/test_write_style.rb +41 -0
  103. data/test/chart/test_write_symbol.rb +16 -0
  104. data/test/chart/test_write_tick_lbl_pos.rb +16 -0
  105. data/test/chart/test_write_v.rb +16 -0
  106. data/test/drawing/test_drawing_chart_01.rb +50 -0
  107. data/test/drawing/test_drawing_image_01.rb +59 -0
  108. data/test/helper.rb +90 -0
  109. data/test/package/app/test_app01.rb +44 -0
  110. data/test/package/app/test_app02.rb +46 -0
  111. data/test/package/app/test_app03.rb +53 -0
  112. data/test/package/comments/test_comments01.rb +36 -0
  113. data/test/package/comments/test_write_text_t.rb +44 -0
  114. data/test/package/content_types/test_content_types.rb +35 -0
  115. data/test/package/content_types/test_write_default.rb +13 -0
  116. data/test/package/content_types/test_write_override.rb +13 -0
  117. data/test/package/core/test_core01.rb +28 -0
  118. data/test/package/core/test_core02.rb +42 -0
  119. data/test/package/relationships/test_relationships.rb +28 -0
  120. data/test/package/relationships/test_sheet_rels.rb +22 -0
  121. data/test/package/shared_strings/test_shared_strings01.rb +30 -0
  122. data/test/package/shared_strings/test_shared_strings02.rb +30 -0
  123. data/test/package/shared_strings/test_write_si.rb +13 -0
  124. data/test/package/shared_strings/test_write_sst.rb +15 -0
  125. data/test/package/styles/test_styles_01.rb +69 -0
  126. data/test/package/styles/test_styles_02.rb +104 -0
  127. data/test/package/styles/test_styles_03.rb +90 -0
  128. data/test/package/styles/test_styles_04.rb +216 -0
  129. data/test/package/styles/test_styles_05.rb +150 -0
  130. data/test/package/styles/test_styles_06.rb +104 -0
  131. data/test/package/styles/test_styles_07.rb +104 -0
  132. data/test/package/styles/test_styles_08.rb +109 -0
  133. data/test/package/styles/test_styles_09.rb +95 -0
  134. data/test/package/vml/test_vml_01.rb +42 -0
  135. data/test/package/vml/test_write_anchor.rb +14 -0
  136. data/test/package/vml/test_write_auto_fill.rb +14 -0
  137. data/test/package/vml/test_write_column.rb +14 -0
  138. data/test/package/vml/test_write_div.rb +14 -0
  139. data/test/package/vml/test_write_fill.rb +14 -0
  140. data/test/package/vml/test_write_idmap.rb +14 -0
  141. data/test/package/vml/test_write_move_with_cells.rb +14 -0
  142. data/test/package/vml/test_write_path.rb +22 -0
  143. data/test/package/vml/test_write_row.rb +14 -0
  144. data/test/package/vml/test_write_shadow.rb +14 -0
  145. data/test/package/vml/test_write_shapelayout.rb +14 -0
  146. data/test/package/vml/test_write_shapetype.rb +14 -0
  147. data/test/package/vml/test_write_size_with_cells.rb +14 -0
  148. data/test/package/vml/test_write_stroke.rb +14 -0
  149. data/test/package/vml/test_write_textbox.rb +14 -0
  150. data/test/perl_output/a_simple.xlsx +0 -0
  151. data/test/perl_output/array_formula.xlsx +0 -0
  152. data/test/perl_output/autofilter.xlsx +0 -0
  153. data/test/perl_output/chart_area.xlsx +0 -0
  154. data/test/perl_output/chart_bar.xlsx +0 -0
  155. data/test/perl_output/chart_column.xlsx +0 -0
  156. data/test/perl_output/chart_line.xlsx +0 -0
  157. data/test/perl_output/chart_pie.xlsx +0 -0
  158. data/test/perl_output/chart_scatter.xlsx +0 -0
  159. data/test/perl_output/chart_stock.xlsx +0 -0
  160. data/test/perl_output/comments1.xlsx +0 -0
  161. data/test/perl_output/comments2.xlsx +0 -0
  162. data/test/perl_output/conditional_format.xlsx +0 -0
  163. data/test/perl_output/data_validate.xlsx +0 -0
  164. data/test/perl_output/defined_name.xlsx +0 -0
  165. data/test/perl_output/demo.xlsx +0 -0
  166. data/test/perl_output/diag_border.xlsx +0 -0
  167. data/test/perl_output/fit_to_pages.xlsx +0 -0
  168. data/test/perl_output/headers.xlsx +0 -0
  169. data/test/perl_output/hide_sheet.xlsx +0 -0
  170. data/test/perl_output/hyperlink.xlsx +0 -0
  171. data/test/perl_output/indent.xlsx +0 -0
  172. data/test/perl_output/merge1.xlsx +0 -0
  173. data/test/perl_output/merge2.xlsx +0 -0
  174. data/test/perl_output/merge3.xlsx +0 -0
  175. data/test/perl_output/merge4.xlsx +0 -0
  176. data/test/perl_output/merge5.xlsx +0 -0
  177. data/test/perl_output/merge6.xlsx +0 -0
  178. data/test/perl_output/outline.xlsx +0 -0
  179. data/test/perl_output/print_scale.xlsx +0 -0
  180. data/test/perl_output/properties.xlsx +0 -0
  181. data/test/perl_output/protection.xlsx +0 -0
  182. data/test/perl_output/rich_strings.xlsx +0 -0
  183. data/test/perl_output/right_to_left.xlsx +0 -0
  184. data/test/perl_output/tab_colors.xlsx +0 -0
  185. data/test/test_delete_files.rb +37 -0
  186. data/test/test_example_match.rb +2281 -0
  187. data/test/test_xml_writer_simple.rb +63 -0
  188. data/test/workbook/test_get_chart_range.rb +59 -0
  189. data/test/workbook/test_sort_defined_names.rb +77 -0
  190. data/test/workbook/test_workbook_01.rb +29 -0
  191. data/test/workbook/test_workbook_02.rb +31 -0
  192. data/test/workbook/test_workbook_03.rb +31 -0
  193. data/test/workbook/test_workbook_new.rb +18 -0
  194. data/test/workbook/test_write_defined_name.rb +17 -0
  195. data/test/workbook/test_write_defined_names.rb +41 -0
  196. data/test/worksheet/test_calculate_spans.rb +58 -0
  197. data/test/worksheet/test_convert_date_time_01.rb +439 -0
  198. data/test/worksheet/test_convert_date_time_02.rb +478 -0
  199. data/test/worksheet/test_convert_date_time_03.rb +435 -0
  200. data/test/worksheet/test_extract_filter_tokens.rb +109 -0
  201. data/test/worksheet/test_parse_filter_expression.rb +143 -0
  202. data/test/worksheet/test_position_object.rb +50 -0
  203. data/test/worksheet/test_repeat_formula.rb +55 -0
  204. data/test/worksheet/test_worksheet_01.rb +32 -0
  205. data/test/worksheet/test_worksheet_02.rb +38 -0
  206. data/test/worksheet/test_worksheet_03.rb +44 -0
  207. data/test/worksheet/test_worksheet_04.rb +45 -0
  208. data/test/worksheet/test_write_array_formula_01.rb +99 -0
  209. data/test/worksheet/test_write_autofilter.rb +260 -0
  210. data/test/worksheet/test_write_brk.rb +18 -0
  211. data/test/worksheet/test_write_cell.rb +49 -0
  212. data/test/worksheet/test_write_cell_value.rb +33 -0
  213. data/test/worksheet/test_write_col_breaks.rb +27 -0
  214. data/test/worksheet/test_write_col_info.rb +95 -0
  215. data/test/worksheet/test_write_conditional_formatting.rb +72 -0
  216. data/test/worksheet/test_write_custom_filter.rb +18 -0
  217. data/test/worksheet/test_write_custom_filters.rb +25 -0
  218. data/test/worksheet/test_write_data_validation_01.rb +113 -0
  219. data/test/worksheet/test_write_data_validation_02.rb +528 -0
  220. data/test/worksheet/test_write_dimension.rb +94 -0
  221. data/test/worksheet/test_write_ext.rb +18 -0
  222. data/test/worksheet/test_write_ext_lst.rb +18 -0
  223. data/test/worksheet/test_write_filter.rb +18 -0
  224. data/test/worksheet/test_write_filter_column.rb +18 -0
  225. data/test/worksheet/test_write_filters.rb +32 -0
  226. data/test/worksheet/test_write_header_footer.rb +53 -0
  227. data/test/worksheet/test_write_hyperlink.rb +39 -0
  228. data/test/worksheet/test_write_hyperlinks.rb +27 -0
  229. data/test/worksheet/test_write_legacy_drawing.rb +19 -0
  230. data/test/worksheet/test_write_merge_cell.rb +18 -0
  231. data/test/worksheet/test_write_merge_cells.rb +192 -0
  232. data/test/worksheet/test_write_methods.rb +353 -0
  233. data/test/worksheet/test_write_mx_plv.rb +19 -0
  234. data/test/worksheet/test_write_page_margins.rb +98 -0
  235. data/test/worksheet/test_write_page_set_up_pr.rb +19 -0
  236. data/test/worksheet/test_write_page_setup.rb +54 -0
  237. data/test/worksheet/test_write_pane.rb +123 -0
  238. data/test/worksheet/test_write_phonetic_pr.rb +19 -0
  239. data/test/worksheet/test_write_print_options.rb +77 -0
  240. data/test/worksheet/test_write_row_breaks.rb +27 -0
  241. data/test/worksheet/test_write_row_element.rb +69 -0
  242. data/test/worksheet/test_write_selection.rb +18 -0
  243. data/test/worksheet/test_write_sheet_calc_pr.rb +18 -0
  244. data/test/worksheet/test_write_sheet_data.rb +18 -0
  245. data/test/worksheet/test_write_sheet_format_pr.rb +18 -0
  246. data/test/worksheet/test_write_sheet_pr.rb +36 -0
  247. data/test/worksheet/test_write_sheet_protection.rb +174 -0
  248. data/test/worksheet/test_write_sheet_view.rb +62 -0
  249. data/test/worksheet/test_write_sheet_view1.rb +64 -0
  250. data/test/worksheet/test_write_sheet_view2.rb +56 -0
  251. data/test/worksheet/test_write_sheet_view3.rb +83 -0
  252. data/test/worksheet/test_write_sheet_view4.rb +83 -0
  253. data/test/worksheet/test_write_sheet_view5.rb +74 -0
  254. data/test/worksheet/test_write_sheet_view6.rb +51 -0
  255. data/test/worksheet/test_write_sheet_view7.rb +71 -0
  256. data/test/worksheet/test_write_sheet_view8.rb +51 -0
  257. data/test/worksheet/test_write_sheet_view9.rb +51 -0
  258. data/test/worksheet/test_write_tab_color.rb +23 -0
  259. data/test/worksheet/test_write_worksheet.rb +19 -0
  260. data/write_xlsx.gemspec +308 -0
  261. metadata +363 -0
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+ ###############################################################################
3
+ #
4
+ # Area - A class for writing Excel Area charts.
5
+ #
6
+ # Used in conjunction with Chart.
7
+ #
8
+ # See formatting note in Chart.
9
+ #
10
+ # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
+ # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
12
+ #
13
+
14
+ require 'write_xlsx/package/xml_writer_simple'
15
+ require 'write_xlsx/chart'
16
+ require 'write_xlsx/utility'
17
+
18
+ module Writexlsx
19
+ class Chart
20
+ class Area < self
21
+ include Writexlsx::Utility
22
+
23
+ def initialize
24
+ super(self.class)
25
+ @cross_between = 'midCat'
26
+ end
27
+
28
+ #
29
+ # Override the virtual superclass method with a chart specific method.
30
+ #
31
+ def write_chart_type
32
+ # Write the c:areaChart element.
33
+ write_area_chart
34
+ end
35
+
36
+ #
37
+ # Write the <c:areaChart> element.
38
+ #
39
+ def write_area_chart
40
+ @writer.start_tag('c:areaChart')
41
+
42
+ # Write the c:grouping element.
43
+ write_grouping('standard')
44
+
45
+ # Write the series elements.
46
+ write_series
47
+
48
+ @writer.end_tag('c:areaChart')
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,126 @@
1
+ # -*- coding: utf-8 -*-
2
+ ###############################################################################
3
+ #
4
+ # Bar - A class for writing Excel Bar charts.
5
+ #
6
+ # Used in conjunction with Chart.
7
+ #
8
+ # See formatting note in Chart.
9
+ #
10
+ # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
+ # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
12
+ #
13
+
14
+ require 'write_xlsx/package/xml_writer_simple'
15
+ require 'write_xlsx/utility'
16
+
17
+ module Writexlsx
18
+ class Chart
19
+ class Bar < self
20
+ include Writexlsx::Utility
21
+
22
+ def initialize
23
+ super(self.class)
24
+ @subtype = 'clustered'
25
+ @cat_axis_position = 'l'
26
+ @val_axis_position = 'b'
27
+ @horiz_val_axis = 0
28
+ @horiz_cat_axis = 1
29
+ end
30
+
31
+ #
32
+ # Override the virtual superclass method with a chart specific method.
33
+ #
34
+ def write_chart_type
35
+ # Reverse X and Y axes for Bar charts.
36
+ @x_axis, @y_axis = @y_axis, @x_axis
37
+
38
+ # Write the c:barChart element.
39
+ write_bar_chart
40
+ end
41
+
42
+ #
43
+ # Write the <c:barChart> element.
44
+ #
45
+ def write_bar_chart
46
+ subtype = @subtype
47
+
48
+ subtype = 'percentStacked' if subtype == 'percent_stacked'
49
+
50
+ @writer.start_tag('c:barChart')
51
+
52
+ # Write the c:barDir element.
53
+ write_bar_dir
54
+
55
+ # Write the c:grouping element.
56
+ write_grouping(subtype)
57
+
58
+ # Write the series elements.
59
+ write_series
60
+
61
+ @writer.end_tag('c:barChart')
62
+ end
63
+
64
+
65
+ #
66
+ # Write the <c:barDir> element.
67
+ #
68
+ def write_bar_dir
69
+ val = 'bar'
70
+
71
+ attributes = ['val', val]
72
+
73
+ @writer.empty_tag('c:barDir', attributes)
74
+ end
75
+
76
+ #
77
+ # Over-ridden to add c:overlap.
78
+ #
79
+ # Write the series elements.
80
+ #
81
+ def write_series
82
+ # Write each series with subelements.
83
+ index = 0
84
+ @series.each do |series|
85
+ write_ser(index, series)
86
+ index += 1
87
+ end
88
+
89
+
90
+ # Write the c:marker element.
91
+ write_marker_value
92
+
93
+ # Write the c:overlap element.
94
+ write_overlap if @subtype =~ /stacked/
95
+
96
+ # Generate the axis ids.
97
+ add_axis_id
98
+ add_axis_id
99
+
100
+ # Write the c:axId element.
101
+ write_axis_id(@axis_ids[0])
102
+ write_axis_id(@axis_ids[1])
103
+ end
104
+
105
+
106
+ #
107
+ # Over-ridden to add % format. TODO. This will be refactored back up to the
108
+ # SUPER class later.
109
+ #
110
+ # Write the <c:numFmt> element.
111
+ #
112
+ def write_number_format(format_code = 'General')
113
+ source_linked = 1
114
+
115
+ format_code = '0%' if @subtype == 'percent_stacked'
116
+
117
+ attributes = [
118
+ 'formatCode', format_code,
119
+ 'sourceLinked', source_linked
120
+ ]
121
+
122
+ @writer.empty_tag('c:numFmt', attributes)
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,132 @@
1
+ # -*- coding: utf-8 -*-
2
+ ###############################################################################
3
+ #
4
+ # Column - A class for writing Excel Column charts.
5
+ #
6
+ # Used in conjunction with Chart.
7
+ #
8
+ # See formatting note in Chart.
9
+ #
10
+ # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
+ # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
12
+ #
13
+
14
+ require 'write_xlsx/package/xml_writer_simple'
15
+ require 'write_xlsx/utility'
16
+
17
+ module Writexlsx
18
+ class Chart
19
+ # The Column chart module also supports the following sub-types:
20
+ #
21
+ # stacked
22
+ # percent_stacked
23
+ # These can be specified at creation time via the add_chart() Worksheet
24
+ # method:
25
+ #
26
+ # chart = workbook.add_chart( :type => 'column', :subtype => 'stacked' )
27
+ #
28
+ class Column < self
29
+ include Writexlsx::Utility
30
+
31
+ def initialize
32
+ super(self.class)
33
+ @subtype = 'clustered'
34
+ @horiz_val_axis = 0
35
+ end
36
+
37
+ #
38
+ # Override the virtual superclass method with a chart specific method.
39
+ #
40
+ def write_chart_type
41
+ # Write the c:barChart element.
42
+ write_bar_chart
43
+ end
44
+
45
+
46
+ ##############################################################################
47
+ #
48
+ # _write_bar_chart
49
+ #
50
+ # Write the <c:barChart> element.
51
+ #
52
+ def write_bar_chart
53
+ subtype = @subtype
54
+
55
+ subtype = 'percentStacked' if subtype == 'percent_stacked'
56
+
57
+ @writer.start_tag('c:barChart')
58
+
59
+ # Write the c:barDir element.
60
+ write_bar_dir
61
+
62
+ # Write the c:grouping element.
63
+ write_grouping(subtype)
64
+
65
+ # Write the series elements.
66
+ write_series
67
+
68
+ @writer.end_tag('c:barChart')
69
+ end
70
+
71
+ #
72
+ # Write the <c:barDir> element.
73
+ #
74
+ def write_bar_dir
75
+ val = 'col'
76
+
77
+ attributes = ['val', val]
78
+
79
+ @writer.empty_tag('c:barDir', attributes)
80
+ end
81
+
82
+
83
+ #
84
+ # Over-ridden to add c:overlap.
85
+ #
86
+ # Write the series elements.
87
+ #
88
+ def write_series
89
+ # Write each series with subelements.
90
+ index = 0
91
+ @series.each do |series|
92
+ write_ser(index, series)
93
+ index += 1
94
+ end
95
+
96
+ # Write the c:marker element.
97
+ write_marker_value
98
+
99
+ # Write the c:overlap element.
100
+ write_overlap if @subtype =~ /stacked/
101
+
102
+ # Generate the axis ids.
103
+ add_axis_id
104
+ add_axis_id
105
+
106
+ # Write the c:axId element.
107
+ write_axis_id(@axis_ids[0])
108
+ write_axis_id(@axis_ids[1])
109
+ end
110
+
111
+ #
112
+ # Over-ridden to add % format. TODO. This will be refactored back up to the
113
+ # SUPER class later.
114
+ #
115
+ # Write the <c:numFmt> element.
116
+ #
117
+ def write_number_format(format_code = nil)
118
+ format_code ||= 'General'
119
+ source_linked = 1
120
+
121
+ format_code = '0%' if @subtype == 'percent_stacked'
122
+
123
+ attributes = [
124
+ 'formatCode', format_code,
125
+ 'sourceLinked', source_linked
126
+ ]
127
+
128
+ @writer.empty_tag('c:numFmt', attributes)
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,51 @@
1
+ # -*- coding: utf-8 -*-
2
+ ###############################################################################
3
+ #
4
+ # Line - A class for writing Excel Line charts.
5
+ #
6
+ # Used in conjunction with Chart.
7
+ #
8
+ # See formatting note in Chart.
9
+ #
10
+ # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
+ # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
12
+ #
13
+
14
+ require 'write_xlsx/package/xml_writer_simple'
15
+ require 'write_xlsx/utility'
16
+
17
+ module Writexlsx
18
+ class Chart
19
+ class Line < self
20
+ include Writexlsx::Utility
21
+
22
+ def initialize
23
+ super(self.class)
24
+ @default_marker = {:type => 'none'}
25
+ end
26
+
27
+ #
28
+ # Override the virtual superclass method with a chart specific method.
29
+ #
30
+ def write_chart_type
31
+ # Write the c:barChart element.
32
+ write_line_chart
33
+ end
34
+
35
+ #
36
+ # Write the <c:lineChart> element.
37
+ #
38
+ def write_line_chart
39
+ @writer.start_tag('c:lineChart')
40
+
41
+ # Write the c:grouping element.
42
+ write_grouping('standard')
43
+
44
+ # Write the series elements.
45
+ write_series
46
+
47
+ @writer.end_tag('c:lineChart')
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,210 @@
1
+ # -*- coding: utf-8 -*-
2
+ ###############################################################################
3
+ #
4
+ # Pie - A class for writing Excel Pie charts.
5
+ #
6
+ # Used in conjunction with Chart.
7
+ #
8
+ # See formatting note in Chart.
9
+ #
10
+ # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
+ # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
12
+ #
13
+
14
+ require 'write_xlsx/package/xml_writer_simple'
15
+ require 'write_xlsx/chart'
16
+ require 'write_xlsx/utility'
17
+
18
+ module Writexlsx
19
+ class Chart
20
+ # A Pie chart doesn't have an X or Y axis so the following common chart
21
+ # methods are ignored.
22
+ #
23
+ # chart.set_x_axis
24
+ # chart.set_y_axis
25
+ #
26
+ class Pie < self
27
+ include Writexlsx::Utility
28
+
29
+ def initialize
30
+ super(self.class)
31
+ @vary_data_color = 1
32
+ end
33
+
34
+ #
35
+ # Override the virtual superclass method with a chart specific method.
36
+ #
37
+ def write_chart_type
38
+ # Write the c:areaChart element.
39
+ write_pie_chart
40
+ end
41
+
42
+ #
43
+ # Write the <c:pieChart> element.
44
+ #
45
+ def write_pie_chart
46
+ @writer.start_tag('c:pieChart')
47
+
48
+ # Write the c:varyColors element.
49
+ write_vary_colors
50
+
51
+ # Write the series elements.
52
+ write_series
53
+
54
+ # Write the c:firstSliceAng element.
55
+ write_first_slice_ang
56
+
57
+ @writer.end_tag('c:pieChart')
58
+ end
59
+
60
+ #
61
+ # Over-ridden method to remove the cat_axis() and val_axis() code since
62
+ # Pie charts don't require those axes.
63
+ #
64
+ # Write the <c:plotArea> element.
65
+ #
66
+ def write_plot_area
67
+ @writer.start_tag('c:plotArea')
68
+
69
+ # Write the c:layout element.
70
+ write_layout
71
+
72
+ # Write the subclass chart type element.
73
+ write_chart_type
74
+
75
+ @writer.end_tag('c:plotArea')
76
+ end
77
+
78
+ #
79
+ # Over-ridden method to remove axis_id code since Pie charts don't require
80
+ # val and cat axes.
81
+ #
82
+ # Write the series elements.
83
+ #
84
+ def write_series
85
+ # Write each series with subelements.
86
+ index = 0
87
+ @series.each do |series|
88
+ write_ser(index, series)
89
+ index += 1
90
+ end
91
+ end
92
+
93
+ #
94
+ # Over-ridden method to add <c:txPr> to legend.
95
+ #
96
+ # Write the <c:legend> element.
97
+ #
98
+ def write_legend
99
+ position = @legend_position
100
+ overlay = 0
101
+
102
+ if position =~ /^overlay_/
103
+ positon.sub!(/^overlay_/, '')
104
+ overlay = 1
105
+ end
106
+
107
+ allowed = {
108
+ 'right' => 'r',
109
+ 'left' => 'l',
110
+ 'top' => 't',
111
+ 'bottom' => 'b'
112
+ }
113
+
114
+ return if position == 'none'
115
+ return unless allowed.has_key?(position)
116
+
117
+ position = allowed[position]
118
+
119
+ @writer.start_tag('c:legend')
120
+
121
+ # Write the c:legendPos element.
122
+ write_legend_pos(position)
123
+
124
+ # Write the c:layout element.
125
+ write_layout
126
+
127
+ # Write the c:overlay element.
128
+ write_overlay if overlay != 0
129
+
130
+ # Write the c:txPr element. Over-ridden.
131
+ write_tx_pr_legend
132
+
133
+ @writer.end_tag('c:legend')
134
+ end
135
+
136
+ #
137
+ # Write the <c:txPr> element for legends.
138
+ #
139
+ def write_tx_pr_legend
140
+ horiz = 0
141
+
142
+ @writer.start_tag('c:txPr')
143
+
144
+ # Write the a:bodyPr element.
145
+ write_a_body_pr(horiz)
146
+
147
+ # Write the a:lstStyle element.
148
+ write_a_lst_style
149
+
150
+ # Write the a:p element.
151
+ write_a_p_legend
152
+
153
+ @writer.end_tag('c:txPr')
154
+ end
155
+
156
+ #
157
+ # Write the <a:p> element for legends.
158
+ #
159
+ def write_a_p_legend
160
+ @writer.start_tag('a:p')
161
+
162
+ # Write the a:pPr element.
163
+ write_a_p_pr_legend
164
+
165
+ # Write the a:endParaRPr element.
166
+ write_a_end_para_rpr
167
+
168
+ @writer.end_tag('a:p')
169
+ end
170
+
171
+ #
172
+ # Write the <a:pPr> element for legends.
173
+ #
174
+ def write_a_p_pr_legend
175
+ rtl = 0
176
+
177
+ attributes = ['rtl', rtl]
178
+
179
+ @writer.start_tag('a:pPr', attributes)
180
+
181
+ # Write the a:defRPr element.
182
+ write_a_def_rpr
183
+
184
+ @writer.end_tag('a:pPr')
185
+ end
186
+
187
+ #
188
+ # Write the <c:varyColors> element.
189
+ #
190
+ def write_vary_colors
191
+ val = 1
192
+
193
+ attributes = ['val', val]
194
+
195
+ @writer.empty_tag('c:varyColors', attributes)
196
+ end
197
+
198
+ #
199
+ # Write the <c:firstSliceAng> element.
200
+ #
201
+ def write_first_slice_ang
202
+ val = 0
203
+
204
+ attributes = ['val', val]
205
+
206
+ @writer.empty_tag('c:firstSliceAng', attributes)
207
+ end
208
+ end
209
+ end
210
+ end