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