@@ -44,6 +44,10 @@ sub new {
44
44
my $fh = shift ;
45
45
my $self = Excel::Writer::XLSX::Package::XMLwriter-> new( $fh );
46
46
47
+ $self -> {_has_dynamic_functions } = 0;
48
+ $self -> {_has_embedded_images } = 0;
49
+ $self -> {_num_embedded_images } = 0;
50
+
47
51
bless $self , $class ;
48
52
49
53
return $self ;
@@ -60,6 +64,10 @@ sub _assemble_xml_file {
60
64
61
65
my $self = shift ;
62
66
67
+ if ( $self -> {_num_embedded_images } > 0 ) {
68
+ $self -> {_has_embedded_images } = 1;
69
+ }
70
+
63
71
$self -> xml_declaration;
64
72
65
73
# Write the metadata element.
@@ -69,10 +77,12 @@ sub _assemble_xml_file {
69
77
$self -> _write_metadata_types();
70
78
71
79
# Write the futureMetadata element.
72
- $self -> _write_future_metadata();
80
+ $self -> _write_cell_future_metadata() if $self -> {_has_dynamic_functions };
81
+ $self -> _write_value_future_metadata() if $self -> {_has_embedded_images };
73
82
74
- # Write the cellMetadata element.
75
- $self -> _write_cell_metadata();
83
+ # Write the valueMetadata element.
84
+ $self -> _write_cell_metadata() if $self -> {_has_dynamic_functions };
85
+ $self -> _write_value_metadata() if $self -> {_has_embedded_images };
76
86
77
87
$self -> xml_end_tag( ' metadata' );
78
88
@@ -96,16 +106,30 @@ sub _assemble_xml_file {
96
106
#
97
107
sub _write_metadata {
98
108
99
- my $self = shift ;
100
- my $xmlns = ' http://schemas.openxmlformats.org/spreadsheetml/2006/main' ;
101
- my $xmlns_xda =
102
- ' http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray' ;
109
+ my $self = shift ;
103
110
104
111
my @attributes = (
105
- ' xmlns' => $xmlns ,
106
- ' xmlns:xda ' => $xmlns_xda ,
112
+ ' xmlns' =>
113
+ ' http://schemas.openxmlformats.org/spreadsheetml/2006/main '
107
114
);
108
115
116
+
117
+ if ( $self -> {_has_embedded_images } ) {
118
+ push @attributes ,
119
+ (
120
+ ' xmlns:xlrd' =>
121
+ ' http://schemas.microsoft.com/office/spreadsheetml/2017/richdata'
122
+ );
123
+ }
124
+
125
+ if ( $self -> {_has_dynamic_functions } ) {
126
+ push @attributes ,
127
+ (
128
+ ' xmlns:xda' =>
129
+ ' http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray'
130
+ );
131
+ }
132
+
109
133
$self -> xml_start_tag( ' metadata' , @attributes );
110
134
}
111
135
@@ -119,25 +143,27 @@ sub _write_metadata {
119
143
sub _write_metadata_types {
120
144
121
145
my $self = shift ;
146
+ my $count = $self -> {_has_dynamic_functions } + $self -> {_has_embedded_images };
122
147
123
- my @attributes = ( ' count' => 1 );
148
+ my @attributes = ( ' count' => $count );
124
149
125
150
$self -> xml_start_tag( ' metadataTypes' , @attributes );
126
151
127
152
# Write the metadataType element.
128
- $self -> _write_metadata_type();
153
+ $self -> _write_cell_metadata_type() if $self -> {_has_dynamic_functions };
154
+ $self -> _write_value_metadata_type() if $self -> {_has_embedded_images };
129
155
130
156
$self -> xml_end_tag( ' metadataTypes' );
131
157
}
132
158
133
159
134
160
# #############################################################################
135
161
#
136
- # _write_metadata_type ()
162
+ # _write_cell_metadata_type ()
137
163
#
138
164
# Write the <metadataType> element.
139
165
#
140
- sub _write_metadata_type {
166
+ sub _write_cell_metadata_type {
141
167
142
168
my $self = shift ;
143
169
@@ -163,11 +189,40 @@ sub _write_metadata_type {
163
189
164
190
# #############################################################################
165
191
#
166
- # _write_future_metadata()
192
+ # _write_value_metadata_type()
193
+ #
194
+ # Write the <metadataType> element.
195
+ #
196
+ sub _write_value_metadata_type {
197
+
198
+ my $self = shift ;
199
+
200
+ my @attributes = (
201
+ ' name' => ' XLRICHVALUE' ,
202
+ ' minSupportedVersion' => 120000,
203
+ ' copy' => 1,
204
+ ' pasteAll' => 1,
205
+ ' pasteValues' => 1,
206
+ ' merge' => 1,
207
+ ' splitFirst' => 1,
208
+ ' rowColShift' => 1,
209
+ ' clearFormats' => 1,
210
+ ' clearComments' => 1,
211
+ ' assign' => 1,
212
+ ' coerce' => 1,
213
+ );
214
+
215
+ $self -> xml_empty_tag( ' metadataType' , @attributes );
216
+ }
217
+
218
+
219
+ # #############################################################################
220
+ #
221
+ # _write_cell_future_metadata()
167
222
#
168
223
# Write the <futureMetadata> element.
169
224
#
170
- sub _write_future_metadata {
225
+ sub _write_cell_future_metadata {
171
226
172
227
my $self = shift ;
173
228
@@ -181,7 +236,7 @@ sub _write_future_metadata {
181
236
$self -> xml_start_tag( ' extLst' );
182
237
183
238
# Write the ext element.
184
- $self -> _write_ext ();
239
+ $self -> _write_cell_ext ();
185
240
186
241
$self -> xml_end_tag( ' ext' );
187
242
$self -> xml_end_tag( ' extLst' );
@@ -193,13 +248,48 @@ sub _write_future_metadata {
193
248
194
249
# #############################################################################
195
250
#
196
- # _write_ext()
251
+ # _write_value_future_metadata()
252
+ #
253
+ # Write the <futureMetadata> element.
254
+ #
255
+ sub _write_value_future_metadata {
256
+
257
+ my $self = shift ;
258
+ my $num_images = $self -> {_num_embedded_images };
259
+
260
+ my @attributes = (
261
+ ' name' => ' XLRICHVALUE' ,
262
+ ' count' => $num_images ,
263
+ );
264
+
265
+ $self -> xml_start_tag( ' futureMetadata' , @attributes );
266
+
267
+ for my $i ( 0 .. $num_images - 1 ) {
268
+ $self -> xml_start_tag( ' bk' );
269
+ $self -> xml_start_tag( ' extLst' );
270
+
271
+ # Write the ext element.
272
+ $self -> _write_value_ext( $i );
273
+
274
+ $self -> xml_end_tag( ' ext' );
275
+ $self -> xml_end_tag( ' extLst' );
276
+ $self -> xml_end_tag( ' bk' );
277
+ }
278
+
279
+ $self -> xml_end_tag( ' futureMetadata' );
280
+ }
281
+
282
+
283
+ # #############################################################################
284
+ #
285
+ # _write_cell_ext()
197
286
#
198
287
# Write the <ext> element.
199
288
#
200
- sub _write_ext {
289
+ sub _write_cell_ext {
201
290
202
291
my $self = shift ;
292
+ my $uri = shift ;
203
293
204
294
my @attributes = ( ' uri' => ' {bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}' );
205
295
@@ -210,6 +300,25 @@ sub _write_ext {
210
300
}
211
301
212
302
303
+ # #############################################################################
304
+ #
305
+ # _write_value_ext()
306
+ #
307
+ # Write the <ext> element.
308
+ #
309
+ sub _write_value_ext {
310
+
311
+ my $self = shift ;
312
+ my $num = shift ;
313
+
314
+ my @attributes = ( ' uri' => ' {3e2802c4-a4d2-4d8b-9148-e3be6c30e623}' );
315
+
316
+ $self -> xml_start_tag( ' ext' , @attributes );
317
+
318
+ # Write the <xlrd:rvb> element.
319
+ $self -> _write_xlrd_rvb( $num );
320
+ }
321
+
213
322
# #############################################################################
214
323
#
215
324
# _write_xda_dynamic_array_properties()
@@ -246,13 +355,45 @@ sub _write_cell_metadata {
246
355
$self -> xml_start_tag( ' bk' );
247
356
248
357
# Write the rc element.
249
- $self -> _write_rc();
358
+ $self -> _write_rc(1, 0 );
250
359
251
360
$self -> xml_end_tag( ' bk' );
252
361
$self -> xml_end_tag( ' cellMetadata' );
253
362
}
254
363
255
364
365
+ # #############################################################################
366
+ #
367
+ # _write_value_metadata()
368
+ #
369
+ # Write the <valueMetadata> element.
370
+ #
371
+ sub _write_value_metadata {
372
+
373
+ my $self = shift ;
374
+ my $count = $self -> {_num_embedded_images };
375
+ my $type = 1;
376
+
377
+ if ($self -> {_has_dynamic_functions }) {
378
+ $type = 2;
379
+ }
380
+ my @attributes = ( ' count' => $count , );
381
+
382
+ $self -> xml_start_tag( ' valueMetadata' , @attributes );
383
+
384
+ for my $i ( 0 .. $count - 1 ) {
385
+ $self -> xml_start_tag( ' bk' );
386
+
387
+ # Write the rc element.
388
+ $self -> _write_rc( $type , $i );
389
+
390
+ $self -> xml_end_tag( ' bk' );
391
+ }
392
+
393
+ $self -> xml_end_tag( ' valueMetadata' );
394
+ }
395
+
396
+
256
397
# #############################################################################
257
398
#
258
399
# _write_rc()
@@ -261,17 +402,36 @@ sub _write_cell_metadata {
261
402
#
262
403
sub _write_rc {
263
404
264
- my $self = shift ;
405
+ my $self = shift ;
406
+ my $type = shift ;
407
+ my $value = shift ;
265
408
266
409
my @attributes = (
267
- ' t' => 1 ,
268
- ' v' => 0 ,
410
+ ' t' => $type ,
411
+ ' v' => $value ,
269
412
);
270
413
271
414
$self -> xml_empty_tag( ' rc' , @attributes );
272
415
}
273
416
274
417
418
+ # #############################################################################
419
+ #
420
+ # _write_xlrd_rvb()
421
+ #
422
+ # Write the <xlrd:rvb> element.
423
+ #
424
+ sub _write_xlrd_rvb {
425
+
426
+ my $self = shift ;
427
+ my $value = shift ;
428
+
429
+ my @attributes = ( ' i' => $value , );
430
+
431
+ $self -> xml_empty_tag( ' xlrd:rvb' , @attributes );
432
+ }
433
+
434
+
275
435
1;
276
436
277
437
297
457
298
458
=head1 COPYRIGHT
299
459
460
+
300
461
(c) MM-MMXXIII, John McNamara.
301
462
302
463
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
0 commit comments