From 9e3a2c2dff53f9889381e40ba5a9825875d7db50 Mon Sep 17 00:00:00 2001 From: John McNamara Date: Fri, 16 Feb 2024 00:06:28 +0000 Subject: [PATCH] wip: working embed_image() with dynamic functions --- lib/Excel/Writer/XLSX/Package/Metadata.pm | 11 +++- t/regression/embed_image05.t | 71 +++++++++++++++++++++ t/regression/xlsx_files/embed_image05.xlsx | Bin 0 -> 8763 bytes 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 t/regression/embed_image05.t create mode 100644 t/regression/xlsx_files/embed_image05.xlsx diff --git a/lib/Excel/Writer/XLSX/Package/Metadata.pm b/lib/Excel/Writer/XLSX/Package/Metadata.pm index 563fcc77..aa27f424 100644 --- a/lib/Excel/Writer/XLSX/Package/Metadata.pm +++ b/lib/Excel/Writer/XLSX/Package/Metadata.pm @@ -355,7 +355,7 @@ sub _write_cell_metadata { $self->xml_start_tag( 'bk' ); # Write the rc element. - $self->_write_rc(0); + $self->_write_rc(1, 0); $self->xml_end_tag( 'bk' ); $self->xml_end_tag( 'cellMetadata' ); @@ -372,7 +372,11 @@ sub _write_value_metadata { my $self = shift; my $count = $self->{_num_embedded_images}; + my $type = 1; + if ($self->{_has_dynamic_functions}) { + $type = 2; + } my @attributes = ( 'count' => $count, ); $self->xml_start_tag( 'valueMetadata', @attributes ); @@ -381,7 +385,7 @@ sub _write_value_metadata { $self->xml_start_tag( 'bk' ); # Write the rc element. - $self->_write_rc( $i ); + $self->_write_rc( $type, $i ); $self->xml_end_tag( 'bk' ); } @@ -399,10 +403,11 @@ sub _write_value_metadata { sub _write_rc { my $self = shift; + my $type = shift; my $value = shift; my @attributes = ( - 't' => 1, + 't' => $type, 'v' => $value, ); diff --git a/t/regression/embed_image05.t b/t/regression/embed_image05.t new file mode 100644 index 00000000..46f5437f --- /dev/null +++ b/t/regression/embed_image05.t @@ -0,0 +1,71 @@ +############################################################################### +# +# Tests the output of Excel::Writer::XLSX against Excel generated files. +# +# Copyright 2000-2023, John McNamara, jmcnamara@cpan.org +# +# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later +# + +use lib 't/lib'; +use TestFunctions qw(_compare_xlsx_files _is_deep_diff); +use strict; +use warnings; + +use Test::More tests => 1; + +############################################################################### +# +# Tests setup. +# +my $filename = 'embed_image05.xlsx'; +my $dir = 't/regression/'; +my $got_filename = $dir . "ewx_$filename"; +my $exp_filename = $dir . 'xlsx_files/' . $filename; + +my $ignore_members = []; +my $ignore_elements = {}; + + +############################################################################### +# +# Test the creation of a simple Excel::Writer::XLSX file with image(s). +# +use Excel::Writer::XLSX; + +my $workbook = Excel::Writer::XLSX->new( $got_filename ); +my $worksheet = $workbook->add_worksheet(); + +$worksheet->write_dynamic_array_formula( 0, 0, 2, 0, '=LEN(B1:B3)', undef, 0 ); + +$worksheet->embed_image( 8, 4, $dir . 'images/red.png' ); + +$workbook->close(); + + +############################################################################### +# +# Compare the generated and existing Excel files. +# + +my ( $got, $expected, $caption ) = _compare_xlsx_files( + + $got_filename, + $exp_filename, + $ignore_members, + $ignore_elements, +); + +_is_deep_diff( $got, $expected, $caption ); + + +############################################################################### +# +# Cleanup. +# +unlink $got_filename; + +__END__ + + + diff --git a/t/regression/xlsx_files/embed_image05.xlsx b/t/regression/xlsx_files/embed_image05.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..5430cdc4f91c8d0d46d117a57694b6e57c8942c3 GIT binary patch literal 8763 zcma)iby!sG^ZpXjNJw|*A}t}(y_AHsSzJEMt&)MtRd#*G0JTvp$vnn72L_7chfC3<_Q`V9&^hnNt0{{Y%0DxNnGJvjx zy`2l#&c#68(*f+Pf7`>>MnfGHfIyzn4`zZbR}XXm9O6Fg7vDhMB!HBcIPiiGX}?g? z*xz4lfzP_HM$p=82cUjdUv5uY^0>Q!d8=`C%11U3O|fXAEzD=&INE@C4p>@5fE|DE z3QX7+sxhCdIn}3gaJE;_V5T9ykiY>I>v<46(YL(Wd1Q%CrIG7a1SU5=>h_Ey*Lq4q z+4P}nM20n1c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