Skip to content

Commit

Permalink
wip: working embed_image() with dynamic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcnamara committed Feb 16, 2024
1 parent 8cf8731 commit 9e3a2c2
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/Excel/Writer/XLSX/Package/Metadata.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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 );
Expand All @@ -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' );
}
Expand All @@ -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,
);

Expand Down
71 changes: 71 additions & 0 deletions t/regression/embed_image05.t
Original file line number Diff line number Diff line change
@@ -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__
Binary file added t/regression/xlsx_files/embed_image05.xlsx
Binary file not shown.

0 comments on commit 9e3a2c2

Please sign in to comment.