line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Spreadsheet::WriteExcel::FromXML::Workbook; |
2
|
5
|
|
|
5
|
|
28
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
164
|
|
3
|
5
|
|
|
5
|
|
157
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
220
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.1'; |
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
43
|
use Carp qw(confess cluck); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
353
|
|
8
|
5
|
|
|
5
|
|
18835
|
use Spreadsheet::WriteExcel; |
|
5
|
|
|
|
|
806909
|
|
|
5
|
|
|
|
|
257
|
|
9
|
5
|
|
|
5
|
|
6088
|
use Spreadsheet::WriteExcel::Big; |
|
5
|
|
|
|
|
3643
|
|
|
5
|
|
|
|
|
235
|
|
10
|
5
|
|
|
5
|
|
5586
|
use Spreadsheet::WriteExcel::FromXML::Worksheet; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
7051
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Spreadsheet::WriteExcel::FromXML::Workbook |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# inner class for use by FromXML |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Workbook object for FromXML. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 API REFERENCE |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 new |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Consturctor for Workbook object. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
sub new |
32
|
|
|
|
|
|
|
{ |
33
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
34
|
0
|
|
0
|
|
|
|
my $class = ref($this) || $this; |
35
|
0
|
|
|
|
|
|
my $self = {}; |
36
|
0
|
|
|
|
|
|
bless $self,$class; |
37
|
0
|
|
|
|
|
|
$self->_init(@_); |
38
|
0
|
|
|
|
|
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 _init |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Creates a new report buffer, file handle and Spreadsheet::WriteExcel |
44
|
|
|
|
|
|
|
object. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _init |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
0
|
|
|
my($self,$bigflag) = @_; |
51
|
0
|
|
|
|
|
|
my $buff = ''; |
52
|
0
|
|
|
|
|
|
$self->_buffer( \$buff ); |
53
|
0
|
|
|
|
|
|
$self->excelFh( IO::Scalar->new( $self->_buffer ) ); |
54
|
0
|
|
|
|
|
|
my $workbook = ''; |
55
|
0
|
0
|
|
|
|
|
if( $bigflag ) |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
|
|
|
$workbook = Spreadsheet::WriteExcel::Big->new( $self->excelFh ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
|
|
|
$workbook = Spreadsheet::WriteExcel->new( $self->excelFh ); |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
$self->excelWorkbook( $workbook ); |
64
|
0
|
0
|
|
|
|
|
unless( $self->excelWorkbook ) |
65
|
|
|
|
|
|
|
{ |
66
|
0
|
|
|
|
|
|
confess "Could not create a Spreadsheet::WriteExcel object. This is bad!\n"; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
$self->worksheets( {} ); |
69
|
0
|
|
|
|
|
|
$self->formats( {} ); |
70
|
0
|
|
|
|
|
|
$self->worksheetOrder( [] ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 addWorksheet($) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Param: title - title for the worksheet that people will see in the Excel spreadsheet. |
76
|
|
|
|
|
|
|
Return: void |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Creates & adds a new worksheet to the spreadsheet. It keeps track of the |
79
|
|
|
|
|
|
|
order the worksheets were added and a hash table so one can easily reference |
80
|
|
|
|
|
|
|
them later. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
sub addWorksheet |
84
|
|
|
|
|
|
|
{ |
85
|
0
|
|
|
0
|
1
|
|
my($self,$title, $landscape, $paper, $header, $header_margin, $footer, $footer_margin) = @_; |
86
|
0
|
0
|
|
|
|
|
if( exists $self->worksheets->{ $title } ) |
87
|
|
|
|
|
|
|
{ |
88
|
0
|
|
|
|
|
|
confess "Worksheet already exists with name '$title'\n"; |
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
|
my $sheet = $self->excelWorkbook->add_worksheet( $title ) ; |
91
|
0
|
|
|
|
|
|
my $ws = Spreadsheet::WriteExcel::FromXML::Worksheet->new( $sheet ); |
92
|
0
|
|
|
|
|
|
$self->worksheets->{ $title } = $ws; |
93
|
0
|
0
|
|
|
|
|
$sheet->set_landscape() if defined($landscape); |
94
|
0
|
0
|
|
|
|
|
$sheet->set_paper($paper) if defined($paper); |
95
|
0
|
0
|
|
|
|
|
unless( $self->worksheets->{ $title } ) |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
|
|
|
confess "Couldn't create a new worksheet on ",$self->excelWorkbook,"??\n"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if (defined($header)) { |
101
|
|
|
|
|
|
|
#print "Header: $header\n"; |
102
|
0
|
0
|
|
|
|
|
if (!defined($header_margin)) { |
103
|
0
|
|
|
|
|
|
$sheet->set_header($header); |
104
|
|
|
|
|
|
|
} else { |
105
|
0
|
|
|
|
|
|
$sheet->set_header($header, $header_margin); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
if (defined($footer)) { |
110
|
|
|
|
|
|
|
#print "Footer: $footer\n"; |
111
|
0
|
0
|
|
|
|
|
if (!defined($footer_margin)) { |
112
|
0
|
|
|
|
|
|
$sheet->set_footer($footer); |
113
|
|
|
|
|
|
|
} else { |
114
|
0
|
|
|
|
|
|
$sheet->set_header($footer, $footer_margin); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
push @{ $self->worksheetOrder }, $title; |
|
0
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
return $self->worksheets->{ $title }; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub addFormat |
123
|
|
|
|
|
|
|
{ |
124
|
0
|
|
|
0
|
0
|
|
my($self,$attr) = @_; |
125
|
0
|
|
|
|
|
|
my $name = $attr->{'name'}; |
126
|
0
|
0
|
|
|
|
|
if( exists $self->formats->{ $name } ) |
127
|
|
|
|
|
|
|
{ |
128
|
0
|
|
|
|
|
|
cluck "format with the name '$name' already exists. Ignoring.\n"; |
129
|
0
|
|
|
|
|
|
return 1; |
130
|
|
|
|
|
|
|
} |
131
|
0
|
|
|
|
|
|
delete $attr->{'name'}; |
132
|
0
|
|
|
|
|
|
my $format = $self->excelWorkbook->add_format(); |
133
|
0
|
|
|
|
|
|
foreach my $k ( keys %{ $attr } ) |
|
0
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
{ |
135
|
0
|
|
|
|
|
|
my $method = 'set_'.$k; |
136
|
|
|
|
|
|
|
# Hack for alignment |
137
|
0
|
0
|
0
|
|
|
|
if ($k eq 'align' && ($attr->{'valign'} || $attr->{'halign'})) { |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
138
|
0
|
|
|
|
|
|
next; # ignore align if valign or halign are set... |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif ($k eq 'halign' or $k eq 'valign') |
141
|
|
|
|
|
|
|
{ |
142
|
0
|
|
|
|
|
|
$method = 'set_align'; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
# print STDERR "Adding format for $method to $format\n"; |
145
|
0
|
|
|
|
|
|
$format->$method( $attr->{$k} ); |
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
|
$self->formats->{ $name } = $format; |
148
|
0
|
|
|
|
|
|
return 1; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 getWorksheet($) |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Param: name - hash table namespace for the worksheet. |
154
|
|
|
|
|
|
|
Return: Worksheet object associated with name. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Accesses the hash table of worksheets and returns the worksheet with the |
157
|
|
|
|
|
|
|
specified name. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
sub getWorksheet |
161
|
|
|
|
|
|
|
{ |
162
|
0
|
|
|
0
|
1
|
|
my($self,$name) = @_; |
163
|
0
|
0
|
|
|
|
|
return undef unless exists $self->worksheets->{ $name }; |
164
|
0
|
|
|
|
|
|
return $self->worksheets->{ $name }; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub getWorksheetsInOrder |
168
|
|
|
|
|
|
|
{ |
169
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
170
|
0
|
|
|
|
|
|
return @{ $self->worksheets }{ @{ $self->worksheetOrder } }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub buildWorkbook |
174
|
|
|
|
|
|
|
{ |
175
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
176
|
0
|
|
|
|
|
|
foreach my $worksheet ( $self->getWorksheetsInOrder ) { |
177
|
0
|
|
|
|
|
|
$worksheet->buildWorksheet( $self->formats ); |
178
|
|
|
|
|
|
|
} |
179
|
0
|
|
|
|
|
|
$self->excelWorkbook->close; |
180
|
0
|
|
|
|
|
|
return 1; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub getFormat |
184
|
|
|
|
|
|
|
{ |
185
|
0
|
|
|
0
|
0
|
|
my($self,$name) = @_; |
186
|
0
|
0
|
|
|
|
|
return undef unless exists $self->formats->{ $name }; |
187
|
0
|
|
|
|
|
|
return $self->formats->{ $name }; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub excelFh |
191
|
|
|
|
|
|
|
{ |
192
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
193
|
0
|
0
|
|
|
|
|
if( @_ ) { |
194
|
0
|
|
|
|
|
|
$self->{'_excelFh'} = shift; |
195
|
|
|
|
|
|
|
} |
196
|
0
|
|
|
|
|
|
return $self->{'_excelFh'}; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub getSpreadsheetData |
200
|
|
|
|
|
|
|
{ |
201
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
202
|
0
|
|
|
|
|
|
return ${ $self->_buffer }; |
|
0
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub _buffer |
206
|
|
|
|
|
|
|
{ |
207
|
0
|
|
|
0
|
|
|
my $self = shift; |
208
|
0
|
0
|
|
|
|
|
if( @_ ) { |
209
|
0
|
|
|
|
|
|
$self->{'__buffer'} = shift; |
210
|
|
|
|
|
|
|
} |
211
|
0
|
|
|
|
|
|
return $self->{'__buffer'}; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub excelWorkbook |
215
|
|
|
|
|
|
|
{ |
216
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
217
|
0
|
0
|
|
|
|
|
if( @_ ) { |
218
|
0
|
|
|
|
|
|
$self->{'_excelWorkbook'} = shift; |
219
|
|
|
|
|
|
|
} |
220
|
0
|
|
|
|
|
|
return $self->{'_excelWorkbook'}; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub worksheets |
224
|
|
|
|
|
|
|
{ |
225
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
226
|
0
|
0
|
|
|
|
|
if( @_ ) { |
227
|
0
|
|
|
|
|
|
$self->{'_worksheets'} = shift; |
228
|
|
|
|
|
|
|
} |
229
|
0
|
|
|
|
|
|
return $self->{'_worksheets'}; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub formats |
233
|
|
|
|
|
|
|
{ |
234
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
235
|
0
|
0
|
|
|
|
|
if( @_ ) { |
236
|
0
|
|
|
|
|
|
$self->{'_formats'} = shift; |
237
|
|
|
|
|
|
|
} |
238
|
0
|
|
|
|
|
|
return $self->{'_formats'}; |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub worksheetOrder |
242
|
|
|
|
|
|
|
{ |
243
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
244
|
0
|
0
|
|
|
|
|
if( @_ ) { |
245
|
0
|
|
|
|
|
|
$self->{'_worksheetOrder'} = shift; |
246
|
|
|
|
|
|
|
} |
247
|
0
|
|
|
|
|
|
return $self->{'_worksheetOrder'}; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
1; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head1 SEE ALSO |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
SpreadSheet::WriteExcel::FromXML |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 AUTHORS |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
W. Justin Bedard juice@lerch.org |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Kyle R. Burton mortis@voicenet.com, krburton@cpan.org |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=cut |