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