write_xlsx 1.00.0 → 1.01.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Changes +15 -0
  4. data/examples/a_simple.rb +1 -1
  5. data/examples/add_vba_project.rb +1 -1
  6. data/examples/array_formula.rb +1 -1
  7. data/examples/chart_area.rb +5 -2
  8. data/examples/chart_bar.rb +5 -2
  9. data/examples/chart_clustered.rb +1 -1
  10. data/examples/chart_column.rb +5 -2
  11. data/examples/chart_combined.rb +1 -1
  12. data/examples/chart_data_table.rb +9 -3
  13. data/examples/chart_data_tools.rb +25 -7
  14. data/examples/chart_doughnut.rb +17 -5
  15. data/examples/chart_gauge.rb +73 -0
  16. data/examples/chart_line.rb +5 -2
  17. data/examples/chart_pareto.rb +1 -1
  18. data/examples/chart_pie.rb +9 -3
  19. data/examples/chart_radar.rb +13 -4
  20. data/examples/chart_scatter.rb +5 -2
  21. data/examples/chart_secondary_axis.rb +5 -2
  22. data/examples/chart_stock.rb +1 -1
  23. data/examples/chart_styles.rb +1 -1
  24. data/examples/colors.rb +1 -1
  25. data/examples/data_validate.rb +1 -1
  26. data/examples/date_time.rb +1 -1
  27. data/examples/demo.rb +4 -1
  28. data/examples/formats.rb +1 -1
  29. data/examples/headers.rb +1 -1
  30. data/examples/hide_row_col.rb +1 -1
  31. data/examples/hide_sheet.rb +1 -1
  32. data/examples/hyperlink1.rb +1 -1
  33. data/examples/indent.rb +1 -1
  34. data/examples/macros.rb +1 -1
  35. data/examples/merge1.rb +1 -1
  36. data/examples/merge2.rb +1 -1
  37. data/examples/merge3.rb +1 -1
  38. data/examples/merge4.rb +1 -1
  39. data/examples/merge5.rb +1 -1
  40. data/examples/merge6.rb +1 -1
  41. data/examples/outline.rb +1 -1
  42. data/examples/outline_collapsed.rb +1 -1
  43. data/examples/panes.rb +1 -1
  44. data/examples/properties.rb +1 -1
  45. data/examples/regions.rb +1 -1
  46. data/examples/rich_strings.rb +1 -1
  47. data/examples/right_to_left.rb +1 -1
  48. data/examples/shape1.rb +1 -1
  49. data/examples/shape2.rb +1 -1
  50. data/examples/shape3.rb +1 -1
  51. data/examples/shape4.rb +1 -1
  52. data/examples/shape5.rb +1 -1
  53. data/examples/shape6.rb +1 -1
  54. data/examples/shape7.rb +1 -1
  55. data/examples/shape8.rb +1 -1
  56. data/examples/shape_all.rb +1 -1
  57. data/examples/sparklines1.rb +1 -1
  58. data/examples/sparklines2.rb +1 -1
  59. data/examples/stats.rb +1 -1
  60. data/examples/stats_ext.rb +1 -1
  61. data/examples/stocks.rb +1 -1
  62. data/examples/tab_colors.rb +1 -1
  63. data/examples/tables.rb +1 -1
  64. data/lib/write_xlsx/chart.rb +18 -13
  65. data/lib/write_xlsx/chart/area.rb +1 -1
  66. data/lib/write_xlsx/chart/bar.rb +1 -1
  67. data/lib/write_xlsx/chart/column.rb +1 -1
  68. data/lib/write_xlsx/chart/doughnut.rb +1 -1
  69. data/lib/write_xlsx/chart/line.rb +1 -1
  70. data/lib/write_xlsx/chart/pie.rb +21 -8
  71. data/lib/write_xlsx/chart/radar.rb +1 -1
  72. data/lib/write_xlsx/chart/scatter.rb +1 -1
  73. data/lib/write_xlsx/chart/stock.rb +1 -1
  74. data/lib/write_xlsx/chartsheet.rb +5 -5
  75. data/lib/write_xlsx/drawing.rb +28 -8
  76. data/lib/write_xlsx/package/comments.rb +7 -7
  77. data/lib/write_xlsx/shape.rb +4 -3
  78. data/lib/write_xlsx/sheets.rb +11 -1
  79. data/lib/write_xlsx/sparkline.rb +1 -1
  80. data/lib/write_xlsx/utility.rb +18 -6
  81. data/lib/write_xlsx/version.rb +1 -1
  82. data/lib/write_xlsx/workbook.rb +5 -5
  83. data/lib/write_xlsx/worksheet.rb +113 -125
  84. data/test/drawing/test_drawing_chart_01.rb +6 -2
  85. data/test/drawing/test_drawing_image_01.rb +12 -3
  86. data/test/drawing/test_drawing_shape_01.rb +8 -5
  87. data/test/drawing/test_drawing_shape_02.rb +12 -5
  88. data/test/drawing/test_drawing_shape_03.rb +8 -5
  89. data/test/drawing/test_drawing_shape_04.rb +8 -24
  90. data/test/drawing/test_drawing_shape_05.rb +8 -5
  91. data/test/drawing/test_drawing_shape_06.rb +11 -6
  92. data/test/drawing/test_drawing_shape_07.rb +11 -6
  93. data/test/drawing/test_write_a_graphic_frame_locks.rb +1 -1
  94. data/test/drawing/test_write_c_chart.rb +1 -1
  95. data/test/drawing/test_write_c_nv_graphic_frame_pr.rb +1 -1
  96. data/test/drawing/test_write_c_nv_pr.rb +1 -1
  97. data/test/drawing/test_write_col.rb +1 -1
  98. data/test/drawing/test_write_col_off.rb +1 -1
  99. data/test/drawing/test_write_ext.rb +1 -1
  100. data/test/drawing/test_write_pos.rb +1 -1
  101. data/test/drawing/test_write_row.rb +1 -1
  102. data/test/drawing/test_write_row_off.rb +1 -1
  103. data/test/drawing/test_write_xfrm_extension.rb +1 -1
  104. data/test/drawing/test_write_xfrm_offset.rb +1 -1
  105. data/test/perl_output/chart_gauge.xlsx +0 -0
  106. data/test/regression/test_chart_axis26.rb +10 -8
  107. data/test/regression/test_chart_axis27.rb +1 -1
  108. data/test/regression/test_chart_axis28.rb +1 -1
  109. data/test/regression/test_chart_axis29.rb +1 -1
  110. data/test/regression/test_chart_axis33.rb +1 -1
  111. data/test/regression/test_chart_axis44.rb +54 -0
  112. data/test/regression/test_chart_axis45.rb +54 -0
  113. data/test/regression/test_chart_axis46.rb +54 -0
  114. data/test/regression/test_chart_combined10.rb +43 -0
  115. data/test/regression/test_chart_combined11.rb +63 -0
  116. data/test/regression/test_chart_data_labels25.rb +1 -1
  117. data/test/regression/test_chart_doughnut07.rb +37 -0
  118. data/test/regression/test_chart_font09.rb +1 -1
  119. data/test/regression/test_chart_size03.rb +4 -1
  120. data/test/regression/test_comment14.rb +29 -0
  121. data/test/regression/test_image08.rb +5 -4
  122. data/test/regression/test_image15.rb +4 -2
  123. data/test/regression/test_image28.rb +1 -1
  124. data/test/regression/test_object_position01.rb +26 -0
  125. data/test/regression/test_object_position02.rb +26 -0
  126. data/test/regression/test_object_position03.rb +26 -0
  127. data/test/regression/test_object_position04.rb +44 -0
  128. data/test/regression/test_object_position06.rb +28 -0
  129. data/test/regression/test_object_position07.rb +28 -0
  130. data/test/regression/test_object_position08.rb +47 -0
  131. data/test/regression/test_object_position09.rb +50 -0
  132. data/test/regression/test_object_position10.rb +28 -0
  133. data/test/regression/test_shape_connect01.rb +4 -2
  134. data/test/regression/xlsx_files/chart_axis26.xlsx +0 -0
  135. data/test/regression/xlsx_files/chart_axis27.xlsx +0 -0
  136. data/test/regression/xlsx_files/chart_axis28.xlsx +0 -0
  137. data/test/regression/xlsx_files/chart_axis29.xlsx +0 -0
  138. data/test/regression/xlsx_files/chart_axis33.xlsx +0 -0
  139. data/test/regression/xlsx_files/chart_axis44.xlsx +0 -0
  140. data/test/regression/xlsx_files/chart_axis45.xlsx +0 -0
  141. data/test/regression/xlsx_files/chart_axis46.xlsx +0 -0
  142. data/test/regression/xlsx_files/chart_combined10.xlsx +0 -0
  143. data/test/regression/xlsx_files/chart_combined11.xlsx +0 -0
  144. data/test/regression/xlsx_files/chart_data_labels25.xlsx +0 -0
  145. data/test/regression/xlsx_files/chart_doughnut07.xlsx +0 -0
  146. data/test/regression/xlsx_files/chart_font09.xlsx +0 -0
  147. data/test/regression/xlsx_files/comment14.xlsx +0 -0
  148. data/test/regression/xlsx_files/object_position01.xlsx +0 -0
  149. data/test/regression/xlsx_files/object_position02.xlsx +0 -0
  150. data/test/regression/xlsx_files/object_position03.xlsx +0 -0
  151. data/test/regression/xlsx_files/object_position04.xlsx +0 -0
  152. data/test/regression/xlsx_files/object_position06.xlsx +0 -0
  153. data/test/regression/xlsx_files/object_position07.xlsx +0 -0
  154. data/test/regression/xlsx_files/object_position08.xlsx +0 -0
  155. data/test/regression/xlsx_files/object_position09.xlsx +0 -0
  156. data/test/regression/xlsx_files/object_position10.xlsx +0 -0
  157. data/test/test_example_match.rb +836 -771
  158. data/test/workbook/test_check_sheetname.rb +61 -0
  159. metadata +75 -6
@@ -10,7 +10,7 @@
10
10
  # of more complex sparkline formatting.
11
11
  #
12
12
  # reverse ('(c)'), November 2011, John McNamara, jmcnamara@cpan.org
13
- # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
13
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
14
14
  #
15
15
 
16
16
  require 'write_xlsx'
@@ -10,7 +10,7 @@
10
10
  # options that can be applied to sparklines.
11
11
  #
12
12
  # reverse ('(c)'), November 2011, John McNamara, jmcnamara@cpan.org
13
- # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
13
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
14
14
  #
15
15
 
16
16
  require 'write_xlsx'
data/examples/stats.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # A Simple example of how to use functions with the WriteXLSX gem.
7
7
  #
8
8
  # reverse(c), March 2001, John McNamara, jmcnamara@cpan.org
9
- # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
9
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
10
10
  #
11
11
 
12
12
  require 'write_xlsx'
@@ -9,7 +9,7 @@
9
9
  # other worksheets within the same workbook.
10
10
  #
11
11
  # reverse(c), March 2001, John McNamara, jmcnamara@cpan.org
12
- # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
12
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
13
13
  #
14
14
 
15
15
  require 'write_xlsx'
data/examples/stocks.rb CHANGED
@@ -9,7 +9,7 @@
9
9
  # with colours to indicate if a share price has gone up or down.
10
10
  #
11
11
  # reverse(c), March 2001, John McNamara, jmcnamara@cpan.org
12
- # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
12
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
13
13
  #
14
14
 
15
15
  require 'write_xlsx'
@@ -5,7 +5,7 @@
5
5
  # Example of how to set Excel worksheet tab colours.
6
6
  #
7
7
  # reverse(c), May 2006, John McNamara, jmcnamara@cpan.org
8
- # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
8
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
9
9
  #
10
10
 
11
11
  require 'write_xlsx'
data/examples/tables.rb CHANGED
@@ -9,7 +9,7 @@
9
9
  # structure that can be references in a formula or formatted collectively.
10
10
  #
11
11
  # reverse(c), March 2001, John McNamara, jmcnamara@cpan.org
12
- # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
12
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
13
13
  #
14
14
 
15
15
  require 'write_xlsx'
@@ -1178,8 +1178,8 @@ def write_cat_axis(params) # :nodoc:
1178
1178
  return unless axis_ids
1179
1179
  return if axis_ids.empty?
1180
1180
 
1181
- position = @cat_axis_position
1182
- horiz = @horiz_cat_axis
1181
+ position = @cat_axis_position
1182
+ is_y_axis = @horiz_cat_axis
1183
1183
 
1184
1184
  # Overwrite the default axis position with a user supplied value.
1185
1185
  position = x_axis.position || position
@@ -1202,9 +1202,9 @@ def write_cat_axis(params) # :nodoc:
1202
1202
 
1203
1203
  # Write the axis title elements.
1204
1204
  if x_axis.formula
1205
- write_title_formula(x_axis, horiz, @x_axis, x_axis.layout)
1205
+ write_title_formula(x_axis, is_y_axis, @x_axis, x_axis.layout)
1206
1206
  elsif x_axis.name
1207
- write_title_rich(x_axis, horiz, x_axis.layout)
1207
+ write_title_rich(x_axis, is_y_axis, x_axis.layout)
1208
1208
  end
1209
1209
 
1210
1210
  # Write the c:numFmt element.
@@ -1808,10 +1808,10 @@ def write_auto_title_deleted
1808
1808
  #
1809
1809
  # Write the <c:title> element for a rich string.
1810
1810
  #
1811
- def write_title_rich(title, horiz = nil, layout = nil, overlay = nil) # :nodoc:
1811
+ def write_title_rich(title, is_y_axis = nil, layout = nil, overlay = nil) # :nodoc:
1812
1812
  @writer.tag_elements('c:title') do
1813
1813
  # Write the c:tx element.
1814
- write_tx_rich(title, horiz)
1814
+ write_tx_rich(title, is_y_axis)
1815
1815
  # Write the c:layout element.
1816
1816
  write_layout(layout, 'text')
1817
1817
  # Write the c:overlay element.
@@ -1822,7 +1822,7 @@ def write_title_rich(title, horiz = nil, layout = nil, overlay = nil) # :nodoc:
1822
1822
  #
1823
1823
  # Write the <c:title> element for a rich string.
1824
1824
  #
1825
- def write_title_formula(title, horiz = nil, axis = nil, layout = nil, overlay = nil) # :nodoc:
1825
+ def write_title_formula(title, is_y_axis = nil, axis = nil, layout = nil, overlay = nil) # :nodoc:
1826
1826
  @writer.tag_elements('c:title') do
1827
1827
  # Write the c:tx element.
1828
1828
  write_tx_formula(title.formula, axis ? axis.data_id : title.data_id)
@@ -1831,15 +1831,15 @@ def write_title_formula(title, horiz = nil, axis = nil, layout = nil, overlay =
1831
1831
  # Write the c:overlay element.
1832
1832
  write_overlay if overlay
1833
1833
  # Write the c:txPr element.
1834
- write_tx_pr(horiz, axis ? axis.name_font : title.name_font)
1834
+ write_tx_pr(is_y_axis, axis ? axis.name_font : title.name_font)
1835
1835
  end
1836
1836
  end
1837
1837
 
1838
1838
  #
1839
1839
  # Write the <c:tx> element.
1840
1840
  #
1841
- def write_tx_rich(title, horiz) # :nodoc:
1842
- @writer.tag_elements('c:tx') { write_rich(title, horiz) }
1841
+ def write_tx_rich(title, is_y_axis) # :nodoc:
1842
+ @writer.tag_elements('c:tx') { write_rich(title, is_y_axis) }
1843
1843
  end
1844
1844
 
1845
1845
  #
@@ -1861,14 +1861,14 @@ def write_tx_formula(title, data_id) # :nodoc:
1861
1861
  #
1862
1862
  # Write the <c:rich> element.
1863
1863
  #
1864
- def write_rich(title, horiz) # :nodoc:
1864
+ def write_rich(title, is_y_axis) # :nodoc:
1865
1865
  rotation = nil
1866
1866
  if title.name_font && title.name_font[:_rotation]
1867
1867
  rotation = title.name_font[:_rotation]
1868
1868
  end
1869
1869
  @writer.tag_elements('c:rich') do
1870
1870
  # Write the a:bodyPr element.
1871
- write_a_body_pr(rotation, horiz)
1871
+ write_a_body_pr(rotation, is_y_axis)
1872
1872
  # Write the a:lstStyle element.
1873
1873
  write_a_lst_style
1874
1874
  # Write the a:p element.
@@ -2241,7 +2241,12 @@ def write_num_base(tag, data)
2241
2241
  write_format_code('General')
2242
2242
 
2243
2243
  # Write the c:ptCount element.
2244
- write_pt_count(data.size)
2244
+ if data
2245
+ count = data.size
2246
+ else
2247
+ count = 0
2248
+ end
2249
+ write_pt_count(count)
2245
2250
 
2246
2251
  data.each_with_index do |token, i|
2247
2252
  # Write non-numeric data as 0.
@@ -8,7 +8,7 @@
8
8
  # See formatting note in Chart.
9
9
  #
10
10
  # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
- # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ # Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
12
  #
13
13
 
14
14
  require 'write_xlsx/package/xml_writer_simple'
@@ -8,7 +8,7 @@
8
8
  # See formatting note in Chart.
9
9
  #
10
10
  # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
- # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ # Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
12
  #
13
13
 
14
14
  require 'write_xlsx/package/xml_writer_simple'
@@ -8,7 +8,7 @@
8
8
  # See formatting note in Chart.
9
9
  #
10
10
  # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
- # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ # Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
12
  #
13
13
 
14
14
  require 'write_xlsx/package/xml_writer_simple'
@@ -8,7 +8,7 @@
8
8
  # See formatting note in Excel::Writer::XLSX::Chart.
9
9
  #
10
10
  # Copyright 2000-2014, John McNamara, jmcnamara@cpan.org
11
- # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ # Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
12
  #
13
13
 
14
14
  require 'write_xlsx/package/xml_writer_simple'
@@ -8,7 +8,7 @@
8
8
  # See formatting note in Chart.
9
9
  #
10
10
  # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
- # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ # Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
12
  #
13
13
 
14
14
  require 'write_xlsx/package/xml_writer_simple'
@@ -8,7 +8,7 @@
8
8
  # See formatting note in Chart.
9
9
  #
10
10
  # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
- # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ # Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
12
  #
13
13
 
14
14
  require 'write_xlsx/package/xml_writer_simple'
@@ -42,13 +42,6 @@ def initialize(subtype)
42
42
  }
43
43
  end
44
44
 
45
- #
46
- # Override parent method to add a warning.
47
- #
48
- def combine(chart)
49
- raise "Combined chart not currently supported for Pie charts"
50
- end
51
-
52
45
  #
53
46
  # Set the Pie/Doughnut chart rotation: the angle of the first slice.
54
47
  #
@@ -91,11 +84,31 @@ def write_pie_chart
91
84
  # Write the <c:plotArea> element.
92
85
  #
93
86
  def write_plot_area
87
+ second_chart = @combined
88
+
94
89
  @writer.tag_elements('c:plotArea') do
95
90
  # Write the c:layout element.
96
91
  write_layout(@plotarea.layout, 'plot')
97
92
  # Write the subclass chart type element.
98
93
  write_chart_type
94
+ # Configure a combined chart if present.
95
+ if second_chart
96
+ # Secondary axis has unique id otherwise use same as primary.
97
+ if second_chart.is_secondary?
98
+ second_chart.id = 1000 + @id
99
+ else
100
+ second_chart.id = @id
101
+ end
102
+
103
+ # Share the same filehandle for writing
104
+ second_chart.writer = @writer
105
+
106
+ # Share series index with primary chart.
107
+ second_chart.series_index = @series_index
108
+
109
+ # Write the subclass chart type elements for combined chart.
110
+ second_chart.write_chart_type
111
+ end
99
112
  # Write the c:spPr eleent for the plotarea formatting.
100
113
  write_sp_pr(@plotarea)
101
114
  end
@@ -8,7 +8,7 @@
8
8
  # See formatting note in Chart.
9
9
  #
10
10
  # Copyright 2000-2012, John McNamara, jmcnamara@cpan.org
11
- # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ # Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
12
  #
13
13
 
14
14
  require 'write_xlsx/package/xml_writer_simple'
@@ -8,7 +8,7 @@
8
8
  # See formatting note in Chart.
9
9
  #
10
10
  # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
- # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ # Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
12
  #
13
13
 
14
14
  require 'write_xlsx/package/xml_writer_simple'
@@ -8,7 +8,7 @@
8
8
  # See formatting note in Chart.
9
9
  #
10
10
  # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
11
- # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ # Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
12
  #
13
13
 
14
14
  require 'write_xlsx/package/xml_writer_simple'
@@ -6,7 +6,7 @@
6
6
  # Used in conjunction with WriteXLSX
7
7
  #
8
8
  # Copyright 2000-2011, John McNamara, jmcnamara@cpan.org
9
- # Convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
9
+ # Convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
10
10
  #
11
11
 
12
12
  require 'write_xlsx/worksheet'
@@ -19,7 +19,7 @@ class Chartsheet < Worksheet
19
19
 
20
20
  def initialize(workbook, index, name)
21
21
  super
22
- @drawing = Drawing.new
22
+ @drawings = Drawings.new
23
23
  @is_chartsheet = true
24
24
  @chart = nil
25
25
  @charts = [1]
@@ -176,9 +176,9 @@ def set_high_low_lines(*args)
176
176
  def prepare_chart(index, chart_id, drawing_id) # :nodoc:
177
177
  @chart.id = chart_id - 1
178
178
 
179
- drawing = Drawing.new
180
- @drawing = drawing
181
- @drawing.orientation = @page_setup.orientation
179
+ drawings = Drawings.new
180
+ @drawings = drawings
181
+ @drawings.orientation = @page_setup.orientation
182
182
 
183
183
  @external_drawing_links << [ '/drawing', "../drawings/drawing#{drawing_id}.xml" ]
184
184
 
@@ -4,6 +4,15 @@
4
4
 
5
5
  module Writexlsx
6
6
  class Drawing
7
+ attr_accessor :type, :dimensions, :width, :height, :name, :shape, :anchor
8
+
9
+ def initialize(type, dimensions, width, height, name, shape, anchor)
10
+ @type, @dimensions, @width, @height, @name, @shape, @anchor =
11
+ type, dimensions, width, height, name, shape, anchor
12
+ end
13
+ end
14
+
15
+ class Drawings
7
16
  include Writexlsx::Utility
8
17
 
9
18
  attr_writer :embedded, :orientation
@@ -32,10 +41,10 @@ def assemble_xml_file
32
41
  write_drawing_workspace do
33
42
  if @embedded
34
43
  index = 0
35
- @drawings.each do |dimensions|
44
+ @drawings.each do |drawing|
36
45
  # Write the xdr:twoCellAnchor element.
37
46
  index += 1
38
- write_two_cell_anchor(index, *(dimensions.flatten))
47
+ write_two_cell_anchor(index, drawing)
39
48
  end
40
49
  else
41
50
  # Write the xdr:absoluteAnchor element.
@@ -48,8 +57,8 @@ def assemble_xml_file
48
57
  #
49
58
  # Add a chart, image or shape sub object to the drawing.
50
59
  #
51
- def add_drawing_object(*args)
52
- @drawings << args.flatten
60
+ def add_drawing_object(drawing)
61
+ @drawings << drawing
53
62
  end
54
63
 
55
64
  private
@@ -71,14 +80,25 @@ def write_drawing_workspace
71
80
  # Write the <xdr:twoCellAnchor> element.
72
81
  #
73
82
  def write_two_cell_anchor(*args)
74
- index, type, col_from, row_from, col_from_offset, row_from_offset,
75
- col_to, row_to, col_to_offset, row_to_offset, col_absolute, row_absolute,
76
- width, height, description, shape = args
83
+ index, drawing = args
84
+
85
+ type = drawing.type
86
+ width = drawing.width
87
+ height = drawing.height
88
+ description = drawing.name
89
+ shape = drawing.shape
90
+ anchor = drawing.anchor
91
+ col_from, row_from, col_from_offset, row_from_offset,
92
+ col_to, row_to, col_to_offset, row_to_offset, col_absolute, row_absolute = drawing.dimensions
77
93
 
78
94
  attributes = []
79
95
 
80
96
  # Add attribute for images.
81
- attributes << [:editAs, 'oneCell'] if type == 2
97
+ if anchor == 2
98
+ attributes << [:editAs, 'oneCell']
99
+ elsif anchor == 3
100
+ attributes << [:editAs, 'absolute']
101
+ end
82
102
 
83
103
  # Add attribute for shapes.
84
104
  attributes << [:editAs, shape.edit_as] if shape && shape.edit_as
@@ -257,13 +257,9 @@ def [](row)
257
257
  @comments[row]
258
258
  end
259
259
 
260
- def add(comment)
261
- if @comments[comment.row]
262
- @comments[comment.row][comment.col] = comment
263
- else
264
- @comments[comment.row] = {}
265
- @comments[comment.row][comment.col] = comment
266
- end
260
+ def add(workbook, worksheet, row, col, string, options)
261
+ @comments[row] ||= {}
262
+ @comments[row][col] = [workbook, worksheet, row, col, string, options]
267
263
  end
268
264
 
269
265
  def empty?
@@ -293,6 +289,10 @@ def sorted_comments
293
289
  # We sort the comments by row and column but that isn't strictly required.
294
290
  @comments.keys.sort.each do |row|
295
291
  @comments[row].keys.sort.each do |col|
292
+ user_options = @comments[row][col]
293
+ comment = Comment.new(*user_options)
294
+ @comments[row][col] = comment
295
+
296
296
  # Set comment visibility if required and not already user defined.
297
297
  @comments[row][col].visible ||= 1 if comments_visible?
298
298
 
@@ -8,14 +8,14 @@ module Writexlsx
8
8
  # Used in conjunction with WriteXLSX.
9
9
  #
10
10
  # Copyright 2000-2012, John McNamara, jmcnamara@cpan.org
11
- # Converted to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
11
+ # Converted to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
12
  #
13
13
  class Shape
14
14
  include Writexlsx::Utility
15
15
 
16
16
  attr_reader :edit_as, :type, :drawing
17
17
  attr_reader :tx_box, :fill, :line, :format
18
- attr_reader :align, :valign
18
+ attr_reader :align, :valign, :anchor
19
19
  attr_accessor :name, :connect, :type, :id, :start, :end, :rotation
20
20
  attr_accessor :flip_h, :flip_v, :adjustments, :palette, :text, :stencil
21
21
  attr_accessor :row_start, :row_end, :column_start, :column_end
@@ -183,11 +183,12 @@ def calc_position_emus(worksheet)
183
183
  @y_abs = (y_abslt * 9_525).to_i
184
184
  end
185
185
 
186
- def set_position(row_start, column_start, x_offset, y_offset, x_scale, y_scale)
186
+ def set_position(row_start, column_start, x_offset, y_offset, x_scale, y_scale, anchor)
187
187
  @row_start = row_start
188
188
  @column_start = column_start
189
189
  @x_offset = x_offset || 0
190
190
  @y_offset = y_offset || 0
191
+ @anchor = anchor || 1
191
192
 
192
193
  # Override shape scale if supplied as an argument. Otherwise, use the
193
194
  # existing shape scale factors.