Skip to content

Commit

Permalink
wip: initial embed_image() structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcnamara committed Feb 14, 2024
1 parent 24563bc commit 238943a
Show file tree
Hide file tree
Showing 14 changed files with 1,588 additions and 302 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ TAGS
*#
~*xlsx
*.bak
.vscode

32 changes: 32 additions & 0 deletions lib/Excel/Writer/XLSX/Package/ContentTypes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,38 @@ sub _add_metadata {
}


###############################################################################
#
# _add_richvalue()
#
# Add the RichValue files to the ContentTypes overrides.
#
sub _add_richvalue {

my $self = shift;

$self->_add_override(
'/xl/richData/rdRichValueTypes.xml',
'application/vnd.ms-excel.rdrichvaluetypes+xml'
);

$self->_add_override(
'/xl/richData/rdrichvalue.xml',
'application/vnd.ms-excel.rdrichvalue+xml'
);

$self->_add_override(
'/xl/richData/rdrichvaluestructure.xml',
'application/vnd.ms-excel.rdrichvaluestructure+xml'
);

$self->_add_override(
'/xl/richData/richValueRel.xml',
'application/vnd.ms-excel.richvaluerel+xml'
);
}


###############################################################################
#
# Internal methods.
Expand Down
191 changes: 169 additions & 22 deletions lib/Excel/Writer/XLSX/Package/Metadata.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ sub new {
my $fh = shift;
my $self = Excel::Writer::XLSX::Package::XMLwriter->new( $fh );

$self->{_cell_metadata} = 0;
$self->{_value_metadata} = 0;

bless $self, $class;

return $self;
Expand All @@ -69,10 +72,12 @@ sub _assemble_xml_file {
$self->_write_metadata_types();

# Write the futureMetadata element.
$self->_write_future_metadata();
$self->_write_cell_future_metadata() if $self->{_cell_metadata};
$self->_write_value_future_metadata() if $self->{_value_metadata};

# Write the cellMetadata element.
$self->_write_cell_metadata();
# Write the valueMetadata element.
$self->_write_cell_metadata() if $self->{_cell_metadata};
$self->_write_value_metadata() if $self->{_value_metadata};

$self->xml_end_tag( 'metadata' );

Expand All @@ -96,16 +101,30 @@ sub _assemble_xml_file {
#
sub _write_metadata {

my $self = shift;
my $xmlns = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main';
my $xmlns_xda =
'http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray';
my $self = shift;

my @attributes = (
'xmlns' => $xmlns,
'xmlns:xda' => $xmlns_xda,
'xmlns' =>
'http://schemas.openxmlformats.org/spreadsheetml/2006/main'
);


if ( $self->{_value_metadata} ) {
push @attributes,
(
'xmlns:xlrd' =>
'http://schemas.microsoft.com/office/spreadsheetml/2017/richdata'
);
}

if ( $self->{_cell_metadata} ) {
push @attributes,
(
'xmlns:xda' =>
'http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray'
);
}

$self->xml_start_tag( 'metadata', @attributes );
}

Expand All @@ -118,26 +137,30 @@ sub _write_metadata {
#
sub _write_metadata_types {

my $self = shift;
my $self = shift;
my $count = $self->{_cell_metadata} + $self->{_value_metadata};

my @attributes = ( 'count' => 1 );
my @attributes = ( 'count' => $count );

$self->xml_start_tag( 'metadataTypes', @attributes );

# Write the metadataType element.
$self->_write_metadata_type();
# Write the Cell Metadata element.
$self->_write_cell_metadata_type() if $self->{_cell_metadata};

# Write the Vell Metadata element.
$self->_write_value_metadata_type() if $self->{_value_metadata};

$self->xml_end_tag( 'metadataTypes' );
}


##############################################################################
#
# _write_metadata_type()
# _write_cell_metadata_type()
#
# Write the <metadataType> element.
#
sub _write_metadata_type {
sub _write_cell_metadata_type {

my $self = shift;

Expand All @@ -163,11 +186,40 @@ sub _write_metadata_type {

##############################################################################
#
# _write_future_metadata()
# _write_value_metadata_type()
#
# Write the <metadataType> element.
#
sub _write_value_metadata_type {

my $self = shift;

my @attributes = (
'name' => 'XLRICHVALUE',
'minSupportedVersion' => 120000,
'copy' => 1,
'pasteAll' => 1,
'pasteValues' => 1,
'merge' => 1,
'splitFirst' => 1,
'rowColShift' => 1,
'clearFormats' => 1,
'clearComments' => 1,
'assign' => 1,
'coerce' => 1,
);

$self->xml_empty_tag( 'metadataType', @attributes );
}


##############################################################################
#
# _write_cell_future_metadata()
#
# Write the <futureMetadata> element.
#
sub _write_future_metadata {
sub _write_cell_future_metadata {

my $self = shift;

Expand All @@ -181,7 +233,7 @@ sub _write_future_metadata {
$self->xml_start_tag( 'extLst' );

# Write the ext element.
$self->_write_ext();
$self->_write_cell_ext();

$self->xml_end_tag( 'ext' );
$self->xml_end_tag( 'extLst' );
Expand All @@ -193,13 +245,44 @@ sub _write_future_metadata {

##############################################################################
#
# _write_ext()
# _write_value_future_metadata()
#
# Write the <futureMetadata> element.
#
sub _write_value_future_metadata {

my $self = shift;

my @attributes = (
'name' => 'XLRICHVALUE',
'count' => 1,
);

$self->xml_start_tag( 'futureMetadata', @attributes );
$self->xml_start_tag( 'bk' );
$self->xml_start_tag( 'extLst' );

# Write the ext element.
$self->_write_value_ext();

$self->xml_end_tag( 'ext' );
$self->xml_end_tag( 'extLst' );
$self->xml_end_tag( 'bk' );

$self->xml_end_tag( 'futureMetadata' );
}


##############################################################################
#
# _write_cell_ext()
#
# Write the <ext> element.
#
sub _write_ext {
sub _write_cell_ext {

my $self = shift;
my $uri = shift;

my @attributes = ( 'uri' => '{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}' );

Expand All @@ -210,6 +293,25 @@ sub _write_ext {
}


##############################################################################
#
# _write_value_ext()
#
# Write the <ext> element.
#
sub _write_value_ext {

my $self = shift;
my $uri = shift;

my @attributes = ( 'uri' => '{3e2802c4-a4d2-4d8b-9148-e3be6c30e623}' );

$self->xml_start_tag( 'ext', @attributes );

# Write the <xlrd:rvb> element.
$self->_write_xlrd_rvb();
}

##############################################################################
#
# _write_xda_dynamic_array_properties()
Expand Down Expand Up @@ -246,13 +348,38 @@ sub _write_cell_metadata {
$self->xml_start_tag( 'bk' );

# Write the rc element.
$self->_write_rc();
$self->_write_rc(0);

$self->xml_end_tag( 'bk' );
$self->xml_end_tag( 'cellMetadata' );
}


##############################################################################
#
# _write_value_metadata()
#
# Write the <valueMetadata> element.
#
sub _write_value_metadata {

my $self = shift;
my $count = $self->{_value_metadata};

my @attributes = ( 'count' => $count, );

$self->xml_start_tag( 'valueMetadata', @attributes );
$self->xml_start_tag( 'bk' );

# Write the rc element.
$self->_write_rc(0);


$self->xml_end_tag( 'bk' );
$self->xml_end_tag( 'valueMetadata' );
}


##############################################################################
#
# _write_rc()
Expand All @@ -261,7 +388,8 @@ sub _write_cell_metadata {
#
sub _write_rc {

my $self = shift;
my $self = shift;
my $value = shift;

my @attributes = (
't' => 1,
Expand All @@ -272,6 +400,24 @@ sub _write_rc {
}


##############################################################################
#
# _write_xlrd_rvb()
#
# Write the <xlrd:rvb> element.
#
sub _write_xlrd_rvb {

my $self = shift;
my $value = 0;

my @attributes = ( 'i' => $value, );

$self->xml_empty_tag( 'xlrd:rvb', @attributes );
}



1;


Expand All @@ -297,6 +443,7 @@ John McNamara jmcnamara@cpan.org
=head1 COPYRIGHT
(c) MM-MMXXIII, John McNamara.
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
Expand Down
Loading

0 comments on commit 238943a

Please sign in to comment.