line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (C) 2003-2007, G. Allen Morris III, all rights reserved |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
22
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
218
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Data::Tabular::Output::XLS; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @CARP_NOT = qw (Data::Tabular Data::Tabular::Output); |
8
|
3
|
|
|
3
|
|
20
|
use Carp qw (croak); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
205
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
19
|
use base qw(Data::Tabular::Output); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
19087
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new |
13
|
|
|
|
|
|
|
{ |
14
|
3
|
|
|
3
|
1
|
7
|
my $class = shift; |
15
|
3
|
|
|
|
|
18
|
my $args = { @_ }; |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
|
|
15
|
my $self = bless {}, $class; |
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
|
|
26
|
my $arg_list = { |
20
|
|
|
|
|
|
|
table => {required => 1}, |
21
|
|
|
|
|
|
|
output => {}, |
22
|
|
|
|
|
|
|
workbook => {required => 1}, |
23
|
|
|
|
|
|
|
worksheet => {required => 1}, |
24
|
|
|
|
|
|
|
row_offset => {}, |
25
|
|
|
|
|
|
|
column_offset => {}, |
26
|
|
|
|
|
|
|
}; |
27
|
3
|
|
|
|
|
17
|
for my $arg (keys %$arg_list) { |
28
|
18
|
|
|
|
|
256
|
$self->{$arg} = $args->{$arg}; |
29
|
18
|
50
|
66
|
|
|
84
|
croak "Need $arg" if $arg_list->{$arg}->{required} && !defined($self->{$arg}); |
30
|
18
|
|
|
|
|
36
|
delete $args->{$arg}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
3
|
50
|
|
|
|
21
|
if (my @x_list = keys %$args) { |
34
|
0
|
|
|
|
|
0
|
die 'Unknows arguments: ' . join(' ', sort @x_list); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
14
|
$self->_render; |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
79
|
$self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub workbook |
43
|
|
|
|
|
|
|
{ |
44
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
45
|
3
|
|
|
|
|
17
|
$self->{workbook}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub worksheet |
49
|
|
|
|
|
|
|
{ |
50
|
3
|
|
|
3
|
1
|
5
|
my $self = shift; |
51
|
3
|
|
|
|
|
16
|
$self->{worksheet}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub row_offset |
55
|
|
|
|
|
|
|
{ |
56
|
3
|
|
|
3
|
1
|
7
|
my $self = shift; |
57
|
3
|
|
|
|
|
8
|
$self->{row_offset}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub col_offset |
61
|
|
|
|
|
|
|
{ |
62
|
3
|
|
|
3
|
1
|
7
|
my $self = shift; |
63
|
3
|
|
|
|
|
7
|
$self->{col_offset}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _get_col_id |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
$self->output->col_id(shift); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _render |
74
|
|
|
|
|
|
|
{ |
75
|
3
|
|
|
3
|
|
7
|
my $self = shift; |
76
|
|
|
|
|
|
|
|
77
|
3
|
|
33
|
|
|
12
|
my $workbook = $self->workbook || croak 'need a workbook'; |
78
|
3
|
|
33
|
|
|
13
|
my $worksheet = $self->worksheet || croak 'need a worksheet'; |
79
|
|
|
|
|
|
|
|
80
|
3
|
|
|
|
|
15
|
my $row_offset = $self->row_offset; |
81
|
3
|
|
|
|
|
10
|
my $col_offset = $self->col_offset; |
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
25
|
my $pin_title = $self->output->test_xls_attribute('pin_title'); |
84
|
|
|
|
|
|
|
|
85
|
3
|
|
|
|
|
41
|
my $format_default = $workbook->addformat( |
86
|
|
|
|
|
|
|
align => 'left', |
87
|
|
|
|
|
|
|
size => 8, |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
3
|
|
|
|
|
3768
|
my $formats = { |
91
|
|
|
|
|
|
|
'right' => $workbook->addformat( |
92
|
|
|
|
|
|
|
align => 'right', |
93
|
|
|
|
|
|
|
text_wrap => 1, |
94
|
|
|
|
|
|
|
bold => 1, |
95
|
|
|
|
|
|
|
), |
96
|
|
|
|
|
|
|
'left' => $workbook->addformat( |
97
|
|
|
|
|
|
|
align => 'left', |
98
|
|
|
|
|
|
|
text_wrap => 1, |
99
|
|
|
|
|
|
|
bold => 1, |
100
|
|
|
|
|
|
|
), |
101
|
|
|
|
|
|
|
}; |
102
|
|
|
|
|
|
|
|
103
|
3
|
|
|
|
|
723
|
my $output = $self->output; |
104
|
|
|
|
|
|
|
|
105
|
3
|
|
|
|
|
32
|
for my $column ($self->columns()) { |
106
|
32
|
|
|
|
|
918
|
my $col = $column->col_id; |
107
|
32
|
|
50
|
|
|
83
|
my $align = $column->align || undef; |
108
|
|
|
|
|
|
|
|
109
|
32
|
|
|
|
|
3198
|
my $type = $self->output->type($column->name); |
110
|
32
|
|
|
|
|
55
|
my $width = undef; |
111
|
32
|
100
|
|
|
|
133
|
if ($type eq 'number') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
112
|
4
|
|
50
|
|
|
15
|
$align ||= 'right'; |
113
|
|
|
|
|
|
|
} elsif ($type eq 'time') { |
114
|
1
|
|
|
|
|
2
|
$width = 22; |
115
|
1
|
|
50
|
|
|
5
|
$align ||= 'right'; |
116
|
|
|
|
|
|
|
} elsif ($type eq 'date') { |
117
|
0
|
|
|
|
|
0
|
$width = 12; |
118
|
0
|
|
0
|
|
|
0
|
$align ||= 'right'; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
32
|
|
|
|
|
155
|
$worksheet->set_column($col, $col, undef, $formats->{$align}); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
3
|
|
|
|
|
154
|
my $types = { |
125
|
|
|
|
|
|
|
default => { |
126
|
|
|
|
|
|
|
align => 'left', |
127
|
|
|
|
|
|
|
size => 8, |
128
|
|
|
|
|
|
|
}, |
129
|
|
|
|
|
|
|
month => { |
130
|
|
|
|
|
|
|
num_format => 'mm/yyyy', |
131
|
|
|
|
|
|
|
align => 'right', |
132
|
|
|
|
|
|
|
size => 8, |
133
|
|
|
|
|
|
|
}, |
134
|
|
|
|
|
|
|
time => { |
135
|
|
|
|
|
|
|
num_format => 'mm/dd/yyyy hh:mm:ss am/pm', |
136
|
|
|
|
|
|
|
align => 'right', |
137
|
|
|
|
|
|
|
size => 8, |
138
|
|
|
|
|
|
|
}, |
139
|
|
|
|
|
|
|
date => { |
140
|
|
|
|
|
|
|
num_format => 'mm/dd/yyyy', |
141
|
|
|
|
|
|
|
align => 'right', |
142
|
|
|
|
|
|
|
size => 8, |
143
|
|
|
|
|
|
|
}, |
144
|
|
|
|
|
|
|
dollar => { |
145
|
|
|
|
|
|
|
num_format => '$#,##0.00_);[Red]($#,##0.00)', |
146
|
|
|
|
|
|
|
align => 'right', |
147
|
|
|
|
|
|
|
size => 8, |
148
|
|
|
|
|
|
|
}, |
149
|
|
|
|
|
|
|
percent => { |
150
|
|
|
|
|
|
|
num_format => '0.0%', |
151
|
|
|
|
|
|
|
align => 'right', |
152
|
|
|
|
|
|
|
size => 8, |
153
|
|
|
|
|
|
|
}, |
154
|
|
|
|
|
|
|
number => { |
155
|
|
|
|
|
|
|
num_format => '#,##0', |
156
|
|
|
|
|
|
|
align => 'right', |
157
|
|
|
|
|
|
|
size => 8, |
158
|
|
|
|
|
|
|
}, |
159
|
|
|
|
|
|
|
text => { |
160
|
|
|
|
|
|
|
align => 'left', |
161
|
|
|
|
|
|
|
size => 8, |
162
|
|
|
|
|
|
|
}, |
163
|
|
|
|
|
|
|
}; |
164
|
3
|
|
|
|
|
9
|
for my $type (keys %{$types}) { |
|
3
|
|
|
|
|
14
|
|
165
|
24
|
|
|
|
|
2842
|
$formats->{$type} = $workbook->addformat(%{$types->{$type}}); |
|
24
|
|
|
|
|
4308
|
|
166
|
24
|
|
|
|
|
19944
|
$formats->{$type . '_hdr'} = $workbook->addformat(%{$types->{$type}}, bold => 1, text_wrap => 0); |
|
24
|
|
|
|
|
107
|
|
167
|
|
|
|
|
|
|
} |
168
|
3
|
|
|
|
|
354
|
$formats->{'title_right'} = $workbook->addformat(align => 'right', size => 8, bold => 1, text_wrap => 1); |
169
|
3
|
|
|
|
|
294
|
$formats->{'title_left'} = $workbook->addformat(align => 'left', size => 8, bold => 1, text_wrap => 1); |
170
|
3
|
|
|
|
|
284
|
$formats->{'title_center'} = $workbook->addformat(align => 'center', size => 8, bold => 1, text_wrap => 1); |
171
|
3
|
|
|
|
|
285
|
$formats->{'averages_right'} = $workbook->addformat(align => 'right', size => 8, bold => 1, text_wrap => 0); |
172
|
3
|
|
|
|
|
306
|
$formats->{'averages_left'} = $workbook->addformat(align => 'left', size => 8, bold => 1, text_wrap => 0); |
173
|
3
|
|
|
|
|
271
|
$formats->{'averages_center'} = $workbook->addformat(align => 'center', size => 8, bold => 1, text_wrap => 0); |
174
|
|
|
|
|
|
|
|
175
|
3
|
|
|
|
|
382
|
my $title_pinned = 0; |
176
|
|
|
|
|
|
|
|
177
|
3
|
|
|
|
|
47
|
for my $row ($self->rows()) { |
178
|
64
|
50
|
|
|
|
335
|
if ($row->is_title) { |
179
|
0
|
0
|
|
|
|
0
|
if ($pin_title) { |
180
|
0
|
0
|
|
|
|
0
|
next if $title_pinned; |
181
|
0
|
|
|
|
|
0
|
$title_pinned = 1; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
} |
184
|
64
|
|
|
|
|
277
|
for my $cell ($row->cells()) { |
185
|
440
|
|
|
|
|
1487
|
my ($y, $x) = ($cell->row_id, $cell->col_id); |
186
|
440
|
|
|
|
|
1142
|
my $data = $cell->data; |
187
|
440
|
|
|
|
|
654
|
my $formula = ''; |
188
|
440
|
|
|
|
|
1307
|
my $value = 'asdf'; |
189
|
440
|
|
|
|
|
570
|
eval { |
190
|
440
|
50
|
|
|
|
843
|
if (ref $data) { |
191
|
440
|
|
|
|
|
3092
|
$worksheet->write($y, $x, $data->string); |
192
|
|
|
|
|
|
|
} else { |
193
|
0
|
|
|
|
|
0
|
$worksheet->write($y, $x, $data); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
}; |
196
|
440
|
50
|
|
|
|
53893
|
if ($@) { |
197
|
0
|
|
|
|
|
|
die "$formula " . $@; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; |
204
|
|
|
|
|
|
|
__END__ |