| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Spreadsheet::DataToExcel; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
234700
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
138
|
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
55
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.0104'; |
|
7
|
1
|
|
|
1
|
|
6
|
use Spreadsheet::WriteExcel; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
41
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use base 'Class::Data::Accessor'; |
|
|
1
|
|
|
|
|
13
|
|
|
|
1
|
|
|
|
|
985
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_classaccessors( qw/ |
|
10
|
|
|
|
|
|
|
data |
|
11
|
|
|
|
|
|
|
file |
|
12
|
|
|
|
|
|
|
error |
|
13
|
|
|
|
|
|
|
/ ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
0
|
|
|
0
|
1
|
|
sub new { bless {}, shift } |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub dump { |
|
19
|
0
|
|
|
0
|
1
|
|
my ( $self, $file, $data, $opts ) = @_; |
|
20
|
|
|
|
|
|
|
|
|
21
|
0
|
|
0
|
|
|
|
$opts ||= {}; |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
%$opts = ( |
|
24
|
|
|
|
|
|
|
width_multiplier => 1, |
|
25
|
|
|
|
|
|
|
text_wrap => 1, |
|
26
|
|
|
|
|
|
|
calc_column_widths => 1, |
|
27
|
|
|
|
|
|
|
center_first_row => 1, |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
%$opts, |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$self->error( undef ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
0
|
0
|
|
|
|
$file = $self->file |
|
35
|
|
|
|
|
|
|
unless defined $file |
|
36
|
|
|
|
|
|
|
and length $file; |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
0
|
0
|
|
|
|
return $self->_set_error('Missing filename for output') |
|
39
|
|
|
|
|
|
|
unless defined $file |
|
40
|
|
|
|
|
|
|
and length $file; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
0
|
0
|
|
|
|
$data = $self->data |
|
43
|
|
|
|
|
|
|
unless defined $data |
|
44
|
|
|
|
|
|
|
and ref $data eq 'ARRAY'; |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
0
|
0
|
|
|
|
return $self->_set_error('Missing data for output or data is in incorrect format (needs to be an arrayref of arrayrefs)') |
|
47
|
|
|
|
|
|
|
unless defined $data |
|
48
|
|
|
|
|
|
|
and ref $data eq 'ARRAY'; |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$self->file( $file ); |
|
51
|
0
|
|
|
|
|
|
$self->data( $data ); |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $wb = Spreadsheet::WriteExcel->new( $file ); |
|
54
|
0
|
|
|
|
|
|
my $ws = $wb->add_worksheet; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if ( $opts->{calc_column_widths} ) { |
|
57
|
0
|
|
|
|
|
|
my $col_num = 0; |
|
58
|
0
|
|
|
|
|
|
my @sizes; |
|
59
|
0
|
|
|
|
|
|
for ( @$data ) { |
|
60
|
0
|
0
|
|
|
|
|
$col_num = $#$_ |
|
61
|
|
|
|
|
|
|
if @$_ > $col_num; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
for my $idx ( 0..$#$_ ) { |
|
64
|
0
|
|
|
|
|
|
my $length; |
|
65
|
0
|
0
|
0
|
|
|
|
if ( $opts->{text_wrap} and defined $_->[$idx] ) { |
|
66
|
0
|
|
|
|
|
|
my @lines = split /\n/, $_->[$idx]; |
|
67
|
0
|
|
|
|
|
|
my $max_line_length = 0; |
|
68
|
0
|
|
|
|
|
|
for ( @lines ) { |
|
69
|
|
|
|
|
|
|
defined |
|
70
|
0
|
0
|
|
|
|
|
or next; |
|
71
|
0
|
0
|
|
|
|
|
$max_line_length = length |
|
72
|
|
|
|
|
|
|
if $max_line_length < length; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
0
|
|
|
|
|
|
$length = $max_line_length; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
else { |
|
77
|
0
|
0
|
|
|
|
|
$length = defined $_->[$idx] ? length $_->[$idx] : 0; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
0
|
0
|
|
|
|
$sizes[$idx] = $length |
|
81
|
|
|
|
|
|
|
if not defined $sizes[$idx] |
|
82
|
|
|
|
|
|
|
or $sizes[$idx] < $length; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
for ( 0..$col_num ) { |
|
87
|
0
|
|
|
|
|
|
$ws->set_column( |
|
88
|
|
|
|
|
|
|
$_, |
|
89
|
|
|
|
|
|
|
$_, |
|
90
|
|
|
|
|
|
|
int($sizes[$_] * $opts->{width_multiplier}) ); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
for my $row_num ( 0..$#$data ) { |
|
95
|
0
|
|
|
|
|
|
my $row = $data->[ $row_num ]; |
|
96
|
0
|
0
|
|
|
|
|
ref $row eq 'ARRAY' |
|
97
|
|
|
|
|
|
|
or next; |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
if ( $opts->{text_wrap} ) { |
|
100
|
0
|
|
|
|
|
|
my $format = $wb->add_format; |
|
101
|
0
|
|
|
|
|
|
$format->set_text_wrap; |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
0
|
0
|
|
|
|
$format->set_align('center') |
|
104
|
|
|
|
|
|
|
if $opts->{center_first_row} |
|
105
|
|
|
|
|
|
|
and $row_num == 0; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
$ws->set_row( $row_num, undef, $format ); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
for my $cell_num ( 0..$#$row ) { |
|
111
|
0
|
|
|
|
|
|
my $cell_data = $row->[$cell_num]; |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$ws->write( $row_num, $cell_num, $cell_data ); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
} |
|
116
|
0
|
|
|
|
|
|
$wb->close; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return 1; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _set_error { |
|
122
|
0
|
|
|
0
|
|
|
my ( $self, $error ) = @_; |
|
123
|
0
|
|
|
|
|
|
$self->error( $error ); |
|
124
|
0
|
|
|
|
|
|
return; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
|
128
|
|
|
|
|
|
|
__END__ |