use
5.008002;
our
@ISA
=
qw(Excel::Writer::XLSX::Package::XMLwriter)
;
our
$VERSION
=
'1.14'
;
sub
new {
my
$class
=
shift
;
my
$fh
=
shift
;
my
$self
= Excel::Writer::XLSX::Package::XMLwriter->new(
$fh
);
$self
->{_has_dynamic_functions} = 0;
$self
->{_has_embedded_images} = 0;
$self
->{_num_embedded_images} = 0;
bless
$self
,
$class
;
return
$self
;
}
sub
_assemble_xml_file {
my
$self
=
shift
;
if
(
$self
->{_num_embedded_images} > 0 ) {
$self
->{_has_embedded_images} = 1;
}
$self
->xml_declaration;
$self
->_write_metadata();
$self
->_write_metadata_types();
$self
->_write_cell_future_metadata()
if
$self
->{_has_dynamic_functions};
$self
->_write_value_future_metadata()
if
$self
->{_has_embedded_images};
$self
->_write_cell_metadata()
if
$self
->{_has_dynamic_functions};
$self
->_write_value_metadata()
if
$self
->{_has_embedded_images};
$self
->xml_end_tag(
'metadata'
);
$self
->xml_get_fh()->
close
();
}
sub
_write_metadata {
my
$self
=
shift
;
my
@attributes
= (
'xmlns'
=>
);
if
(
$self
->{_has_embedded_images} ) {
push
@attributes
,
(
'xmlns:xlrd'
=>
);
}
if
(
$self
->{_has_dynamic_functions} ) {
push
@attributes
,
(
'xmlns:xda'
=>
);
}
$self
->xml_start_tag(
'metadata'
,
@attributes
);
}
sub
_write_metadata_types {
my
$self
=
shift
;
my
$count
=
$self
->{_has_dynamic_functions} +
$self
->{_has_embedded_images};
my
@attributes
= (
'count'
=>
$count
);
$self
->xml_start_tag(
'metadataTypes'
,
@attributes
);
$self
->_write_cell_metadata_type()
if
$self
->{_has_dynamic_functions};
$self
->_write_value_metadata_type()
if
$self
->{_has_embedded_images};
$self
->xml_end_tag(
'metadataTypes'
);
}
sub
_write_cell_metadata_type {
my
$self
=
shift
;
my
@attributes
= (
'name'
=>
'XLDAPR'
,
'minSupportedVersion'
=> 120000,
'copy'
=> 1,
'pasteAll'
=> 1,
'pasteValues'
=> 1,
'merge'
=> 1,
'splitFirst'
=> 1,
'rowColShift'
=> 1,
'clearFormats'
=> 1,
'clearComments'
=> 1,
'assign'
=> 1,
'coerce'
=> 1,
'cellMeta'
=> 1,
);
$self
->xml_empty_tag(
'metadataType'
,
@attributes
);
}
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
);
}
sub
_write_cell_future_metadata {
my
$self
=
shift
;
my
@attributes
= (
'name'
=>
'XLDAPR'
,
'count'
=> 1,
);
$self
->xml_start_tag(
'futureMetadata'
,
@attributes
);
$self
->xml_start_tag(
'bk'
);
$self
->xml_start_tag(
'extLst'
);
$self
->_write_cell_ext();
$self
->xml_end_tag(
'ext'
);
$self
->xml_end_tag(
'extLst'
);
$self
->xml_end_tag(
'bk'
);
$self
->xml_end_tag(
'futureMetadata'
);
}
sub
_write_value_future_metadata {
my
$self
=
shift
;
my
$num_images
=
$self
->{_num_embedded_images};
my
@attributes
= (
'name'
=>
'XLRICHVALUE'
,
'count'
=>
$num_images
,
);
$self
->xml_start_tag(
'futureMetadata'
,
@attributes
);
for
my
$i
( 0 ..
$num_images
- 1 ) {
$self
->xml_start_tag(
'bk'
);
$self
->xml_start_tag(
'extLst'
);
$self
->_write_value_ext(
$i
);
$self
->xml_end_tag(
'ext'
);
$self
->xml_end_tag(
'extLst'
);
$self
->xml_end_tag(
'bk'
);
}
$self
->xml_end_tag(
'futureMetadata'
);
}
sub
_write_cell_ext {
my
$self
=
shift
;
my
$uri
=
shift
;
my
@attributes
= (
'uri'
=>
'{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}'
);
$self
->xml_start_tag(
'ext'
,
@attributes
);
$self
->_write_xda_dynamic_array_properties();
}
sub
_write_value_ext {
my
$self
=
shift
;
my
$num
=
shift
;
my
@attributes
= (
'uri'
=>
'{3e2802c4-a4d2-4d8b-9148-e3be6c30e623}'
);
$self
->xml_start_tag(
'ext'
,
@attributes
);
$self
->_write_xlrd_rvb(
$num
);
}
sub
_write_xda_dynamic_array_properties {
my
$self
=
shift
;
my
@attributes
= (
'fDynamic'
=> 1,
'fCollapsed'
=> 0,
);
$self
->xml_empty_tag(
'xda:dynamicArrayProperties'
,
@attributes
);
}
sub
_write_cell_metadata {
my
$self
=
shift
;
my
$count
= 1;
my
@attributes
= (
'count'
=>
$count
, );
$self
->xml_start_tag(
'cellMetadata'
,
@attributes
);
$self
->xml_start_tag(
'bk'
);
$self
->_write_rc(1, 0);
$self
->xml_end_tag(
'bk'
);
$self
->xml_end_tag(
'cellMetadata'
);
}
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
);
for
my
$i
( 0 ..
$count
- 1 ) {
$self
->xml_start_tag(
'bk'
);
$self
->_write_rc(
$type
,
$i
);
$self
->xml_end_tag(
'bk'
);
}
$self
->xml_end_tag(
'valueMetadata'
);
}
sub
_write_rc {
my
$self
=
shift
;
my
$type
=
shift
;
my
$value
=
shift
;
my
@attributes
= (
't'
=>
$type
,
'v'
=>
$value
,
);
$self
->xml_empty_tag(
'rc'
,
@attributes
);
}
sub
_write_xlrd_rvb {
my
$self
=
shift
;
my
$value
=
shift
;
my
@attributes
= (
'i'
=>
$value
, );
$self
->xml_empty_tag(
'xlrd:rvb'
,
@attributes
);
}
1;