line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Spreadsheet::Write::WriteXLS; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
3
|
use Spreadsheet::WriteExcel; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use base qw'Spreadsheet::Write'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
942
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
2
|
|
|
2
|
1
|
6
|
my ($class, %args) = @_; |
11
|
2
|
|
|
|
|
4
|
my $self = bless {}, $class; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
0
|
|
|
18
|
my $filename = $args{'file'} || $args{'filename'} || die "Need filename."; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
5
|
$self->{'_FILENAME'} = $filename; |
16
|
2
|
|
50
|
|
|
7
|
$self->{'_SHEETNAME'} = $args{'sheet'} || ''; |
17
|
2
|
|
50
|
|
|
8
|
$self->{'_STYLES'} = $args{'styles'} || {}; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
9
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _prepare { |
23
|
8
|
|
|
8
|
|
9
|
my $self = shift; |
24
|
8
|
|
|
|
|
9
|
my $worksheet = $self->{'_WORKSHEET'}; |
25
|
8
|
|
|
|
|
18
|
my $workbook = $self->{'_WORKBOOK'}; |
26
|
|
|
|
|
|
|
|
27
|
8
|
100
|
|
|
|
9
|
if(!$worksheet) { |
28
|
2
|
|
|
|
|
5
|
$self->{'_FH'}->binmode(); |
29
|
2
|
|
|
|
|
16
|
$workbook = Spreadsheet::WriteExcel->new($self->{'_FH'}); |
30
|
2
|
|
|
|
|
2938
|
$self->{'_WORKBOOK'} = $workbook; |
31
|
2
|
|
|
|
|
10
|
$worksheet = $workbook->add_worksheet($self->{'_SHEETNAME'}); |
32
|
2
|
|
|
|
|
690
|
$self->{'_WORKSHEET'} = $worksheet; |
33
|
2
|
|
|
|
|
2
|
$self->{'_WORKBOOK_ROW'} = 0; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
8
|
|
|
|
|
18
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub freeze (@) { |
40
|
2
|
|
|
2
|
1
|
7
|
my $self=shift; |
41
|
2
|
50
|
|
|
|
3
|
$self->_open() || return undef; |
42
|
2
|
|
|
|
|
7
|
$self->{'_WORKSHEET'}->freeze_panes(@_); |
43
|
2
|
|
|
|
|
20
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub close { |
47
|
4
|
|
|
4
|
1
|
8
|
my $self=shift; |
48
|
|
|
|
|
|
|
|
49
|
4
|
100
|
|
|
|
19
|
return if $self->{'_CLOSED'}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$self->{'_WORKBOOK'}->close |
52
|
2
|
50
|
|
|
|
13
|
if $self->{'_WORKBOOK'}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$self->{'_FH'}->close |
55
|
2
|
50
|
|
|
|
11685
|
if $self->{'_FH'}; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
133
|
$self->{'_CLOSED'} = 1; |
58
|
2
|
|
|
|
|
17
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _format_cache($$) { |
62
|
20
|
|
|
20
|
|
21
|
my ($self, $format) = @_; |
63
|
|
|
|
|
|
|
|
64
|
20
|
|
|
|
|
17
|
my $cache_key=''; |
65
|
20
|
|
|
|
|
36
|
foreach my $key (sort keys %$format) { |
66
|
20
|
|
|
|
|
28
|
$cache_key .= $key . $format->{$key}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
20
|
100
|
|
|
|
30
|
if(exists($self->{'_FORMAT_CACHE'}->{$cache_key})) { |
70
|
14
|
|
|
|
|
32
|
return $self->{'_FORMAT_CACHE'}->{$cache_key}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
6
|
|
|
|
|
18
|
return $self->{'_FORMAT_CACHE'}->{$cache_key} = $self->{'_WORKBOOK'}->add_format(%$format); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub addsheet ($$) { |
77
|
0
|
|
|
0
|
1
|
0
|
my ($self,$name)=@_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
0
|
$self->_open() || return undef; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
my $worksheet = $self->{'_WORKBOOK'}->add_worksheet($name); |
82
|
0
|
|
|
|
|
0
|
$self->{'_SHEETNAME'} = $name; |
83
|
0
|
|
|
|
|
0
|
$self->{'_WORKSHEET'} = $worksheet; |
84
|
0
|
|
|
|
|
0
|
$self->{'_WORKBOOK_ROW'} = 0; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
0
|
return $self; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _add_prepared_row { |
90
|
6
|
|
|
6
|
|
7
|
my $self = shift; |
91
|
|
|
|
|
|
|
|
92
|
6
|
|
|
|
|
5
|
my $worksheet = $self->{'_WORKSHEET'}; |
93
|
6
|
|
|
|
|
5
|
my $workbook = $self->{'_WORKBOOK'}; |
94
|
6
|
|
|
|
|
5
|
my $row = $self->{'_WORKBOOK_ROW'}; |
95
|
6
|
|
|
|
|
6
|
my $col = 0; |
96
|
|
|
|
|
|
|
|
97
|
6
|
|
|
|
|
16
|
for(my $i=0; $i
|
98
|
24
|
|
|
|
|
1507
|
my %props = %{ $_[$i] }; |
|
24
|
|
|
|
|
59
|
|
99
|
24
|
|
|
|
|
33
|
my $value = $props{'content'}; |
100
|
|
|
|
|
|
|
|
101
|
24
|
|
|
|
|
21
|
delete $props{'content'}; |
102
|
24
|
|
|
|
|
20
|
my $props = \%props; |
103
|
|
|
|
|
|
|
|
104
|
24
|
|
|
|
|
22
|
my %format; |
105
|
24
|
100
|
|
|
|
26
|
if(%props) { |
106
|
20
|
100
|
|
|
|
24
|
if(my $stylelist = $props->{'style'}) { |
107
|
12
|
50
|
|
|
|
73
|
$stylelist=[$stylelist] unless ref $stylelist; |
108
|
|
|
|
|
|
|
|
109
|
12
|
50
|
|
|
|
21
|
foreach my $style (ref $stylelist ? @$stylelist : ($stylelist)) { |
110
|
12
|
|
|
|
|
16
|
my $stprops = $self->{'_STYLES'}->{$style}; |
111
|
12
|
50
|
|
|
|
16
|
if(!$stprops) { |
112
|
0
|
|
|
|
|
0
|
warn "Style '$style' is not defined\n"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
else { |
115
|
12
|
|
|
|
|
8
|
my %a; |
116
|
12
|
|
|
|
|
33
|
@a{keys %$stprops} = values %$stprops; |
117
|
12
|
|
|
|
|
21
|
@a{keys %$props} = values %$props; |
118
|
12
|
|
|
|
|
28
|
$props=\%a; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
20
|
100
|
66
|
|
|
40
|
if(defined $props->{'font_weight'} && $props->{'font_weight'} eq 'bold') { |
124
|
8
|
|
|
|
|
9
|
$format{'bold'} = 1; |
125
|
|
|
|
|
|
|
} |
126
|
20
|
100
|
66
|
|
|
50
|
if(defined $props->{'font_style'} && $props->{'font_style'} eq 'italic') { |
127
|
8
|
|
|
|
|
8
|
$format{'italic'} = 1; |
128
|
|
|
|
|
|
|
} |
129
|
20
|
50
|
33
|
|
|
33
|
if(defined $props->{'font_decoration'} && $props->{'font_decoration'} =~ m'underline') { |
130
|
0
|
|
|
|
|
0
|
$format{'underline'} = 1; |
131
|
|
|
|
|
|
|
} |
132
|
20
|
50
|
33
|
|
|
21
|
if(defined $props->{'font_decoration'} && $props->{'font_decoration'} =~ m'strikeout') { |
133
|
0
|
|
|
|
|
0
|
$format{'font_strikeout'} = 1; |
134
|
|
|
|
|
|
|
} |
135
|
20
|
50
|
|
|
|
27
|
if(defined $props->{'font_color'}) { |
136
|
0
|
|
|
|
|
0
|
$format{'color'} = $props->{'font_color'}; |
137
|
|
|
|
|
|
|
} |
138
|
20
|
50
|
|
|
|
22
|
if (defined $props->{'bg_color'}) { |
139
|
0
|
|
|
|
|
0
|
$format{'bg_color'} = $props->{'bg_color'}; |
140
|
|
|
|
|
|
|
} |
141
|
20
|
50
|
|
|
|
21
|
if (defined $props->{'font_face'}) { |
142
|
0
|
|
|
|
|
0
|
$format{'font'}=$props->{'font_face'}; |
143
|
|
|
|
|
|
|
} |
144
|
20
|
50
|
|
|
|
21
|
if (defined $props->{'font_size'}) { |
145
|
0
|
|
|
|
|
0
|
$format{'size'}=$props->{'font_size'}; |
146
|
|
|
|
|
|
|
} |
147
|
20
|
50
|
|
|
|
21
|
if (defined $props->{'align'}) { |
148
|
0
|
|
|
|
|
0
|
$format{'align'}=$props->{'align'}; |
149
|
|
|
|
|
|
|
} |
150
|
20
|
50
|
|
|
|
21
|
if (defined $props->{'valign'}) { |
151
|
0
|
|
|
|
|
0
|
$format{'valign'}=$props->{'valign'}; |
152
|
|
|
|
|
|
|
} |
153
|
20
|
100
|
|
|
|
21
|
if (defined $props->{'format'}) { |
154
|
4
|
|
|
|
|
6
|
$format{'num_format'} = $props->{'format'}; |
155
|
|
|
|
|
|
|
} |
156
|
20
|
50
|
|
|
|
21
|
if (defined $props->{'width'}) { |
157
|
0
|
|
|
|
|
0
|
$worksheet->set_column($col,$col,$props->{'width'}); |
158
|
|
|
|
|
|
|
} |
159
|
20
|
50
|
33
|
|
|
33
|
if (defined $props->{'comment'} && length($props->{'comment'})) { |
160
|
0
|
|
|
|
|
0
|
$worksheet->write_comment($row,$col,$props->{'comment'}); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
24
|
|
|
|
|
32
|
my @params = ($row, $col++, $value); |
165
|
24
|
100
|
|
|
|
42
|
push @params, $self->_format_cache(\%format) if keys %format; |
166
|
|
|
|
|
|
|
|
167
|
24
|
|
100
|
|
|
311
|
my $type = lc ($props->{'type'} || 'auto'); |
168
|
24
|
100
|
|
|
|
39
|
if ($type eq 'auto') { $worksheet->write(@params); } |
|
12
|
50
|
|
|
|
19
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
169
|
12
|
|
|
|
|
21
|
elsif ($type eq 'string') { $worksheet->write_string(@params); } |
170
|
0
|
|
|
|
|
0
|
elsif ($type eq 'text') { $worksheet->write_string(@params); } |
171
|
0
|
|
|
|
|
0
|
elsif ($type eq 'number') { $worksheet->write_number(@params); } |
172
|
0
|
|
|
|
|
0
|
elsif ($type eq 'blank') { $worksheet->write_blank(@params); } |
173
|
0
|
|
|
|
|
0
|
elsif ($type eq 'formula') { $worksheet->write_formula(@params); } |
174
|
0
|
|
|
|
|
0
|
elsif ($type eq 'url') { $worksheet->write_url(@params); } |
175
|
|
|
|
|
|
|
else { |
176
|
0
|
|
|
|
|
0
|
warn "Unknown cell type $type"; |
177
|
0
|
|
|
|
|
0
|
$worksheet->write(@params); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
6
|
|
|
|
|
3283
|
$self->{'_WORKBOOK_ROW'}++; |
182
|
|
|
|
|
|
|
|
183
|
6
|
|
|
|
|
26
|
return $self; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |