write_xlsx 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,65 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Writexlsx
4
+ class Colors
5
+ COLORS = {
6
+ :aqua => 0x0F,
7
+ :cyan => 0x0F,
8
+ :black => 0x08,
9
+ :blue => 0x0C,
10
+ :brown => 0x10,
11
+ :magenta => 0x0E,
12
+ :fuchsia => 0x0E,
13
+ :gray => 0x17,
14
+ :grey => 0x17,
15
+ :green => 0x11,
16
+ :lime => 0x0B,
17
+ :navy => 0x12,
18
+ :orange => 0x35,
19
+ :pink => 0x21,
20
+ :purple => 0x14,
21
+ :red => 0x0A,
22
+ :silver => 0x16,
23
+ :white => 0x09,
24
+ :yellow => 0x0D,
25
+ } # :nodoc:
26
+
27
+ ###############################################################################
28
+ #
29
+ # get_color(colour)
30
+ #
31
+ # Used in conjunction with the set_xxx_color methods to convert a color
32
+ # string into a number. Color range is 0..63 but we will restrict it
33
+ # to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
34
+ #
35
+ def get_color(color = nil) # :nodoc:
36
+ if color.respond_to?(:to_int) && color.respond_to?(:+)
37
+ # the default color if arg is outside range,
38
+ if color < 0 || 63 < color
39
+ 0x7FFF
40
+ # or an index < 8 mapped into the correct range,
41
+ elsif color < 8
42
+ (color + 8).to_i
43
+ # or an integer in the valid range
44
+ else
45
+ color.to_i
46
+ end
47
+ elsif color.respond_to?(:to_sym)
48
+ color = color.downcase.to_sym if color.respond_to?(:to_str)
49
+ # or the color string converted to an integer,
50
+ if COLORS.has_key?(color)
51
+ COLORS[color]
52
+ # or the default color if string is unrecognised,
53
+ else
54
+ 0x7FFF
55
+ end
56
+ else
57
+ 0x7FFF
58
+ end
59
+ end
60
+
61
+ def inspect
62
+ to_s
63
+ end
64
+ end # class Colors
65
+ end
@@ -0,0 +1,71 @@
1
+ # coding: utf-8
2
+ #
3
+ # Why would we ever use Ruby 1.8.7 when we can backport with something
4
+ # as simple as this?
5
+ #
6
+ # copied from prawn.
7
+ # modified by Hideo NAKAMURA
8
+ #
9
+ class String #:nodoc:
10
+ def first_line
11
+ self.each_line { |line| return line }
12
+ end
13
+ unless "".respond_to?(:lines)
14
+ alias_method :lines, :to_a
15
+ end
16
+ unless "".respond_to?(:each_char)
17
+ def each_char #:nodoc:
18
+ # copied from jcode
19
+ if block_given?
20
+ scan(/./m) { |x| yield x }
21
+ else
22
+ scan(/./m)
23
+ end
24
+ end
25
+ end
26
+
27
+ unless "".respond_to?(:bytesize)
28
+ def bytesize # :nodoc:
29
+ self.length
30
+ end
31
+ end
32
+
33
+ unless "".respond_to?(:ord)
34
+ def ord
35
+ self[0]
36
+ end
37
+ end
38
+
39
+ unless "".respond_to?(:ascii_only?)
40
+ def ascii_only?
41
+ !!(self =~ /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]\{\}^` ~\0\n]/)
42
+ end
43
+ end
44
+ end
45
+
46
+ unless File.respond_to?(:binread)
47
+ def File.binread(file) #:nodoc:
48
+ File.open(file,"rb") { |f| f.read }
49
+ end
50
+ end
51
+
52
+ if RUBY_VERSION < "1.9"
53
+
54
+ def ruby_18 #:nodoc:
55
+ yield
56
+ end
57
+
58
+ def ruby_19 #:nodoc:
59
+ false
60
+ end
61
+
62
+ else
63
+
64
+ def ruby_18 #:nodoc:
65
+ false
66
+ end
67
+
68
+ def ruby_19 #:nodoc:
69
+ yield
70
+ end
71
+ end
@@ -0,0 +1,547 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'write_xlsx/package/xml_writer_simple.rb'
3
+
4
+ module Writexlsx
5
+ class Drawing
6
+ attr_writer :embedded
7
+
8
+ def initialize
9
+ @writer = Package::XMLWriterSimple.new
10
+ @drawings = []
11
+ @embedded = false
12
+ @orientation = false
13
+ end
14
+
15
+ def xml_str
16
+ @writer.string
17
+ end
18
+
19
+ def set_xml_writer(filename)
20
+ @writer.set_xml_writer(filename)
21
+ end
22
+
23
+ #
24
+ # Assemble and write the XML file.
25
+ #
26
+ def assemble_xml_file
27
+ @writer.xml_decl
28
+
29
+ # Write the xdr:wsDr element.
30
+ write_drawing_workspace
31
+
32
+ if @embedded
33
+ index = 0
34
+ @drawings.each do |dimensions|
35
+ # Write the xdr:twoCellAnchor element.
36
+ index += 1
37
+
38
+ write_two_cell_anchor(index, *(dimensions.flatten))
39
+ end
40
+ else
41
+ index = 0
42
+
43
+ # Write the xdr:absoluteAnchor element.
44
+ index += 1
45
+ write_absolute_anchor(index)
46
+ end
47
+
48
+ @writer.end_tag('xdr:wsDr')
49
+ @writer.crlf
50
+ @writer.close
51
+ end
52
+
53
+ #
54
+ # Add a chart or image sub object to the drawing.
55
+ #
56
+ def add_drawing_object(*args)
57
+ @drawings << args
58
+ end
59
+
60
+ private
61
+
62
+ #
63
+ # Write the <xdr:wsDr> element.
64
+ #
65
+ def write_drawing_workspace
66
+ schema = 'http://schemas.openxmlformats.org/drawingml/'
67
+ xmlns_xdr = "#{schema}2006/spreadsheetDrawing"
68
+ xmlns_a = "#{schema}2006/main"
69
+
70
+ attributes = [
71
+ 'xmlns:xdr', xmlns_xdr,
72
+ 'xmlns:a', xmlns_a
73
+ ]
74
+
75
+ @writer.start_tag('xdr:wsDr', attributes)
76
+ end
77
+
78
+ #
79
+ # Write the <xdr:twoCellAnchor> element.
80
+ #
81
+ def write_two_cell_anchor(*args)
82
+ index, type, col_from, row_from, col_from_offset, row_from_offset,
83
+ col_to, row_to, col_to_offset, row_to_offset, col_absolute, row_absolute,
84
+ width, height, description = args
85
+
86
+ attributes = []
87
+
88
+ # Add attribute for images.
89
+ attributes << :editAs << 'oneCell' if type == 2
90
+
91
+ @writer.start_tag('xdr:twoCellAnchor', attributes)
92
+
93
+ # Write the xdr:from element.
94
+ write_from(col_from, row_from, col_from_offset, row_from_offset)
95
+
96
+ # Write the xdr:from element.
97
+ write_to(col_to, row_to, col_to_offset, row_to_offset)
98
+
99
+ if type == 1
100
+ # Write the xdr:graphicFrame element for charts.
101
+ write_graphic_frame(index)
102
+ else
103
+ # Write the xdr:pic element.
104
+ write_pic(index, col_absolute, row_absolute, width, height, description)
105
+ end
106
+
107
+ # Write the xdr:clientData element.
108
+ write_client_data
109
+
110
+ @writer.end_tag('xdr:twoCellAnchor')
111
+ end
112
+
113
+ #
114
+ # Write the <xdr:from> element.
115
+ #
116
+ def write_from(col, row, col_offset, row_offset)
117
+ @writer.start_tag('xdr:from')
118
+
119
+ # Write the xdr:col element.
120
+ write_col(col)
121
+
122
+ # Write the xdr:colOff element.
123
+ write_col_off(col_offset)
124
+
125
+ # Write the xdr:row element.
126
+ write_row(row)
127
+
128
+ # Write the xdr:rowOff element.
129
+ write_row_off(row_offset)
130
+
131
+ @writer.end_tag('xdr:from')
132
+ end
133
+
134
+ #
135
+ # Write the <xdr:to> element.
136
+ #
137
+ def write_to(col, row, col_offset, row_offset)
138
+ @writer.start_tag('xdr:to')
139
+
140
+ # Write the xdr:col element.
141
+ write_col(col)
142
+
143
+ # Write the xdr:colOff element.
144
+ write_col_off(col_offset)
145
+
146
+ # Write the xdr:row element.
147
+ write_row(row)
148
+
149
+ # Write the xdr:rowOff element.
150
+ write_row_off(row_offset)
151
+
152
+ @writer.end_tag('xdr:to')
153
+ end
154
+
155
+ #
156
+ # Write the <xdr:col> element.
157
+ #
158
+ def write_col(data)
159
+ @writer.data_element('xdr:col', data)
160
+ end
161
+
162
+ #
163
+ # Write the <xdr:colOff> element.
164
+ #
165
+ def write_col_off(data)
166
+ @writer.data_element('xdr:colOff', data)
167
+ end
168
+
169
+
170
+ #
171
+ # Write the <xdr:row> element.
172
+ #
173
+ def write_row(data)
174
+ @writer.data_element('xdr:row', data)
175
+ end
176
+
177
+
178
+ #
179
+ # Write the <xdr:rowOff> element.
180
+ #
181
+ def write_row_off(data)
182
+ @writer.data_element('xdr:rowOff', data)
183
+ end
184
+
185
+ #
186
+ # Write the <xdr:graphicFrame> element.
187
+ #
188
+ def write_graphic_frame(index)
189
+ macro = ''
190
+
191
+ attributes = ['macro', macro]
192
+
193
+ @writer.start_tag('xdr:graphicFrame', attributes)
194
+
195
+ # Write the xdr:nvGraphicFramePr element.
196
+ write_nv_graphic_frame_pr(index)
197
+
198
+ # Write the xdr:xfrm element.
199
+ write_xfrm
200
+
201
+ # Write the a:graphic element.
202
+ write_atag_graphic(index)
203
+
204
+ @writer.end_tag('xdr:graphicFrame')
205
+ end
206
+
207
+ #
208
+ # Write the <xdr:nvGraphicFramePr> element.
209
+ #
210
+ def write_nv_graphic_frame_pr(index)
211
+ @writer.start_tag('xdr:nvGraphicFramePr')
212
+
213
+ # Write the xdr:cNvPr element.
214
+ write_c_nv_pr( index + 1, "Chart #{index}" )
215
+
216
+ # Write the xdr:cNvGraphicFramePr element.
217
+ write_c_nv_graphic_frame_pr
218
+
219
+ @writer.end_tag('xdr:nvGraphicFramePr')
220
+ end
221
+
222
+ #
223
+ # Write the <xdr:cNvPr> element.
224
+ #
225
+ def write_c_nv_pr(id, name, descr = nil)
226
+ attributes = [
227
+ 'id', id,
228
+ 'name', name
229
+ ]
230
+
231
+ # Add description attribute for images.
232
+ attributes << 'descr' << descr if descr
233
+
234
+ @writer.empty_tag('xdr:cNvPr', attributes)
235
+ end
236
+
237
+
238
+ #
239
+ # Write the <xdr:cNvGraphicFramePr> element.
240
+ #
241
+ def write_c_nv_graphic_frame_pr
242
+ if @embedded
243
+ @writer.empty_tag('xdr:cNvGraphicFramePr')
244
+ else
245
+ @writer.start_tag('xdr:cNvGraphicFramePr')
246
+
247
+ # Write the a:graphicFrameLocks element.
248
+ write_a_graphic_frame_locks
249
+
250
+ @writer.end_tag('xdr:cNvGraphicFramePr')
251
+ end
252
+ end
253
+
254
+ #
255
+ # Write the <a:graphicFrameLocks> element.
256
+ #
257
+ def write_a_graphic_frame_locks
258
+ no_grp = 1
259
+
260
+ attributes = ['noGrp', no_grp ]
261
+
262
+ @writer.empty_tag('a:graphicFrameLocks', attributes)
263
+ end
264
+
265
+ #
266
+ # Write the <xdr:xfrm> element.
267
+ #
268
+ def write_xfrm
269
+ @writer.start_tag('xdr:xfrm')
270
+
271
+ # Write the xfrmOffset element.
272
+ write_xfrm_offset
273
+
274
+ # Write the xfrmOffset element.
275
+ write_xfrm_extension
276
+
277
+ @writer.end_tag('xdr:xfrm')
278
+ end
279
+
280
+ #
281
+ # Write the <a:off> xfrm sub-element.
282
+ #
283
+ def write_xfrm_offset
284
+ x = 0
285
+ y = 0
286
+
287
+ attributes = [
288
+ 'x', x,
289
+ 'y', y
290
+ ]
291
+
292
+ @writer.empty_tag('a:off', attributes)
293
+ end
294
+
295
+ #
296
+ # Write the <a:ext> xfrm sub-element.
297
+ #
298
+ def write_xfrm_extension
299
+ x = 0
300
+ y = 0
301
+
302
+ attributes = [
303
+ 'cx', x,
304
+ 'cy', y
305
+ ]
306
+
307
+ @writer.empty_tag('a:ext', attributes)
308
+ end
309
+
310
+ #
311
+ # Write the <a:graphic> element.
312
+ #
313
+ def write_atag_graphic(index)
314
+ @writer.start_tag('a:graphic')
315
+
316
+ # Write the a:graphicData element.
317
+ write_atag_graphic_data(index)
318
+
319
+ @writer.end_tag('a:graphic')
320
+ end
321
+
322
+ #
323
+ # Write the <a:graphicData> element.
324
+ #
325
+ def write_atag_graphic_data(index)
326
+ uri = 'http://schemas.openxmlformats.org/drawingml/2006/chart'
327
+
328
+ attributes = ['uri', uri]
329
+
330
+ @writer.start_tag('a:graphicData', attributes)
331
+
332
+ # Write the c:chart element.
333
+ write_c_chart("rId#{index}")
334
+
335
+ @writer.end_tag('a:graphicData')
336
+ end
337
+
338
+ #
339
+ # Write the <c:chart> element.
340
+ #
341
+ def write_c_chart(r_id)
342
+ schema = 'http://schemas.openxmlformats.org/'
343
+ xmlns_c = "#{schema}drawingml/2006/chart"
344
+ xmlns_r = "#{schema}officeDocument/2006/relationships"
345
+
346
+
347
+ attributes = [
348
+ 'xmlns:c', xmlns_c,
349
+ 'xmlns:r', xmlns_r,
350
+ 'r:id', r_id
351
+ ]
352
+
353
+ @writer.empty_tag('c:chart', attributes)
354
+ end
355
+
356
+ #
357
+ # Write the <xdr:clientData> element.
358
+ #
359
+ def write_client_data
360
+ @writer.empty_tag('xdr:clientData')
361
+ end
362
+
363
+ #
364
+ # Write the <xdr:pic> element.
365
+ #
366
+ def write_pic(index, col_absolute, row_absolute, width, height, description)
367
+ @writer.start_tag('xdr:pic')
368
+
369
+ # Write the xdr:nvPicPr element.
370
+ write_nv_pic_pr(index, description)
371
+
372
+ # Write the xdr:blipFill element.
373
+ write_blip_fill(index)
374
+
375
+ # Write the xdr:spPr element.
376
+ write_sp_pr(col_absolute, row_absolute, width, height)
377
+
378
+ @writer.end_tag('xdr:pic')
379
+ end
380
+
381
+ #
382
+ # Write the <xdr:nvPicPr> element.
383
+ #
384
+ def write_nv_pic_pr(index, description)
385
+ @writer.start_tag('xdr:nvPicPr')
386
+
387
+ # Write the xdr:cNvPr element.
388
+ write_c_nv_pr( index + 1, "Picture #{index}", description )
389
+
390
+ # Write the xdr:cNvPicPr element.
391
+ write_c_nv_pic_pr
392
+
393
+ @writer.end_tag('xdr:nvPicPr')
394
+ end
395
+
396
+ #
397
+ # Write the <xdr:cNvPicPr> element.
398
+ #
399
+ def write_c_nv_pic_pr
400
+ @writer.start_tag('xdr:cNvPicPr')
401
+
402
+ # Write the a:picLocks element.
403
+ write_a_pic_locks
404
+
405
+ @writer.end_tag('xdr:cNvPicPr')
406
+ end
407
+
408
+ #
409
+ # Write the <a:picLocks> element.
410
+ #
411
+ def write_a_pic_locks
412
+ no_change_aspect = 1
413
+
414
+ attributes = ['noChangeAspect', no_change_aspect]
415
+
416
+ @writer.empty_tag('a:picLocks', attributes)
417
+ end
418
+
419
+ #
420
+ # Write the <xdr:blipFill> element.
421
+ #
422
+ def write_blip_fill(index)
423
+ @writer.start_tag('xdr:blipFill')
424
+
425
+ # Write the a:blip element.
426
+ write_a_blip(index)
427
+
428
+ # Write the a:stretch element.
429
+ write_a_stretch
430
+
431
+ @writer.end_tag('xdr:blipFill')
432
+ end
433
+
434
+ #
435
+ # Write the <a:blip> element.
436
+ #
437
+ def write_a_blip(index)
438
+ schema = 'http://schemas.openxmlformats.org/officeDocument/'
439
+ xmlns_r = "#{schema}2006/relationships"
440
+ r_embed = "rId#{index}"
441
+
442
+ attributes = [
443
+ 'xmlns:r', xmlns_r,
444
+ 'r:embed', r_embed
445
+ ]
446
+
447
+ @writer.empty_tag('a:blip', attributes)
448
+ end
449
+
450
+ #
451
+ # Write the <a:stretch> element.
452
+ #
453
+ def write_a_stretch
454
+ @writer.start_tag('a:stretch')
455
+
456
+ # Write the a:fillRect element.
457
+ write_a_fill_rect
458
+
459
+ @writer.end_tag('a:stretch')
460
+ end
461
+
462
+ #
463
+ # Write the <a:fillRect> element.
464
+ #
465
+ def write_a_fill_rect
466
+ @writer.empty_tag('a:fillRect')
467
+ end
468
+
469
+ #
470
+ # Write the <xdr:spPr> element.
471
+ #
472
+ def write_sp_pr(col_absolute, row_absolute, width, height)
473
+ @writer.start_tag('xdr:spPr')
474
+
475
+ # Write the a:xfrm element.
476
+ write_a_xfrm(col_absolute, row_absolute, width, height)
477
+
478
+ # Write the a:prstGeom element.
479
+ write_a_prst_geom
480
+
481
+ @writer.end_tag('xdr:spPr')
482
+ end
483
+
484
+ #
485
+ # Write the <a:xfrm> element.
486
+ #
487
+ def write_a_xfrm(col_absolute, row_absolute, width, height)
488
+ @writer.start_tag('a:xfrm')
489
+
490
+ # Write the a:off element.
491
+ write_a_off( col_absolute, row_absolute )
492
+
493
+ # Write the a:ext element.
494
+ write_a_ext( width, height )
495
+
496
+ @writer.end_tag('a:xfrm')
497
+ end
498
+
499
+ #
500
+ # Write the <a:off> element.
501
+ #
502
+ def write_a_off(x, y)
503
+ attributes = [
504
+ 'x', x,
505
+ 'y', y
506
+ ]
507
+
508
+ @writer.empty_tag('a:off', attributes)
509
+ end
510
+
511
+
512
+ #
513
+ # Write the <a:ext> element.
514
+ #
515
+ def write_a_ext(cx, cy)
516
+ attributes = [
517
+ 'cx', cx,
518
+ 'cy', cy
519
+ ]
520
+
521
+ @writer.empty_tag('a:ext', attributes)
522
+ end
523
+
524
+ #
525
+ # Write the <a:prstGeom> element.
526
+ #
527
+ def write_a_prst_geom
528
+ prst = 'rect'
529
+
530
+ attributes = ['prst', prst]
531
+
532
+ @writer.start_tag('a:prstGeom', attributes)
533
+
534
+ # Write the a:avLst element.
535
+ write_a_av_lst
536
+
537
+ @writer.end_tag('a:prstGeom')
538
+ end
539
+
540
+ #
541
+ # Write the <a:avLst> element.
542
+ #
543
+ def write_a_av_lst
544
+ @writer.empty_tag('a:avLst')
545
+ end
546
+ end
547
+ end