write_xlsx 1.09.5 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/Changes +5 -0
  4. data/LICENSE.txt +1 -1
  5. data/examples/autofilter.rb +38 -9
  6. data/examples/dynamic_arrays.rb +247 -0
  7. data/examples/lambda.rb +43 -0
  8. data/examples/watermark.png +0 -0
  9. data/examples/watermark.rb +26 -0
  10. data/lib/write_xlsx/chart.rb +1 -0
  11. data/lib/write_xlsx/chartsheet.rb +1 -0
  12. data/lib/write_xlsx/col_name.rb +1 -0
  13. data/lib/write_xlsx/colors.rb +1 -0
  14. data/lib/write_xlsx/compatibility.rb +1 -0
  15. data/lib/write_xlsx/drawing.rb +20 -10
  16. data/lib/write_xlsx/format.rb +5 -0
  17. data/lib/write_xlsx/formats.rb +1 -0
  18. data/lib/write_xlsx/gradient.rb +2 -0
  19. data/lib/write_xlsx/package/app.rb +1 -0
  20. data/lib/write_xlsx/package/button.rb +6 -2
  21. data/lib/write_xlsx/package/comments.rb +3 -1
  22. data/lib/write_xlsx/package/conditional_format.rb +1 -0
  23. data/lib/write_xlsx/package/content_types.rb +1 -0
  24. data/lib/write_xlsx/package/core.rb +1 -0
  25. data/lib/write_xlsx/package/custom.rb +1 -0
  26. data/lib/write_xlsx/package/metadata.rb +1 -0
  27. data/lib/write_xlsx/package/packager.rb +1 -0
  28. data/lib/write_xlsx/package/relationships.rb +1 -0
  29. data/lib/write_xlsx/package/shared_strings.rb +1 -1
  30. data/lib/write_xlsx/package/styles.rb +1 -0
  31. data/lib/write_xlsx/package/table.rb +1 -0
  32. data/lib/write_xlsx/package/theme.rb +1 -0
  33. data/lib/write_xlsx/package/vml.rb +1 -0
  34. data/lib/write_xlsx/package/xml_writer_simple.rb +21 -2
  35. data/lib/write_xlsx/shape.rb +1 -0
  36. data/lib/write_xlsx/sheets.rb +1 -0
  37. data/lib/write_xlsx/sparkline.rb +1 -0
  38. data/lib/write_xlsx/utility.rb +2 -3
  39. data/lib/write_xlsx/version.rb +3 -1
  40. data/lib/write_xlsx/worksheet/cell_data.rb +52 -62
  41. data/lib/write_xlsx/worksheet/data_validation.rb +1 -0
  42. data/lib/write_xlsx/worksheet/hyperlink.rb +3 -2
  43. data/lib/write_xlsx/worksheet/page_setup.rb +1 -0
  44. data/lib/write_xlsx/worksheet.rb +260 -47
  45. data/lib/write_xlsx/zip_file_utils.rb +1 -0
  46. data/lib/write_xlsx.rb +1 -0
  47. data/write_xlsx.gemspec +1 -0
  48. metadata +8 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '080f089bfba0e7182c26bb8fab6d08f7515cbf828bbd358c5166b6fcf3fc689f'
4
- data.tar.gz: 074e380eeace6467f5ab04fa18ad032452b61c82013f3ae5e2254d5eb068c86e
3
+ metadata.gz: 6a6aa71ba6c2a27f86f844a1313cd1983f0b5e54e94fb944b3e2fbf31b089437
4
+ data.tar.gz: 901aadf4eb4bd06ad95377b5d9de33ccc13850299e223453c0e544addcb26a1f
5
5
  SHA512:
6
- metadata.gz: d17f85e3491ed06d5dd39e94c11cdcb6b1abfeda6124143575da1e839d8ca88b8d4bcb06c51a7a94a813c06439c395e209424cf7fd0e1dd9616ed769a3538fc9
7
- data.tar.gz: 112c2336c1bde5435637c6b68e8ae9af98062bc884c1a82b378e8bd0e5d8c5733a23b261a10c8fd5654c4b66ac8bcf765a8ccf1a23887bd70f25634d24d10e17
6
+ metadata.gz: 94101fe3a84563a842fe9989ca162d29aee8dbb1944feb8bd8dbd3c5ee459b3956fb46ccb251ee28e099efd852f9142d3040b5f896b67440e4a5c7b54895d4a9
7
+ data.tar.gz: 8cbd76084fd2276cf02eaff6dc58de57b60b8de991677020aa7634b637f2ec7a0f28b4fb9379483e025572cb5f0cc0070682cfc2eb353b97df118f700e843ae9
data/.rubocop.yml CHANGED
@@ -59,6 +59,7 @@ Metrics/MethodLength:
59
59
 
60
60
  Metrics/ParameterLists:
61
61
  Max: 12
62
+ MaxOptionalParameters: 6
62
63
 
63
64
  Metrics/PerceivedComplexity:
64
65
  Max: 50
data/Changes CHANGED
@@ -1,5 +1,10 @@
1
1
  Change history of write_xlsx rubygem.
2
2
 
3
+ 2023-01-29 v.1.10.0
4
+ Ruby version 2.5.0 or later are required.
5
+
6
+ Added support for new Excel 365 dynamic functions.
7
+
3
8
  2023-01-18 v1.09.5
4
9
  Fixed issue #92. Worksheet#write raises with Time instance token.
5
10
 
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2022 Hideo NAKAMURA
1
+ Copyright (c) 2012-2023 Hideo NAKAMURA
2
2
 
3
3
  MIT License
4
4
 
@@ -22,6 +22,7 @@ worksheet3 = workbook.add_worksheet
22
22
  worksheet4 = workbook.add_worksheet
23
23
  worksheet5 = workbook.add_worksheet
24
24
  worksheet6 = workbook.add_worksheet
25
+ worksheet7 = workbook.add_worksheet
25
26
 
26
27
  bold = workbook.add_format(:bold => 1)
27
28
 
@@ -127,14 +128,12 @@ end
127
128
  ###############################################################################
128
129
  #
129
130
  #
130
- # Example 5. Autofilter with filter for blanks.
131
+ # Example 5. Autofilter with filter list condition in one of the columns.
131
132
  #
132
133
 
133
- # Create a blank cell in our test data.
134
- data[5][0] = ''
135
-
136
134
  worksheet5.autofilter('A1:D51')
137
- worksheet5.filter_column('A', 'x eq Blanks')
135
+
136
+ worksheet5.filter_column_list('A', %w[East North South])
138
137
 
139
138
  #
140
139
  # Hide the rows that don't match the filter criteria.
@@ -144,7 +143,7 @@ row = 1
144
143
  data.each do |row_data|
145
144
  region = row_data[0]
146
145
 
147
- worksheet5.set_row(row, nil, nil, 1) unless region == ''
146
+ worksheet5.set_row(row, nil, nil, 1) unless %w[East North South].include?(region)
148
147
 
149
148
  worksheet5.write(row, 0, row_data)
150
149
  row += 1
@@ -153,11 +152,14 @@ end
153
152
  ###############################################################################
154
153
  #
155
154
  #
156
- # Example 6. Autofilter with filter for non-blanks.
155
+ # Example 6. Autofilter with filter for blanks.
157
156
  #
158
157
 
158
+ # Create a blank cell in our test data.
159
+ data[5][0] = ''
160
+
159
161
  worksheet6.autofilter('A1:D51')
160
- worksheet6.filter_column('A', 'x eq NonBlanks')
162
+ worksheet6.filter_column('A', 'x == Blanks')
161
163
 
162
164
  #
163
165
  # Hide the rows that don't match the filter criteria.
@@ -167,7 +169,7 @@ row = 1
167
169
  data.each do |row_data|
168
170
  region = row_data[0]
169
171
 
170
- worksheet6.set_row(row, nil, nil, 1) unless region != ''
172
+ worksheet6.set_row(row, nil, nil, 1) unless region == ''
171
173
 
172
174
  worksheet6.write(row, 0, row_data)
173
175
  row += 1
@@ -175,6 +177,33 @@ end
175
177
 
176
178
  workbook.close
177
179
 
180
+ ###############################################################################
181
+ #
182
+ #
183
+ # Example 7. Autofilter with filter for non-blanks.
184
+ #
185
+
186
+ worksheet7.autofilter('A1:D51')
187
+ worksheet7.filter_column('A', 'x == NonBlanks')
188
+
189
+ #
190
+ # Hide the rows that don't match the filter criteria.
191
+ #
192
+ row = 1
193
+
194
+ data.each do |row_data|
195
+ region = row_data[0]
196
+
197
+ worksheet7.set_row(row, nil, nil, 1) unless region != ''
198
+
199
+ worksheet7.write(row, 0, row_data)
200
+ row += 1
201
+ end
202
+
203
+ workbook.close
204
+
205
+
206
+
178
207
  __END__
179
208
  Region Item Volume Month
180
209
  East Apple 9000 July
@@ -0,0 +1,247 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # An example of how to use the write_xlsx rubygem to write functions
7
+ # that create dynamic arrays. These functions are new to Excel 365. The
8
+ # examples mirror the examples in the Excel documentation on these functions.
9
+ #
10
+ # Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
11
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
+ #
13
+
14
+ require 'write_xlsx'
15
+
16
+ # Used from test_dynamic_arrays
17
+ # Utility function to write the data some of the functions work on.
18
+ def write_worksheet_data(worksheet, header)
19
+ worksheet.write('A1', 'Region', header)
20
+ worksheet.write('B1', 'Sales Rep', header)
21
+ worksheet.write('C1', 'Product', header)
22
+ worksheet.write('D1', 'Units', header)
23
+
24
+ data = [
25
+ ['East', 'Tom', 'Apple', 6380],
26
+ ['West', 'Fred', 'Grape', 5619],
27
+ ['North', 'Amy', 'Pear', 4565],
28
+ ['South', 'Sal', 'Banana', 5323],
29
+ ['East', 'Fritz', 'Apple', 4394],
30
+ ['West', 'Sravan', 'Grape', 7195],
31
+ ['North', 'Xi', 'Pear', 5231],
32
+ ['South', 'Hector', 'Banana', 2427],
33
+ ['East', 'Tom', 'Banana', 4213],
34
+ ['West', 'Fred', 'Pear', 3239],
35
+ ['North', 'Amy', 'Grape', 6520],
36
+ ['South', 'Sal', 'Apple', 1310],
37
+ ['East', 'Fritz', 'Banana', 6274],
38
+ ['West', 'Sravan', 'Pear', 4894],
39
+ ['North', 'Xi', 'Grape', 7580],
40
+ ['South', 'Hector', 'Apple', 9814]
41
+ ]
42
+
43
+ row_num = 1
44
+ data.each do |row_data|
45
+ worksheet.write_row(row_num, 0, row_data)
46
+ row_num += 1
47
+ end
48
+ end
49
+
50
+ # Create a new workbook called simple.xls and add a worksheet
51
+ workbook = WriteXLSX.new('dynamic_arrays.xlsx')
52
+ worksheet1 = workbook.add_worksheet('Filter')
53
+ worksheet2 = workbook.add_worksheet('Unique')
54
+ worksheet3 = workbook.add_worksheet('Sort')
55
+ worksheet4 = workbook.add_worksheet('Sortby')
56
+ worksheet5 = workbook.add_worksheet('Xlookup')
57
+ worksheet6 = workbook.add_worksheet('Xmatch')
58
+ worksheet7 = workbook.add_worksheet('Randarray')
59
+ worksheet8 = workbook.add_worksheet('Sequence')
60
+ worksheet9 = workbook.add_worksheet('Spill ranges')
61
+ worksheet10 = workbook.add_worksheet('Older functions')
62
+ header1 = workbook.add_format(:fg_color => '#74AC4C', :color => '#FFFFFF')
63
+ header2 = workbook.add_format(:fg_color => '#528FD3', :color => '#FFFFFF')
64
+
65
+ #
66
+ # Example of using the FILTER() function.
67
+ #
68
+ worksheet1.write('F2', '=FILTER(A1:D17,C1:C17=K2)')
69
+
70
+ # Write the data the function will work on.
71
+ worksheet1.write('K1', 'Product', header2)
72
+ worksheet1.write('K2', 'Apple')
73
+ worksheet1.write('F1', 'Region', header2)
74
+ worksheet1.write('G1', 'Sales Rep', header2)
75
+ worksheet1.write('H1', 'Product', header2)
76
+ worksheet1.write('I1', 'Units', header2)
77
+
78
+ write_worksheet_data(worksheet1, header1)
79
+ worksheet1.set_column_pixels('E:E', 20)
80
+ worksheet1.set_column_pixels('J:J', 20)
81
+
82
+ #
83
+ # Example of using the UNIQUE() function.
84
+ #
85
+ worksheet2.write('F2', '=UNIQUE(B2:B17)')
86
+
87
+ # A more complex example combining SORT and UNIQUE.
88
+ worksheet2.write('H2', '=SORT(UNIQUE(B2:B17))')
89
+
90
+ # Write the data the function will work on.
91
+ worksheet2.write('F1', 'Sales Rep', header2)
92
+ worksheet2.write('H1', 'Sales Rep', header2)
93
+
94
+ write_worksheet_data(worksheet2, header1)
95
+ worksheet2.set_column_pixels('E:E', 20)
96
+ worksheet2.set_column_pixels('G:G', 20)
97
+
98
+ #
99
+ # Example of using the SORT() function.
100
+ #
101
+ worksheet3.write('F2', '=SORT(B2:B17)')
102
+
103
+ # A more complex example combining SORT and FILTER.
104
+ worksheet3.write('H2', '=SORT(FILTER(C2:D17,D2:D17>5000,""),2,1)')
105
+
106
+ # Write the data the function will work on.
107
+ worksheet3.write('F1', 'Sales Rep', header2)
108
+ worksheet3.write('H1', 'Product', header2)
109
+ worksheet3.write('I1', 'Units', header2)
110
+
111
+ write_worksheet_data(worksheet3, header1)
112
+ worksheet3.set_column_pixels('E:E', 20)
113
+ worksheet3.set_column_pixels('G:G', 20)
114
+
115
+ #
116
+ # Example of using the SORTBY() function.
117
+ #
118
+ worksheet4.write('D2', '=SORTBY(A2:B9,B2:B9)')
119
+
120
+ # Write the data the function will work on.
121
+ worksheet4.write('A1', 'Name', header1)
122
+ worksheet4.write('B1', 'Age', header1)
123
+
124
+ worksheet4.write('A2', 'Tom')
125
+ worksheet4.write('A3', 'Fred')
126
+ worksheet4.write('A4', 'Amy')
127
+ worksheet4.write('A5', 'Sal')
128
+ worksheet4.write('A6', 'Fritz')
129
+ worksheet4.write('A7', 'Srivan')
130
+ worksheet4.write('A8', 'Xi')
131
+ worksheet4.write('A9', 'Hector')
132
+
133
+ worksheet4.write('B2', 52)
134
+ worksheet4.write('B3', 65)
135
+ worksheet4.write('B4', 22)
136
+ worksheet4.write('B5', 73)
137
+ worksheet4.write('B6', 19)
138
+ worksheet4.write('B7', 39)
139
+ worksheet4.write('B8', 19)
140
+ worksheet4.write('B9', 66)
141
+
142
+ worksheet4.write('D1', 'Name', header2)
143
+ worksheet4.write('E1', 'Age', header2)
144
+
145
+ worksheet4.set_column_pixels('C:C', 20)
146
+
147
+ #
148
+ # Example of using the XLOOKUP() function.
149
+ #
150
+ worksheet5.write('F1', '=XLOOKUP(E1,A2:A9,C2:C9)')
151
+
152
+ # Write the data the function will work on.
153
+ worksheet5.write('A1', 'Country', header1)
154
+ worksheet5.write('B1', 'Abr', header1)
155
+ worksheet5.write('C1', 'Prefix', header1)
156
+
157
+ worksheet5.write('A2', 'China')
158
+ worksheet5.write('A3', 'India')
159
+ worksheet5.write('A4', 'United States')
160
+ worksheet5.write('A5', 'Indonesia')
161
+ worksheet5.write('A6', 'Brazil')
162
+ worksheet5.write('A7', 'Pakistan')
163
+ worksheet5.write('A8', 'Nigeria')
164
+ worksheet5.write('A9', 'Bangladesh')
165
+
166
+ worksheet5.write('B2', 'CN')
167
+ worksheet5.write('B3', 'IN')
168
+ worksheet5.write('B4', 'US')
169
+ worksheet5.write('B5', 'ID')
170
+ worksheet5.write('B6', 'BR')
171
+ worksheet5.write('B7', 'PK')
172
+ worksheet5.write('B8', 'NG')
173
+ worksheet5.write('B9', 'BD')
174
+
175
+ worksheet5.write('C2', 86)
176
+ worksheet5.write('C3', 91)
177
+ worksheet5.write('C4', 1)
178
+ worksheet5.write('C5', 62)
179
+ worksheet5.write('C6', 55)
180
+ worksheet5.write('C7', 92)
181
+ worksheet5.write('C8', 234)
182
+ worksheet5.write('C9', 880)
183
+
184
+ worksheet5.write('E1', 'Brazil', header2)
185
+
186
+ worksheet5.set_column_pixels('A:A', 100)
187
+ worksheet5.set_column_pixels('D:D', 20)
188
+
189
+ #
190
+ # Example of using the XMATCH() function.
191
+ #
192
+ worksheet6.write('D2', '=XMATCH(C2,A2:A6)')
193
+
194
+ # Write the data the function will work on.
195
+ worksheet6.write('A1', 'Product', header1)
196
+
197
+ worksheet6.write('A2', 'Apple')
198
+ worksheet6.write('A3', 'Grape')
199
+ worksheet6.write('A4', 'Pear')
200
+ worksheet6.write('A5', 'Banana')
201
+ worksheet6.write('A6', 'Cherry')
202
+
203
+ worksheet6.write('C1', 'Product', header2)
204
+ worksheet6.write('D1', 'Position', header2)
205
+ worksheet6.write('C2', 'Grape')
206
+
207
+ worksheet6.set_column_pixels('B:B', 20)
208
+
209
+ #
210
+ # Example of using the RANDARRAY() function.
211
+ #
212
+ worksheet7.write('A1', '=RANDARRAY(5,3,1,100, TRUE)')
213
+
214
+ #
215
+ # Example of using the SEQUENCE() function.
216
+ #
217
+ worksheet8.write('A1', '=SEQUENCE(4,5)')
218
+
219
+ #
220
+ # Example of using the Spill range operator.
221
+ #
222
+ worksheet9.write('H2', '=ANCHORARRAY(F2)')
223
+
224
+ worksheet9.write('J2', '=COUNTA(ANCHORARRAY(F2))')
225
+
226
+ # Write the data the to work on.
227
+ worksheet9.write('F2', '=UNIQUE(B2:B17)')
228
+ worksheet9.write('F1', 'Unique', header2)
229
+ worksheet9.write('H1', 'Spill', header2)
230
+ worksheet9.write('J1', 'Spill', header2)
231
+
232
+ write_worksheet_data(worksheet9, header1)
233
+ worksheet9.set_column_pixels('E:E', 20)
234
+ worksheet9.set_column_pixels('G:G', 20)
235
+ worksheet9.set_column_pixels('I:I', 20)
236
+ #
237
+ # Example of using dynamic ranges with older Excel functions.
238
+ #
239
+ worksheet10.write_dynamic_array_formula('B1:B3', '=LEN(A1:A3)')
240
+
241
+ # Write the data the to work on.
242
+ worksheet10.write('A1', 'Foo')
243
+ worksheet10.write('A2', 'Food')
244
+ worksheet10.write('A3', 'Frood')
245
+
246
+ # Close the workbook.
247
+ workbook.close
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # An example of using the new Excel LAMBDA() function with the
7
+ # WriteXLSX rubygem. Note, this function is only currently available
8
+ # if you are subscribed to the Microsoft Office Beta program.
9
+ #
10
+ # Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
11
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
+ #
13
+
14
+ require 'write_xlsx'
15
+
16
+ workbook = WriteXLSX.new('lambda.xlsx')
17
+ worksheet = workbook.add_worksheet
18
+
19
+ worksheet.write(
20
+ 'A1',
21
+ 'Note: Lambda functions currently only work with the Beta Channel versions of Excel 365'
22
+ )
23
+
24
+ # Write a Lambda function to convert Fahrenheit to Celsius to a cell.
25
+ #
26
+ # Note that the lambda function parameters must be prefixed with
27
+ # "_xlpm.". These prefixes won't show up in Excel.
28
+ worksheet.write('A2', '=LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))(32)')
29
+
30
+ # Create the same formula (without an argument) as a defined name and use that
31
+ # to calculate a value.
32
+ #
33
+ # Note that the formula name is prefixed with "_xlfn." (this is normally
34
+ # converted automatically by write_formula but isn't for defined names)
35
+ # and note that the lambda function parameters are prefixed with
36
+ # "_xlpm.". These prefixes won't show up in Excel.
37
+ workbook.define_name(
38
+ 'ToCelsius',
39
+ '=_xlfn.LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))'
40
+ )
41
+ worksheet.write_dynamic_array_formula('A3', '=ToCelsius(212)')
42
+
43
+ workbook.close
Binary file
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #######################################################################
4
+ #
5
+ # An example of adding a worksheet watermark image using the WriteXLSX
6
+ # rubygem. This is based on the method of putting an image in the worksheet
7
+ # header as suggested in the Microsoft documentation:
8
+ # https://support.microsoft.com/en-us/office/add-a-watermark-in-excel-a372182a-d733-484e-825c-18ddf3edf009
9
+ #
10
+ # Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
11
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
+ #
13
+
14
+ require 'write_xlsx'
15
+
16
+ workbook = WriteXLSX.new('watermark.xlsx')
17
+ worksheet = workbook.add_worksheet
18
+
19
+ # Set a worksheet header with the watermark image.
20
+ dirname = File.dirname(File.expand_path(__FILE__))
21
+ worksheet.set_header(
22
+ '&C&C&[Picture]', nil,
23
+ { :image_center => File.join(dirname, 'watermark.png') }
24
+ )
25
+
26
+ workbook.close
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/gradient'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'singleton'
4
5
 
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Writexlsx
4
5
  class Colors
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  #
4
5
  # Why would we ever use Ruby 1.8.7 when we can backport with something
@@ -1,24 +1,26 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
5
6
 
6
7
  module Writexlsx
7
8
  class Drawing
8
- attr_accessor :type, :dimensions, :width, :height, :description, :shape, :anchor, :rel_index, :url_rel_index
9
+ attr_accessor :type, :dimensions, :width, :height, :shape, :anchor, :rel_index, :url_rel_index, :name, :description
9
10
  attr_reader :tip, :decorative
10
11
 
11
- def initialize(type, dimensions, width, height, description, shape, anchor, rel_index = nil, url_rel_index = nil, tip = nil, decorative = nil)
12
+ def initialize(type, dimensions, width, height, shape, anchor, rel_index = nil, url_rel_index = nil, tip = nil, name = nil, description = nil, decorative = nil)
12
13
  @type = type
13
14
  @dimensions = dimensions
14
15
  @width = width
15
16
  @height = height
16
- @description = description
17
17
  @shape = shape
18
18
  @anchor = anchor
19
19
  @rel_index = rel_index
20
20
  @url_rel_index = url_rel_index
21
21
  @tip = tip
22
+ @name = name
23
+ @description = description
22
24
  @decorative = decorative
23
25
  end
24
26
  end
@@ -96,12 +98,13 @@ module Writexlsx
96
98
  type = drawing.type
97
99
  width = drawing.width
98
100
  height = drawing.height
99
- description = drawing.description
100
101
  shape = drawing.shape
101
102
  anchor = drawing.anchor
102
103
  rel_index = drawing.rel_index
103
104
  url_rel_index = drawing.url_rel_index
104
105
  tip = drawing.tip
106
+ name = drawing.name
107
+ description = drawing.description
105
108
  decorative = drawing.decorative
106
109
 
107
110
  col_from, row_from, col_from_offset, row_from_offset,
@@ -129,7 +132,7 @@ module Writexlsx
129
132
  # Graphic frame.
130
133
 
131
134
  # Write the xdr:graphicFrame element for charts.
132
- write_graphic_frame(index, rel_index, description)
135
+ write_graphic_frame(index, rel_index, name, description, decorative)
133
136
  elsif type == 2
134
137
  # Write the xdr:pic element.
135
138
  write_pic(
@@ -263,14 +266,17 @@ module Writexlsx
263
266
  #
264
267
  # Write the <xdr:graphicFrame> element.
265
268
  #
266
- def write_graphic_frame(index, rel_index, name = nil)
267
- macro = ''
269
+ def write_graphic_frame(
270
+ index, rel_index, name = nil,
271
+ description = nil, decorative = nil, macro = nil
272
+ )
273
+ macro ||= ''
268
274
 
269
275
  attributes = [['macro', macro]]
270
276
 
271
277
  @writer.tag_elements('xdr:graphicFrame', attributes) do
272
278
  # Write the xdr:nvGraphicFramePr element.
273
- write_nv_graphic_frame_pr(index, name)
279
+ write_nv_graphic_frame_pr(index, name, description, decorative)
274
280
  # Write the xdr:xfrm element.
275
281
  write_xfrm
276
282
  # Write the a:graphic element.
@@ -281,12 +287,16 @@ module Writexlsx
281
287
  #
282
288
  # Write the <xdr:nvGraphicFramePr> element.
283
289
  #
284
- def write_nv_graphic_frame_pr(index, name = nil)
290
+ def write_nv_graphic_frame_pr(
291
+ index, name = nil, description = nil, decorative = nil
292
+ )
293
+
285
294
  name = "Chart #{index}" unless ptrue?(name)
286
295
 
287
296
  @writer.tag_elements('xdr:nvGraphicFramePr') do
288
297
  # Write the xdr:cNvPr element.
289
- write_c_nv_pr(index + 1, name)
298
+ write_c_nv_pr(index + 1, name, description,
299
+ nil, nil, decorative)
290
300
  # Write the xdr:cNvGraphicFramePr element.
291
301
  write_c_nv_graphic_frame_pr
292
302
  end
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/utility'
4
5
 
@@ -658,6 +659,10 @@ module Writexlsx
658
659
  attributes
659
660
  end
660
661
 
662
+ def force_text_format?
663
+ @num_format == 49 # Text format ('@')
664
+ end
665
+
661
666
  private
662
667
 
663
668
  def write_font_shapes(writer)
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Writexlsx
2
4
  module Gradient
3
5
  def gradient_properties(args)
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/utility'
4
5
 
@@ -7,10 +8,13 @@ module Writexlsx
7
8
  class Button
8
9
  include Writexlsx::Utility
9
10
 
10
- attr_accessor :font, :macro, :vertices
11
+ attr_accessor :font, :macro, :vertices, :description
11
12
 
12
13
  def v_shape_attributes(id, z_index)
13
- attributes = v_shape_attributes_base(id, z_index)
14
+ attributes = v_shape_attributes_base(id)
15
+ attributes << ['alt', description] if description
16
+
17
+ attributes << ['style', (v_shape_style_base(z_index, vertices) + style_addition).join]
14
18
  attributes << ['o:button', 't']
15
19
  attributes << ['fillcolor', color]
16
20
  attributes << ['strokecolor', 'windowText [64]']
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/format'
4
5
  require 'write_xlsx/package/xml_writer_simple'
@@ -112,7 +113,8 @@ module Writexlsx
112
113
  end
113
114
 
114
115
  def v_shape_attributes(id, z_index)
115
- attr = v_shape_attributes_base(id, z_index)
116
+ attr = v_shape_attributes_base(id)
117
+ attr << ['style', (v_shape_style_base(z_index, vertices) + style_addition).join]
116
118
  attr << ['fillcolor', color]
117
119
  attr << ['o:insetmode', 'auto']
118
120
  attr
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Writexlsx
4
5
  module Package
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'