write_xlsx 1.07.0 → 1.09.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/Changes +40 -0
  3. data/README.md +1 -1
  4. data/examples/background.rb +19 -0
  5. data/examples/ignore_errors.rb +39 -0
  6. data/ignore_errors.xlsx +0 -0
  7. data/lib/write_xlsx/chart/axis.rb +3 -3
  8. data/lib/write_xlsx/chart/scatter.rb +0 -15
  9. data/lib/write_xlsx/chart/series.rb +1 -1
  10. data/lib/write_xlsx/chart.rb +31 -33
  11. data/lib/write_xlsx/chartsheet.rb +3 -3
  12. data/lib/write_xlsx/drawing.rb +118 -55
  13. data/lib/write_xlsx/format.rb +11 -179
  14. data/lib/write_xlsx/package/app.rb +5 -5
  15. data/lib/write_xlsx/package/button.rb +8 -8
  16. data/lib/write_xlsx/package/comments.rb +8 -8
  17. data/lib/write_xlsx/package/conditional_format.rb +2 -8
  18. data/lib/write_xlsx/package/content_types.rb +18 -9
  19. data/lib/write_xlsx/package/core.rb +5 -5
  20. data/lib/write_xlsx/package/custom.rb +2 -2
  21. data/lib/write_xlsx/package/metadata.rb +159 -0
  22. data/lib/write_xlsx/package/packager.rb +22 -0
  23. data/lib/write_xlsx/package/shared_strings.rb +6 -6
  24. data/lib/write_xlsx/package/styles.rb +27 -14
  25. data/lib/write_xlsx/package/table.rb +31 -23
  26. data/lib/write_xlsx/package/theme.rb +1 -1
  27. data/lib/write_xlsx/package/vml.rb +43 -43
  28. data/lib/write_xlsx/shape.rb +17 -15
  29. data/lib/write_xlsx/sparkline.rb +340 -340
  30. data/lib/write_xlsx/utility.rb +9 -24
  31. data/lib/write_xlsx/version.rb +1 -1
  32. data/lib/write_xlsx/workbook.rb +193 -643
  33. data/lib/write_xlsx/worksheet/cell_data.rb +25 -3
  34. data/lib/write_xlsx/worksheet/data_validation.rb +21 -26
  35. data/lib/write_xlsx/worksheet/hyperlink.rb +4 -4
  36. data/lib/write_xlsx/worksheet/page_setup.rb +12 -12
  37. data/lib/write_xlsx/worksheet.rb +461 -4233
  38. data/test/drawing/{test_write_ext.rb → test_write_xdr_ext.rb} +2 -2
  39. data/test/perl_output/background.xlsx +0 -0
  40. data/test/perl_output/ignore_errors.xlsx +0 -0
  41. data/test/regression/images/logo.gif +0 -0
  42. data/test/regression/images/logo.jpg +0 -0
  43. data/test/regression/images/red.gif +0 -0
  44. data/test/regression/test_background01.rb +23 -0
  45. data/test/regression/test_background02.rb +23 -0
  46. data/test/regression/test_background03.rb +24 -0
  47. data/test/regression/test_background04.rb +25 -0
  48. data/test/regression/test_background05.rb +25 -0
  49. data/test/regression/test_background06.rb +31 -0
  50. data/test/regression/test_background07.rb +37 -0
  51. data/test/regression/test_chart_axis47.rb +52 -0
  52. data/test/regression/test_chart_axis48.rb +53 -0
  53. data/test/regression/test_chart_crossing01.rb +1 -1
  54. data/test/regression/test_chart_crossing05.rb +46 -0
  55. data/test/regression/test_chart_crossing06.rb +46 -0
  56. data/test/regression/test_chart_data_labels48.rb +55 -0
  57. data/test/regression/test_chart_data_labels49.rb +55 -0
  58. data/test/regression/test_chart_data_labels50.rb +57 -0
  59. data/test/regression/test_dynamic_array01.rb +25 -0
  60. data/test/regression/test_format16.rb +24 -0
  61. data/test/regression/test_format17.rb +24 -0
  62. data/test/regression/test_header04.rb +30 -0
  63. data/test/regression/test_hyperlink50.rb +27 -0
  64. data/test/regression/test_hyperlink51.rb +27 -0
  65. data/test/regression/test_ignore_error01.rb +23 -0
  66. data/test/regression/test_ignore_error02.rb +24 -0
  67. data/test/regression/test_ignore_error03.rb +26 -0
  68. data/test/regression/test_ignore_error04.rb +26 -0
  69. data/test/regression/test_ignore_error05.rb +32 -0
  70. data/test/regression/test_ignore_error06.rb +32 -0
  71. data/test/regression/test_image52.rb +26 -0
  72. data/test/regression/test_image53.rb +26 -0
  73. data/test/regression/test_image54.rb +26 -0
  74. data/test/regression/test_image55.rb +27 -0
  75. data/test/regression/test_image56.rb +23 -0
  76. data/test/regression/test_image57.rb +23 -0
  77. data/test/regression/test_protect04.rb +32 -0
  78. data/test/regression/test_protect05.rb +35 -0
  79. data/test/regression/test_protect06.rb +35 -0
  80. data/test/regression/test_protect07.rb +23 -0
  81. data/test/regression/test_set_column10.rb +55 -0
  82. data/test/regression/test_set_column11.rb +48 -0
  83. data/test/regression/test_set_row01.rb +35 -0
  84. data/test/regression/test_set_row02.rb +35 -0
  85. data/test/regression/test_set_row03.rb +35 -0
  86. data/test/regression/test_set_row04.rb +35 -0
  87. data/test/regression/test_table26.rb +38 -0
  88. data/test/regression/xlsx_files/background01.xlsx +0 -0
  89. data/test/regression/xlsx_files/background02.xlsx +0 -0
  90. data/test/regression/xlsx_files/background03.xlsx +0 -0
  91. data/test/regression/xlsx_files/background04.xlsx +0 -0
  92. data/test/regression/xlsx_files/background05.xlsx +0 -0
  93. data/test/regression/xlsx_files/background06.xlsx +0 -0
  94. data/test/regression/xlsx_files/background07.xlsx +0 -0
  95. data/test/regression/xlsx_files/chart_axis47.xlsx +0 -0
  96. data/test/regression/xlsx_files/chart_axis48.xlsx +0 -0
  97. data/test/regression/xlsx_files/chart_crossing05.xlsx +0 -0
  98. data/test/regression/xlsx_files/chart_crossing06.xlsx +0 -0
  99. data/test/regression/xlsx_files/chart_data_labels48.xlsx +0 -0
  100. data/test/regression/xlsx_files/chart_data_labels49.xlsx +0 -0
  101. data/test/regression/xlsx_files/chart_data_labels50.xlsx +0 -0
  102. data/test/regression/xlsx_files/dynamic_array01.xlsx +0 -0
  103. data/test/regression/xlsx_files/format16.xlsx +0 -0
  104. data/test/regression/xlsx_files/format17.xlsx +0 -0
  105. data/test/regression/xlsx_files/header04.xlsx +0 -0
  106. data/test/regression/xlsx_files/hyperlink50.xlsx +0 -0
  107. data/test/regression/xlsx_files/hyperlink51.xlsx +0 -0
  108. data/test/regression/xlsx_files/ignore_error01.xlsx +0 -0
  109. data/test/regression/xlsx_files/ignore_error02.xlsx +0 -0
  110. data/test/regression/xlsx_files/ignore_error03.xlsx +0 -0
  111. data/test/regression/xlsx_files/ignore_error04.xlsx +0 -0
  112. data/test/regression/xlsx_files/ignore_error05.xlsx +0 -0
  113. data/test/regression/xlsx_files/ignore_error06.xlsx +0 -0
  114. data/test/regression/xlsx_files/image52.xlsx +0 -0
  115. data/test/regression/xlsx_files/image53.xlsx +0 -0
  116. data/test/regression/xlsx_files/image54.xlsx +0 -0
  117. data/test/regression/xlsx_files/image55.xlsx +0 -0
  118. data/test/regression/xlsx_files/image56.xlsx +0 -0
  119. data/test/regression/xlsx_files/image57.xlsx +0 -0
  120. data/test/regression/xlsx_files/protect04.xlsx +0 -0
  121. data/test/regression/xlsx_files/protect05.xlsx +0 -0
  122. data/test/regression/xlsx_files/protect06.xlsx +0 -0
  123. data/test/regression/xlsx_files/protect07.xlsx +0 -0
  124. data/test/regression/xlsx_files/set_row01.xlsx +0 -0
  125. data/test/regression/xlsx_files/set_row03.xlsx +0 -0
  126. data/test/regression/xlsx_files/table26.xlsx +0 -0
  127. data/test/test_example_match.rb +43 -0
  128. data/test/utility/test_range.rb +20 -0
  129. data/test/worksheet/test_pixels_to_row_col.rb +46 -0
  130. metadata +190 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 677847fdb975ab7253b3a5ed5f6aa779a9bbf2a459e941f5037b7d557e2abfe4
4
- data.tar.gz: 4c4b0b03ce3b510a0ad6423c30a76fc778463afe92f992da52b49bbe65c7a1ac
3
+ metadata.gz: c6e34fc6f5c19637ceda0a196039c186fea4e0b6959c1d99d6d13260854cf0fd
4
+ data.tar.gz: c582b95f3b8e9851015bd8555a8d6b5a1e9d9d9f4cec1e66357ea328963b765e
5
5
  SHA512:
6
- metadata.gz: b3f81d2d54e5f7a7170c34e7666f58c7f4f77b993ff3b95263327b0ff8edff5c9a0b1a6ea825ece5b43c5b1d2b91a6f01764237f22ee6442bd8c747de8e04150
7
- data.tar.gz: 3e49064459345dbcc5d97fef0f8154159776e8361cb0709e8a4564f32dd062fe95b6e4f08976df81b5ac478a40287be9a33086726444af3c75d1cbeb5c869dc2
6
+ metadata.gz: 00a16bb85b40a0e8ca072e1afaac2723f9bd845d28c4ea495c8c9fab0e4bad40c2f2b6cbe2875cdec97fcb8a0ad0a1f53a357c479e838bb873debba49e8de8f5
7
+ data.tar.gz: ae74b4e1506d658d770c3667f45043e3f999d10bce0700e48a40c0cfcc1d07ce7d40e4a77e8b51ea7b65dbaecc2b131a9793b124e064c9e5448ee50e5c16808e
data/Changes CHANGED
@@ -1,5 +1,45 @@
1
1
  Change history of write_xlsx rubygem.
2
2
 
3
+ 2021-11-26 v1.09.0
4
+
5
+ Added support for background images in worksheets. See set_background().
6
+
7
+ Added support for GIF image files (and in Excel 365, animated GIF files).
8
+
9
+ Added support for pixel sizing in set_row() and set_column() via new
10
+ functions called set_row_pixels() and set_column_pixels().
11
+
12
+ 2021-11-19 v1.08.0
13
+
14
+ Added ability to add accessibility options "description" and
15
+ "decorative" to images via insert_image().
16
+
17
+ Added the workbook read_only_recommended() method to set the Excel
18
+ "Read-only Recommended" option that is available when saving a file.
19
+
20
+ Added option to set a chart crossing to 'min' as well as the existing
21
+ 'max' option. The 'min' option isn't available in the Excel interface
22
+ but can be enabled via VBA.
23
+
24
+ Added option to unprotect ranges in protected worksheets.
25
+
26
+ Added check, and warning, for worksheet tables with no data row. Either
27
+ with or without a header row.
28
+
29
+ Added ignore_errors() worksheet method to ignore Excel worksheet
30
+ errors/warnings in user defined ranges.
31
+
32
+ Fixed issue where pattern formats without colours where given a default
33
+ black fill colour.
34
+
35
+ Fix issue where custom chart data labels didn't inherit the position for
36
+ the data labels in the series.
37
+
38
+ Fixed issue with relative url links in images.
39
+
40
+ Fixed issue where headers/footers were restricted to 254 characters
41
+ instead of 255.
42
+
3
43
  2021-02-17 v1.07.0
4
44
 
5
45
  Added support for Border, Fill, Pattern and Gradient formatting to chart
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  gem to create a new file in the Excel 2007+ XLSX format, and you can use the
7
7
  same interface as writeexcel gem. write_xlsx is converted from Perl's module
8
- [Excel::Writer::XLSX-1.07](https://github.com/jmcnamara/excel-writer-xlsx/tree/CPAN_1.07)
8
+ [Excel::Writer::XLSX-1.09](https://github.com/jmcnamara/excel-writer-xlsx/tree/CPAN_1.09)
9
9
 
10
10
  ## Description
11
11
 
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # An example of setting a worksheet background image with Excel::Writer::XLSX.
7
+ #
8
+ # Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
9
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
10
+ #
11
+
12
+ require 'write_xlsx'
13
+
14
+ workbook = WriteXLSX.new('background.xlsx')
15
+ worksheet = workbook.add_worksheet
16
+
17
+ worksheet.set_background('republic.png')
18
+
19
+ workbook.close
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ##############################################################################
5
+ #
6
+ # An example of turning off worksheet cells errors/warnings using the
7
+ # Excel::Writer::XLSX module.
8
+ #
9
+ # Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
10
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
11
+ #
12
+
13
+ require 'write_xlsx'
14
+
15
+ workbook = WriteXLSX.new('ignore_errors.xlsx')
16
+ worksheet = workbook.add_worksheet
17
+
18
+ # Write strings that looks like numbers. This will cause an Excel warning.
19
+ worksheet.write_string('C2', '123')
20
+ worksheet.write_string('C3', '123')
21
+
22
+ # Write a divide by zero formula. This will also cause an Excel warning.
23
+ worksheet.write_formula('C5', '=1/0')
24
+ worksheet.write_formula('C6', '=1/0')
25
+
26
+ # Turn off some of the warnings:
27
+ worksheet.ignore_errors(
28
+ :number_stored_as_text => 'C3',
29
+ :eval_error => 'C6'
30
+ )
31
+
32
+ # Write some descriptions for the cells and make the column wider for clarity.
33
+ worksheet.set_column('B:B', 16)
34
+ worksheet.write('B2', 'Warning:')
35
+ worksheet.write('B3', 'Warning turned off:')
36
+ worksheet.write('B5', 'Warning:')
37
+ worksheet.write('B6', 'Warning turned off:')
38
+
39
+ workbook.close
Binary file
@@ -87,8 +87,8 @@ module Writexlsx
87
87
 
88
88
  def num_fmt_attributes
89
89
  [
90
- ['formatCode', @num_format],
91
- ['sourceLinked', source_linked]
90
+ ['formatCode', @num_format],
91
+ ['sourceLinked', source_linked]
92
92
  ]
93
93
  end
94
94
 
@@ -175,7 +175,7 @@ module Writexlsx
175
175
  if @position_axis == 'on_tick'
176
176
  @position_axis = 'midCat'
177
177
  elsif @position_axis == 'between'
178
- # Doesn't neet to be modified.
178
+ # Doesn't neet to be modified.
179
179
  else
180
180
  # Otherwise use the default value.
181
181
  @position_axis = nil
@@ -17,21 +17,6 @@ require 'write_xlsx/utility'
17
17
 
18
18
  module Writexlsx
19
19
  class Chart
20
- # The Scatter chart module also supports the following sub-types:
21
- #
22
- # markers_only (the default)
23
- # straight_with_markers
24
- # straight
25
- # smooth_with_markers
26
- # smooth
27
- # These can be specified at creation time via the add_chart() Worksheet
28
- # method:
29
- #
30
- # chart = workbook.add_chart(
31
- # :type => 'scatter',
32
- # :subtype => 'straight_with_markers'
33
- # )
34
- #
35
20
  class Scatter < self
36
21
  include Writexlsx::Utility
37
22
  include Writexlsx::WriteDPtPoint
@@ -192,7 +192,7 @@ module Writexlsx
192
192
  @values = aref_to_formula(params[:values])
193
193
  @categories = aref_to_formula(params[:categories])
194
194
  @name, @name_formula =
195
- chart.process_names(params[:name], params[:name_formula])
195
+ chart.process_names(params[:name], params[:name_formula])
196
196
 
197
197
  set_data_ids(params)
198
198
 
@@ -165,16 +165,16 @@ module Writexlsx
165
165
  include Writexlsx::Utility
166
166
  include Writexlsx::Gradient
167
167
 
168
- attr_accessor :id, :name # :nodoc:
169
- attr_writer :index, :palette, :protection # :nodoc:
170
- attr_reader :embedded, :formula_ids, :formula_data # :nodoc:
171
- attr_reader :x_scale, :y_scale, :x_offset, :y_offset # :nodoc:
172
- attr_reader :width, :height # :nodoc:
168
+ attr_accessor :id, :name # :nodoc:
169
+ attr_writer :index, :palette, :protection # :nodoc:
170
+ attr_reader :embedded, :formula_ids, :formula_data # :nodoc:
171
+ attr_reader :x_scale, :y_scale, :x_offset, :y_offset # :nodoc:
172
+ attr_reader :width, :height # :nodoc:
173
173
  attr_reader :label_positions, :label_position_default, :combined # :nodoc:
174
- attr_writer :date_category, :already_inserted
175
- attr_writer :series_index
176
- attr_writer :writer
177
- attr_reader :x2_axis, :y2_axis, :axis2_ids
174
+ attr_writer :date_category, :already_inserted # :nodoc:
175
+ attr_writer :series_index # :nodoc:
176
+ attr_writer :writer # :nodoc:
177
+ attr_reader :x2_axis, :y2_axis, :axis2_ids # :nodoc:
178
178
 
179
179
  #
180
180
  # Factory method for returning chart objects based on their class type.
@@ -1057,7 +1057,7 @@ module Writexlsx
1057
1057
  end
1058
1058
 
1059
1059
  def write_val_base(formula, data_id, tag) # :nodoc:
1060
- data = @formula_data[data_id]
1060
+ data = @formula_data[data_id]
1061
1061
 
1062
1062
  @writer.tag_elements(tag) do
1063
1063
  # Unlike Cat axes data should only be numeric.
@@ -1397,7 +1397,7 @@ module Writexlsx
1397
1397
 
1398
1398
  def write_crossing(crossing)
1399
1399
  # Note, the category crossing comes from the value axis.
1400
- if nil_or_max?(crossing)
1400
+ if [nil, 'max', 'min'].include?(crossing)
1401
1401
  # Write the c:crosses element.
1402
1402
  write_crosses(crossing)
1403
1403
  else
@@ -1408,11 +1408,11 @@ module Writexlsx
1408
1408
 
1409
1409
  def write_scaling_with_param(param)
1410
1410
  write_scaling(
1411
- param.reverse,
1412
- param.min,
1413
- param.max,
1414
- param.log_base
1415
- )
1411
+ param.reverse,
1412
+ param.min,
1413
+ param.max,
1414
+ param.log_base
1415
+ )
1416
1416
  end
1417
1417
  #
1418
1418
  # Write the <c:scaling> element.
@@ -1443,7 +1443,7 @@ module Writexlsx
1443
1443
  # Write the <c:orientation> element.
1444
1444
  #
1445
1445
  def write_orientation(reverse = nil) # :nodoc:
1446
- val = ptrue?(reverse) ? 'maxMin' : 'minMax'
1446
+ val = ptrue?(reverse) ? 'maxMin' : 'minMax'
1447
1447
 
1448
1448
  @writer.empty_tag('c:orientation', [ ['val', val] ])
1449
1449
  end
@@ -1499,9 +1499,9 @@ module Writexlsx
1499
1499
  source_linked = 0
1500
1500
 
1501
1501
  attributes = [
1502
- ['formatCode', format_code],
1503
- ['sourceLinked', source_linked]
1504
- ]
1502
+ ['formatCode', format_code],
1503
+ ['sourceLinked', source_linked]
1504
+ ]
1505
1505
 
1506
1506
  @writer.empty_tag('c:numFmt', attributes)
1507
1507
  end
@@ -1778,13 +1778,13 @@ module Writexlsx
1778
1778
  footer = 0.3
1779
1779
 
1780
1780
  attributes = [
1781
- ['b', b],
1782
- ['l', l],
1783
- ['r', r],
1784
- ['t', t],
1785
- ['header', header],
1786
- ['footer', footer]
1787
- ]
1781
+ ['b', b],
1782
+ ['l', l],
1783
+ ['r', r],
1784
+ ['t', t],
1785
+ ['header', header],
1786
+ ['footer', footer]
1787
+ ]
1788
1788
 
1789
1789
  @writer.empty_tag('c:pageMargins', attributes)
1790
1790
  end
@@ -2272,7 +2272,7 @@ module Writexlsx
2272
2272
  data.each_with_index do |token, i|
2273
2273
  # Write non-numeric data as 0.
2274
2274
  if token &&
2275
- !(token.to_s =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)
2275
+ !(token.to_s =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)
2276
2276
  token = 0
2277
2277
  end
2278
2278
 
@@ -2418,12 +2418,14 @@ module Writexlsx
2418
2418
  elsif label[:formula]
2419
2419
  write_custom_label_formula(label)
2420
2420
 
2421
+ write_d_lbl_pos(parent[:position]) if parent[:position]
2421
2422
  write_show_val if parent[:value]
2422
2423
  write_show_cat_name if parent[:category]
2423
2424
  write_show_ser_name if parent[:series_name]
2424
2425
  elsif label[:value]
2425
2426
  write_custom_label_str(label)
2426
2427
 
2428
+ write_d_lbl_pos(parent[:position]) if parent[:position]
2427
2429
  write_show_val if parent[:value]
2428
2430
  write_show_cat_name if parent[:category]
2429
2431
  write_show_ser_name if parent[:series_name]
@@ -2701,7 +2703,7 @@ module Writexlsx
2701
2703
  end
2702
2704
 
2703
2705
  def write_num_ref_or_lit(values, data)
2704
- if values.to_s =~ /^=/ # '=Sheet1!$A$1:$A$5'
2706
+ if values.to_s =~ /^=/ # '=Sheet1!$A$1:$A$5'
2705
2707
  write_num_ref(values, data, 'num')
2706
2708
  else # [1, 2, 3]
2707
2709
  write_num_lit(values)
@@ -2926,9 +2928,5 @@ module Writexlsx
2926
2928
  @writer.empty_tag(tag)
2927
2929
  end
2928
2930
  end
2929
-
2930
- def nil_or_max?(val) # :nodoc:
2931
- val.nil? || val == 'max'
2932
- end
2933
2931
  end
2934
2932
  end
@@ -204,9 +204,9 @@ module Writexlsx
204
204
  mc_preserve_attributes = 'mv:*'
205
205
 
206
206
  attributes = [
207
- ['xmlns', xmlns],
208
- ['xmlns:r', xmlns_r]
209
- ]
207
+ ['xmlns', xmlns],
208
+ ['xmlns:r', xmlns_r]
209
+ ]
210
210
 
211
211
  @writer.tag_elements('chartsheet', attributes) do
212
212
  yield
@@ -5,11 +5,11 @@ require 'write_xlsx/utility'
5
5
  module Writexlsx
6
6
  class Drawing
7
7
  attr_accessor :type, :dimensions, :width, :height, :description, :shape, :anchor, :rel_index, :url_rel_index
8
- attr_reader :tip
8
+ attr_reader :tip, :decorative
9
9
 
10
- def initialize(type, dimensions, width, height, description, shape, anchor, rel_index = nil, url_rel_index = nil, tip = nil)
11
- @type, @dimensions, @width, @height, @description, @shape, @anchor, @rel_index, @url_rel_index, @tip =
12
- type, dimensions, width, height, description, shape, anchor, rel_index, url_rel_index, tip
10
+ def initialize(type, dimensions, width, height, description, shape, anchor, rel_index = nil, url_rel_index = nil, tip = nil, decorative = nil)
11
+ @type, @dimensions, @width, @height, @description, @shape, @anchor, @rel_index, @url_rel_index, @tip, @decorative =
12
+ type, dimensions, width, height, description, shape, anchor, rel_index, url_rel_index, tip, decorative
13
13
  end
14
14
  end
15
15
 
@@ -70,8 +70,8 @@ module Writexlsx
70
70
  def write_drawing_workspace
71
71
  schema = 'http://schemas.openxmlformats.org/drawingml/'
72
72
  attributes = [
73
- ['xmlns:xdr', "#{schema}2006/spreadsheetDrawing"],
74
- ['xmlns:a', "#{schema}2006/main"]
73
+ ['xmlns:xdr', "#{schema}2006/spreadsheetDrawing"],
74
+ ['xmlns:a', "#{schema}2006/main"]
75
75
  ]
76
76
 
77
77
  @writer.tag_elements('xdr:wsDr', attributes) { yield }
@@ -92,6 +92,7 @@ module Writexlsx
92
92
  rel_index = drawing.rel_index
93
93
  url_rel_index = drawing.url_rel_index
94
94
  tip = drawing.tip
95
+ decorative = drawing.decorative
95
96
 
96
97
  col_from, row_from, col_from_offset, row_from_offset,
97
98
  col_to, row_to, col_to_offset, row_to_offset, col_absolute, row_absolute = drawing.dimensions
@@ -124,7 +125,7 @@ module Writexlsx
124
125
  write_pic(
125
126
  index, rel_index, col_absolute,
126
127
  row_absolute, width, height,
127
- description, url_rel_index , tip
128
+ description, url_rel_index , tip, decorative
128
129
  )
129
130
  else
130
131
  # Write the xdr:sp element for shapes.
@@ -148,13 +149,13 @@ module Writexlsx
148
149
  write_pos(0, 0)
149
150
 
150
151
  # Write the xdr:ext element.
151
- write_ext(9308969, 6078325)
152
+ write_xdr_ext(9308969, 6078325)
152
153
  else
153
154
  # Write the xdr:pos element.
154
155
  write_pos(0, -47625)
155
156
 
156
157
  # Write the xdr:ext element.
157
- write_ext(6162675, 6124575)
158
+ write_xdr_ext(6162675, 6124575)
158
159
  end
159
160
 
160
161
  # Write the xdr:graphicFrame element.
@@ -165,7 +166,7 @@ module Writexlsx
165
166
  end
166
167
  end
167
168
 
168
- #
169
+ #
169
170
  # Write the <xdr:from> element.
170
171
  #
171
172
  def write_from(col, row, col_offset, row_offset)
@@ -242,7 +243,7 @@ module Writexlsx
242
243
  #
243
244
  # Write the <xdr:ext> element.
244
245
  #
245
- def write_ext(cx, cy)
246
+ def write_xdr_ext(cx, cy)
246
247
  attributes = [
247
248
  ['cx', cx],
248
249
  ['cy', cy]
@@ -286,19 +287,25 @@ module Writexlsx
286
287
  #
287
288
  # Write the <xdr:cNvPr> element.
288
289
  #
289
- def write_c_nv_pr(index, name, description = nil, url_rel_index = nil, tip = nil)
290
+ def write_c_nv_pr(index, name, description = nil, url_rel_index = nil, tip = nil, decorative = nil)
290
291
  attributes = [
291
292
  ['id', index],
292
293
  ['name', name]
293
294
  ]
294
295
 
295
296
  # Add description attribute for images.
296
- attributes << ['descr', description] if description
297
+ attributes << ['descr', description] if ptrue?(description) && !ptrue?(decorative)
297
298
 
298
- if ptrue?(url_rel_index)
299
+ if ptrue?(url_rel_index) || ptrue?(decorative)
299
300
  @writer.tag_elements('xdr:cNvPr', attributes) do
300
- # Write the a:hlinkClick element.
301
- write_a_hlink_click(url_rel_index, tip)
301
+ if ptrue?(url_rel_index)
302
+ # Write the a:hlinkClick element.
303
+ write_a_hlink_click(url_rel_index, tip)
304
+ end
305
+ if ptrue?(decorative)
306
+ # Write the adec:decorative element.
307
+ write_decorative
308
+ end
302
309
  end
303
310
  else
304
311
  @writer.empty_tag('xdr:cNvPr', attributes)
@@ -323,6 +330,62 @@ module Writexlsx
323
330
  @writer.empty_tag('a:hlinkClick', attributes)
324
331
  end
325
332
 
333
+ #
334
+ # Write the <adec:decorative> element.
335
+ #
336
+ def write_decorative
337
+ @writer.tag_elements('a:extLst') do
338
+ write_a_uri_ext('{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}')
339
+ write_a16_creation_id
340
+ @writer.end_tag('a:ext')
341
+
342
+ write_a_uri_ext('{C183D7F6-B498-43B3-948B-1728B52AA6E4}')
343
+ write_adec_decorative
344
+ @writer.end_tag('a:ext')
345
+ end
346
+ end
347
+
348
+ #
349
+ # Write the <a:ext> element.
350
+ #
351
+ def write_a_uri_ext(uri)
352
+ attributes = [
353
+ ['uri', uri]
354
+ ]
355
+
356
+ @writer.start_tag('a:ext', attributes)
357
+ end
358
+
359
+ #
360
+ # Write the <adec:decorative> element.
361
+ #
362
+ def write_adec_decorative
363
+ xmlns_adec = 'http://schemas.microsoft.com/office/drawing/2017/decorative'
364
+ val = 1
365
+
366
+ attributes = [
367
+ ['xmlns:adec', xmlns_adec],
368
+ ['val', val]
369
+ ]
370
+
371
+ @writer.empty_tag('adec:decorative', attributes)
372
+ end
373
+
374
+ #
375
+ # Write the <a16:creationId> element.
376
+ #
377
+ def write_a16_creation_id
378
+ xmlns_a_16 = 'http://schemas.microsoft.com/office/drawing/2014/main'
379
+ id = '{00000000-0008-0000-0000-000002000000}'
380
+
381
+ attributes = [
382
+ ['xmlns:a16', xmlns_a_16],
383
+ ['id', id]
384
+ ]
385
+
386
+ @writer.empty_tag('a16:creationId', attributes)
387
+ end
388
+
326
389
  #
327
390
  # Write the <xdr:cNvGraphicFramePr> element.
328
391
  #
@@ -424,9 +487,9 @@ module Writexlsx
424
487
 
425
488
 
426
489
  attributes = [
427
- ['xmlns:c', xmlns_c],
428
- ['xmlns:r', xmlns_r]
429
- ]
490
+ ['xmlns:c', xmlns_c],
491
+ ['xmlns:r', xmlns_r]
492
+ ]
430
493
  attributes << r_id_attributes(id)
431
494
 
432
495
  @writer.empty_tag('c:chart', attributes)
@@ -456,9 +519,9 @@ module Writexlsx
456
519
  else
457
520
  # Add attribute for shapes.
458
521
  attributes = [
459
- [:macro, ''],
460
- [:textlink, '']
461
- ]
522
+ [:macro, ''],
523
+ [:textlink, '']
524
+ ]
462
525
  @writer.tag_elements('xdr:sp', attributes) do
463
526
 
464
527
  # Write the xdr:nvSpPr element.
@@ -491,17 +554,17 @@ module Writexlsx
491
554
 
492
555
  if shape.start
493
556
  attributes = [
494
- ['id', shape.start],
495
- ['idx', shape.start_index]
496
- ]
557
+ ['id', shape.start],
558
+ ['idx', shape.start_index]
559
+ ]
497
560
  @writer.empty_tag('a:stCxn', attributes)
498
561
  end
499
562
 
500
563
  if shape.end
501
564
  attributes = [
502
- ['id', shape.end],
503
- ['idx', shape.end_index]
504
- ]
565
+ ['id', shape.end],
566
+ ['idx', shape.end_index]
567
+ ]
505
568
  @writer.empty_tag('a:endCxn', attributes)
506
569
  end
507
570
  end
@@ -527,10 +590,10 @@ module Writexlsx
527
590
  #
528
591
  # Write the <xdr:pic> element.
529
592
  #
530
- def write_pic(index, rel_index, col_absolute, row_absolute, width, height, description, url_rel_index, tip)
593
+ def write_pic(index, rel_index, col_absolute, row_absolute, width, height, description, url_rel_index, tip, decorative)
531
594
  @writer.tag_elements('xdr:pic') do
532
595
  # Write the xdr:nvPicPr element.
533
- write_nv_pic_pr(index, rel_index, description, url_rel_index, tip)
596
+ write_nv_pic_pr(index, rel_index, description, url_rel_index, tip, decorative)
534
597
  # Write the xdr:blipFill element.
535
598
  write_blip_fill(rel_index)
536
599
 
@@ -546,12 +609,12 @@ module Writexlsx
546
609
  #
547
610
  # Write the <xdr:nvPicPr> element.
548
611
  #
549
- def write_nv_pic_pr(index, rel_index, description, url_rel_index, tip)
612
+ def write_nv_pic_pr(index, rel_index, description, url_rel_index, tip, decorative)
550
613
  @writer.tag_elements('xdr:nvPicPr') do
551
614
  # Write the xdr:cNvPr element.
552
615
  write_c_nv_pr(
553
616
  index + 1, "Picture #{index}", description,
554
- url_rel_index, tip
617
+ url_rel_index, tip, decorative
555
618
  )
556
619
  # Write the xdr:cNvPicPr element.
557
620
  write_c_nv_pic_pr
@@ -745,9 +808,9 @@ module Writexlsx
745
808
  adj_int = (adj * 1000).to_i
746
809
 
747
810
  attributes = [
748
- [:name, "adj#{suffix}"],
749
- [:fmla, "val #{adj_int}"]
750
- ]
811
+ [:name, "adj#{suffix}"],
812
+ [:fmla, "val #{adj_int}"]
813
+ ]
751
814
  @writer.empty_tag('a:gd', attributes)
752
815
  end
753
816
  end
@@ -804,15 +867,15 @@ module Writexlsx
804
867
  #
805
868
  def write_tx_body(shape)
806
869
  attributes = [
807
- [:vertOverflow, "clip"],
808
- [:wrap, "square"],
809
- [:lIns, "27432"],
810
- [:tIns, "22860"],
811
- [:rIns, "27432"],
812
- [:bIns, "22860"],
813
- [:anchor, shape.valign],
814
- [:upright, "1"]
815
- ]
870
+ [:vertOverflow, "clip"],
871
+ [:wrap, "square"],
872
+ [:lIns, "27432"],
873
+ [:tIns, "22860"],
874
+ [:rIns, "27432"],
875
+ [:bIns, "22860"],
876
+ [:anchor, shape.valign],
877
+ [:upright, "1"]
878
+ ]
816
879
  @writer.tag_elements('xdr:txBody') do
817
880
  @writer.empty_tag('a:bodyPr', attributes)
818
881
  @writer.empty_tag('a:lstStyle')
@@ -822,9 +885,9 @@ module Writexlsx
822
885
  rotation *= 60000
823
886
 
824
887
  attributes = [
825
- [:algn, shape.align],
826
- [:rtl, rotation]
827
- ]
888
+ [:algn, shape.align],
889
+ [:rtl, rotation]
890
+ ]
828
891
  @writer.tag_elements('a:pPr', attributes) do
829
892
  attributes = [ [:sz, "1000"] ]
830
893
  @writer.empty_tag('a:defRPr', attributes)
@@ -840,14 +903,14 @@ module Writexlsx
840
903
  strike = ptrue?(shape.format[:font_strikeout]) ? 'Strike' : 'noStrike'
841
904
 
842
905
  attributes = [
843
- [:lang, "en-US"],
844
- [:sz, size],
845
- [:b, bold],
846
- [:i, italic],
847
- [:u, underline],
848
- [:strike, strike],
849
- [:baseline, 0]
850
- ]
906
+ [:lang, "en-US"],
907
+ [:sz, size],
908
+ [:b, bold],
909
+ [:i, italic],
910
+ [:u, underline],
911
+ [:strike, strike],
912
+ [:baseline, 0]
913
+ ]
851
914
  @writer.tag_elements('a:rPr', attributes) do
852
915
  color = shape.format[:color]
853
916
  if color