Excel-Template-XLSX

 view release on metacpan or  search on metacpan

lib/Excel/Template/XLSX.pm  view on Meta::CPAN

      my $code = $_->att('formatCode') // $id;
      $number_format->{$id} = { num_format => $code } if $id;
   } $styles->find_nodes('//numFmts/numFmt');
   return $number_format;
}
###############################################################################
sub _parse_protection {

=head2 _parse_protection

Parses locked and hidden attributes for a cell. These are only
useful if the worksheet is locked.  

This module does not lock the workbook or the worksheet.

=cut

   my $self       = shift;
   my ($node)     = @_;
   my @protection = qw(locked hidden);
   my %prot       = ();
   if ( my $protection = $_->first_child('protection') ) {
      map {
         my $v = $protection->att($_);
         $prot{$_} = $v if defined $v;
      } @protection;
   }
   return %prot;
}
###############################################################################

t/04-styles.t  view on Meta::CPAN

$sheet->write( 2, 0, 'Pattern',  $pat_format );
$sheet->write( 3, 0, 4050.1,     $num_format1 );

# Zip codes:
# string tested in shared strings
my $zip_format = $wbk->add_format( num_format => '00000' );
$sheet->write( 4, 0, '01111', $zip_format );
$sheet->keep_leading_zeros();    # Just converts number to a string
$sheet->write( 5, 0, '01111' );

my $prot_format = $wbk->add_format( 'hidden' => 1, 'locked' => 1 );
$sheet->write_formula( 6, 0, '="Locked" & " Hidden"', $prot_format );

$wbk->close();

# Get workbook content as a template
my ( $gfh, $gfilename ) = tempfile( SUFFIX => '.xlsx' );
my ( $self, $twbk ) = Excel::Template::XLSX->new( $gfilename, $efilename );
$self->parse_template();

# Get the format object referenced by cell 0,0

t/04-styles.t  view on Meta::CPAN

#warn Dump $got_format6;
is($got_format6->{'_num_format'},
   'dd/mm/yy hh:mm',
   'Number Format date/time'
);

my $got_format7 = $got_sheet->{_table}{4}{0}[2];
is( $got_format7->{'_num_format'}, '00000', 'Number Format zip code' );

my $got_format8 = $got_sheet->{_table}{6}{0}[2];
is( $got_format8->{'_locked'}, '1', 'Protection locked' );
is( $got_format8->{'_hidden'}, '1', 'Protection hidden' );

$twbk->close();

warn "Files \n$efilename\n$gfilename\n not deleted\n"
    if $File::Temp::KEEP_ALL;
done_testing();

__END__



( run in 0.900 second using v1.01-cache-2.11-cpan-49f99fa48dc )