| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Spreadsheet::SimpleExcel; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
94310
|
use 5.006; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
88
|
|
|
4
|
2
|
|
|
2
|
|
13
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
162
|
|
|
5
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
|
2
|
|
|
|
|
9
|
|
|
|
2
|
|
|
|
|
72
|
|
|
6
|
2
|
|
|
2
|
|
9119
|
use Spreadsheet::WriteExcel; |
|
|
2
|
|
|
|
|
232823
|
|
|
|
2
|
|
|
|
|
95
|
|
|
7
|
2
|
|
|
2
|
|
2640
|
use IO::Scalar; |
|
|
2
|
|
|
|
|
9691
|
|
|
|
2
|
|
|
|
|
100
|
|
|
8
|
2
|
|
|
2
|
|
16
|
use IO::File; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
326
|
|
|
9
|
2
|
|
|
2
|
|
1933
|
use XML::Writer; |
|
|
2
|
|
|
|
|
16723
|
|
|
|
2
|
|
|
|
|
10907
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.9'; |
|
12
|
|
|
|
|
|
|
our $errstr = ''; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new{ |
|
15
|
3
|
|
|
3
|
1
|
148
|
my ($class,%opts) = @_; |
|
16
|
3
|
|
|
|
|
8
|
my $self = {}; |
|
17
|
3
|
|
100
|
|
|
30
|
$self->{worksheets} = $opts{-worksheets} || []; |
|
18
|
3
|
|
|
|
|
12
|
$self->{type} = 'application/vnd.ms-excel'; |
|
19
|
3
|
|
50
|
|
|
144
|
$self->{BIG} = $opts{-big} || 0; |
|
20
|
3
|
|
50
|
|
|
37
|
$self->{FILE} = $opts{-filename} || ''; |
|
21
|
3
|
|
|
|
|
9
|
bless($self,$class); |
|
22
|
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
6
|
for my $sheet( @{ $self->{worksheets} } ){ |
|
|
3
|
|
|
|
|
18
|
|
|
24
|
1
|
50
|
|
|
|
6
|
if( length($sheet->[0]) > 31 ){ |
|
25
|
0
|
|
|
|
|
0
|
warn "length of worksheet name is greater than 31. It is truncated..."; |
|
26
|
0
|
|
|
|
|
0
|
$sheet->[0] = substr $sheet->[0], 0, 30; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
16
|
$self->_last_sheet(''); |
|
31
|
|
|
|
|
|
|
|
|
32
|
3
|
|
|
|
|
11
|
return $self; |
|
33
|
|
|
|
|
|
|
}# end new |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub current_sheet{ |
|
36
|
3
|
|
|
3
|
1
|
1481
|
my ($self) = @_; |
|
37
|
3
|
|
|
|
|
10
|
return $self->_last_sheet; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub add_worksheet{ |
|
41
|
5
|
|
|
5
|
1
|
1002
|
my ($self,@array) = @_; |
|
42
|
5
|
|
|
|
|
15
|
my ($package,$filename,$line) = caller(); |
|
43
|
5
|
50
|
|
|
|
18
|
unless(defined $array[0]){ |
|
44
|
0
|
|
|
|
|
0
|
$errstr = qq~No worksheet defined at Spreadsheet::SimpleExcel add_worksheet() from |
|
45
|
|
|
|
|
|
|
$filename line $line\n~; |
|
46
|
0
|
0
|
|
|
|
0
|
$array[0] = 'unknown' unless defined $array[0]; |
|
47
|
0
|
|
|
|
|
0
|
return undef; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
5
|
50
|
|
|
|
18
|
if( length( $array[0] ) > 31 ){ |
|
51
|
0
|
|
|
|
|
0
|
$errstr = qq~Length of worksheet name has be at most 31~; |
|
52
|
0
|
|
|
|
|
0
|
return undef; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
5
|
|
|
|
|
15
|
$self->_last_sheet($array[0]); |
|
56
|
|
|
|
|
|
|
|
|
57
|
5
|
50
|
|
|
|
8
|
if(grep{$_->[0] eq $array[0]}@{$self->{worksheets}}){ |
|
|
4
|
|
|
|
|
14
|
|
|
|
5
|
|
|
|
|
18
|
|
|
58
|
0
|
|
|
|
|
0
|
$errstr = qq~Duplicate worksheet-title at Spreadsheet::SimpleExcel add_worksheet() from |
|
59
|
|
|
|
|
|
|
$filename line $line\n~; |
|
60
|
0
|
|
|
|
|
0
|
return undef; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
5
|
|
|
|
|
7
|
push(@{$self->{worksheets}},[@array]); |
|
|
5
|
|
|
|
|
27
|
|
|
63
|
5
|
|
|
|
|
12
|
return 1; |
|
64
|
|
|
|
|
|
|
}# end add_worksheet |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _last_sheet{ |
|
67
|
101
|
|
|
101
|
|
107
|
my ($self,$title) = @_; |
|
68
|
|
|
|
|
|
|
|
|
69
|
101
|
100
|
|
|
|
191
|
$self->{last_sheet} = $title if defined $title; |
|
70
|
|
|
|
|
|
|
|
|
71
|
101
|
|
|
|
|
180
|
return $self->{last_sheet}; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub del_worksheet{ |
|
75
|
1
|
|
|
1
|
1
|
3
|
my ($self,$title) = @_; |
|
76
|
1
|
|
|
|
|
4
|
my ($package,$filename,$line) = caller(); |
|
77
|
|
|
|
|
|
|
|
|
78
|
1
|
50
|
|
|
|
4
|
$title = $self->_last_sheet unless defined $title; |
|
79
|
1
|
|
|
|
|
3
|
$self->_last_sheet( $title ); |
|
80
|
|
|
|
|
|
|
|
|
81
|
1
|
50
|
|
|
|
3
|
unless(defined $title){ |
|
82
|
0
|
|
|
|
|
0
|
$errstr = qq~No worksheet-title defined at Spreadsheet::SimpleExcel del_worksheet() from |
|
83
|
|
|
|
|
|
|
$filename line $line\n~; |
|
84
|
0
|
|
|
|
|
0
|
return undef; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
1
|
|
|
|
|
3
|
my @worksheets = grep{$_->[0] ne $title}@{$self->{worksheets}}; |
|
|
3
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
3
|
|
|
87
|
1
|
|
|
|
|
4
|
$self->{worksheets} = [@worksheets]; |
|
88
|
|
|
|
|
|
|
}# end del_worksheet |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub add_row{ |
|
91
|
43
|
|
|
43
|
1
|
137
|
my ($self,$title,$arref,$props) = @_; |
|
92
|
43
|
|
|
|
|
83
|
my ($package,$filename,$line) = caller(); |
|
93
|
|
|
|
|
|
|
|
|
94
|
43
|
100
|
|
|
|
92
|
if(ref $title eq 'ARRAY'){ |
|
95
|
42
|
|
|
|
|
36
|
$props = $arref; |
|
96
|
42
|
|
|
|
|
38
|
$arref = $title; |
|
97
|
42
|
|
|
|
|
69
|
$title = $self->_last_sheet; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
43
|
50
|
|
|
|
74
|
$title = $self->_last_sheet unless $title; |
|
101
|
43
|
|
|
|
|
63
|
$self->_last_sheet( $title ); |
|
102
|
|
|
|
|
|
|
|
|
103
|
43
|
50
|
|
|
|
47
|
unless(grep{$_->[0] eq $title}@{$self->{worksheets}}){ |
|
|
85
|
|
|
|
|
234
|
|
|
|
43
|
|
|
|
|
64
|
|
|
104
|
0
|
|
|
|
|
0
|
$errstr = qq~Worksheet $title does not exist at Spreadsheet::SimpleExcel add_row() from |
|
105
|
|
|
|
|
|
|
$filename line $line\n~; |
|
106
|
0
|
|
|
|
|
0
|
return undef; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
43
|
50
|
|
|
|
83
|
unless(ref($arref) eq 'ARRAY'){ |
|
109
|
0
|
|
|
|
|
0
|
$errstr = qq~Is not an arrayref at Spreadsheet::SimpleExcel add_row() from |
|
110
|
|
|
|
|
|
|
$filename line $line\n~; |
|
111
|
0
|
|
|
|
|
0
|
return undef; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
43
|
|
|
|
|
45
|
foreach my $worksheet(@{$self->{worksheets}}){ |
|
|
43
|
|
|
|
|
70
|
|
|
114
|
85
|
100
|
|
|
|
150
|
if($worksheet->[0] eq $title){ |
|
115
|
43
|
|
|
|
|
36
|
push(@{$worksheet->[1]->{'-data'}},$arref); |
|
|
43
|
|
|
|
|
76
|
|
|
116
|
43
|
|
|
|
|
48
|
last; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} |
|
119
|
43
|
|
|
|
|
86
|
return 1; |
|
120
|
|
|
|
|
|
|
}# end add_data |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub set_headers{ |
|
123
|
1
|
|
|
1
|
1
|
9
|
my ($self,$title,$arref,$props) = @_; |
|
124
|
1
|
|
|
|
|
6
|
my ($package,$filename,$line) = caller(); |
|
125
|
|
|
|
|
|
|
|
|
126
|
1
|
50
|
|
|
|
5
|
if(ref $title eq 'ARRAY'){ |
|
127
|
0
|
|
|
|
|
0
|
$props = $arref; |
|
128
|
0
|
|
|
|
|
0
|
$arref = $title; |
|
129
|
0
|
|
|
|
|
0
|
$title = $self->_last_sheet; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
1
|
|
33
|
|
|
4
|
$title ||= $self->_last_sheet; |
|
133
|
1
|
|
|
|
|
4
|
$self->_last_sheet( $title ); |
|
134
|
|
|
|
|
|
|
|
|
135
|
1
|
50
|
|
|
|
1
|
unless(grep{$_->[0] eq $title}@{$self->{worksheets}}){ |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
3
|
|
|
136
|
0
|
|
|
|
|
0
|
$errstr = qq~Worksheet $title does not exist at Spreadsheet::SimpleExcel set_headers() from |
|
137
|
|
|
|
|
|
|
$filename line $line\n~; |
|
138
|
0
|
|
|
|
|
0
|
return undef; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
1
|
50
|
|
|
|
5
|
unless(ref($arref) eq 'ARRAY'){ |
|
141
|
0
|
|
|
|
|
0
|
$errstr = qq~Is not an arrayref at Spreadsheet::SimpleExcel set_headers() from |
|
142
|
|
|
|
|
|
|
$filename line $line\n~; |
|
143
|
0
|
|
|
|
|
0
|
return undef; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
1
|
|
|
|
|
2
|
foreach my $worksheet(@{$self->{worksheets}}){ |
|
|
1
|
|
|
|
|
4
|
|
|
146
|
1
|
50
|
|
|
|
2
|
if($worksheet->[0] eq $title){ |
|
147
|
1
|
|
|
|
|
3
|
$worksheet->[1]->{'-headers'} = $arref; |
|
148
|
1
|
|
|
|
|
3
|
last; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
} |
|
151
|
1
|
|
|
|
|
2
|
return 1; |
|
152
|
|
|
|
|
|
|
}# end add_headers |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub set_headers_format{ |
|
155
|
0
|
|
|
0
|
1
|
0
|
my ($self,$title,$arref) = @_; |
|
156
|
0
|
|
|
|
|
0
|
my ($package,$filename,$line) = caller(); |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
0
|
if(ref $title eq 'ARRAY'){ |
|
159
|
0
|
|
|
|
|
0
|
$arref = $title; |
|
160
|
0
|
|
|
|
|
0
|
$title = $self->_last_sheet; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
0
|
0
|
|
|
|
0
|
$title = $self->_last_sheet unless defined $title; |
|
164
|
0
|
|
|
|
|
0
|
$self->_last_sheet( $title ); |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
0
|
unless(grep{$_->[0] eq $title}@{$self->{worksheets}}){ |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
167
|
0
|
|
|
|
|
0
|
$errstr = qq~Worksheet $title does not exist at Spreadsheet::SimpleExcel set_headers_format() from |
|
168
|
|
|
|
|
|
|
$filename line $line\n~; |
|
169
|
0
|
|
|
|
|
0
|
return undef; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
0
|
0
|
|
|
|
0
|
unless(ref($arref) eq 'ARRAY'){ |
|
172
|
0
|
|
|
|
|
0
|
$errstr = qq~Is not an arrayref at Spreadsheet::SimpleExcel set_headers_format() from |
|
173
|
|
|
|
|
|
|
$filename line $line\n~; |
|
174
|
0
|
|
|
|
|
0
|
return undef; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
0
|
|
|
|
|
0
|
foreach my $worksheet(@{$self->{worksheets}}){ |
|
|
0
|
|
|
|
|
0
|
|
|
177
|
0
|
0
|
|
|
|
0
|
if($worksheet->[0] eq $title){ |
|
178
|
0
|
|
|
|
|
0
|
$worksheet->[1]->{'-headers_format'} = $arref; |
|
179
|
0
|
|
|
|
|
0
|
last; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
} |
|
182
|
0
|
|
|
|
|
0
|
return 1; |
|
183
|
|
|
|
|
|
|
}# end add_headers |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub set_data_format{ |
|
186
|
0
|
|
|
0
|
1
|
0
|
my ($self,$title,$arref) = @_; |
|
187
|
0
|
|
|
|
|
0
|
my ($package,$filename,$line) = caller(); |
|
188
|
|
|
|
|
|
|
|
|
189
|
0
|
0
|
|
|
|
0
|
if(ref $title eq 'ARRAY'){ |
|
190
|
0
|
|
|
|
|
0
|
$arref = $title; |
|
191
|
0
|
|
|
|
|
0
|
$title = $self->_last_sheet; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
0
|
0
|
|
|
|
0
|
$title = $self->_last_sheet unless defined $title; |
|
195
|
0
|
|
|
|
|
0
|
$self->_last_sheet( $title ); |
|
196
|
|
|
|
|
|
|
|
|
197
|
0
|
0
|
|
|
|
0
|
unless(grep{$_->[0] eq $title}@{$self->{worksheets}}){ |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
198
|
0
|
|
|
|
|
0
|
$errstr = qq~Worksheet $title does not exist at Spreadsheet::SimpleExcel set_data_format() from |
|
199
|
|
|
|
|
|
|
$filename line $line\n~; |
|
200
|
0
|
|
|
|
|
0
|
return undef; |
|
201
|
|
|
|
|
|
|
} |
|
202
|
0
|
0
|
|
|
|
0
|
unless(ref($arref) eq 'ARRAY'){ |
|
203
|
0
|
|
|
|
|
0
|
$errstr = qq~Is not an arrayref at Spreadsheet::SimpleExcel set_data_format() from |
|
204
|
|
|
|
|
|
|
$filename line $line\n~; |
|
205
|
0
|
|
|
|
|
0
|
return undef; |
|
206
|
|
|
|
|
|
|
} |
|
207
|
0
|
|
|
|
|
0
|
foreach my $worksheet(@{$self->{worksheets}}){ |
|
|
0
|
|
|
|
|
0
|
|
|
208
|
0
|
0
|
|
|
|
0
|
if($worksheet->[0] eq $title){ |
|
209
|
0
|
|
|
|
|
0
|
$worksheet->[1]->{'-data_format'} = $arref; |
|
210
|
0
|
|
|
|
|
0
|
last; |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
} |
|
213
|
0
|
|
|
|
|
0
|
return 1; |
|
214
|
|
|
|
|
|
|
}# end add_headers |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub add_row_at{ |
|
217
|
1
|
|
|
1
|
1
|
3
|
my ($self,$title,$index,$arref,$props) = @_; |
|
218
|
1
|
|
|
|
|
24
|
my ($package,$filename,$line) = caller(); |
|
219
|
|
|
|
|
|
|
|
|
220
|
1
|
50
|
|
|
|
5
|
if(ref $index eq 'ARRAY'){ |
|
221
|
0
|
|
|
|
|
0
|
$props = $arref; |
|
222
|
0
|
|
|
|
|
0
|
$arref = $index; |
|
223
|
0
|
|
|
|
|
0
|
$index = $title; |
|
224
|
0
|
|
|
|
|
0
|
$title = $self->_last_sheet; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
1
|
50
|
|
|
|
4
|
$title = $self->_last_sheet unless defined $title; |
|
228
|
1
|
|
|
|
|
3
|
$self->_last_sheet( $title ); |
|
229
|
|
|
|
|
|
|
|
|
230
|
1
|
50
|
|
|
|
1
|
unless(grep{$_->[0] eq $title}@{$self->{worksheets}}){ |
|
|
3
|
|
|
|
|
11
|
|
|
|
1
|
|
|
|
|
4
|
|
|
231
|
0
|
|
|
|
|
0
|
$errstr = qq~Worksheet $title does not exist at Spreadsheet::SimpleExcel add_row_at() from |
|
232
|
|
|
|
|
|
|
$filename line $line\n~; |
|
233
|
0
|
|
|
|
|
0
|
return undef; |
|
234
|
|
|
|
|
|
|
} |
|
235
|
1
|
50
|
|
|
|
5
|
unless(ref($arref) eq 'ARRAY'){ |
|
236
|
0
|
|
|
|
|
0
|
$errstr = qq~Is not an arrayref at Spreadsheet::SimpleExcel add_row() from |
|
237
|
|
|
|
|
|
|
$filename line $line\n~; |
|
238
|
0
|
|
|
|
|
0
|
return undef; |
|
239
|
|
|
|
|
|
|
} |
|
240
|
1
|
|
|
|
|
2
|
foreach my $worksheet(@{$self->{worksheets}}){ |
|
|
1
|
|
|
|
|
4
|
|
|
241
|
1
|
50
|
|
|
|
4
|
if($worksheet->[0] eq $title){ |
|
242
|
1
|
|
|
|
|
2
|
my @array = @{$worksheet->[1]->{'-data'}}; |
|
|
1
|
|
|
|
|
3
|
|
|
243
|
1
|
50
|
33
|
|
|
9
|
if($index =~ /[^\d]/ || $index > $#array){ |
|
244
|
0
|
|
|
|
|
0
|
$errstr = qq~Index not in Array at Spreadsheet::SimpleExcel add_row_at() from |
|
245
|
|
|
|
|
|
|
$filename line $line\n~; |
|
246
|
0
|
|
|
|
|
0
|
return undef; |
|
247
|
|
|
|
|
|
|
} |
|
248
|
1
|
|
|
|
|
2
|
splice(@array,$index,0,$arref); |
|
249
|
1
|
|
|
|
|
3
|
$worksheet->[1]->{'-data'} = \@array; |
|
250
|
1
|
|
|
|
|
3
|
last; |
|
251
|
|
|
|
|
|
|
} |
|
252
|
|
|
|
|
|
|
} |
|
253
|
1
|
|
|
|
|
2
|
return 1; |
|
254
|
|
|
|
|
|
|
}# end add_row_at |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub sort_data{ |
|
257
|
2
|
|
|
2
|
1
|
245
|
my ($self,$title,$index,$type) = @_; |
|
258
|
2
|
|
|
|
|
7
|
my ($package,$filename,$line) = caller(); |
|
259
|
|
|
|
|
|
|
|
|
260
|
2
|
50
|
|
|
|
24
|
if(scalar @_ == 1){ |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
261
|
0
|
|
|
|
|
0
|
$errstr = qq~at least column index is missing ($filename line $line)~; |
|
262
|
0
|
|
|
|
|
0
|
return undef; |
|
263
|
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
elsif(scalar @_ == 2){ |
|
265
|
0
|
0
|
|
|
|
0
|
if($title =~ /\D/){ |
|
266
|
0
|
|
|
|
|
0
|
$errstr = qq~Index not in Array at Spreadsheet::SimpleExcel sort_data() from |
|
267
|
|
|
|
|
|
|
$filename line $line\n~; |
|
268
|
0
|
|
|
|
|
0
|
return undef; |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
} |
|
271
|
|
|
|
|
|
|
else{ |
|
272
|
0
|
|
|
|
|
0
|
$index = $title; |
|
273
|
0
|
|
|
|
|
0
|
$title = $self->_last_sheet; |
|
274
|
|
|
|
|
|
|
} |
|
275
|
|
|
|
|
|
|
} |
|
276
|
|
|
|
|
|
|
elsif(scalar @_ == 3){ |
|
277
|
0
|
0
|
0
|
|
|
0
|
if($title =~ /^\d+$/ and $index =~ /^ASC|DESC$/){ |
|
278
|
0
|
|
|
|
|
0
|
$type = $index; |
|
279
|
0
|
|
|
|
|
0
|
$index = $title; |
|
280
|
0
|
|
|
|
|
0
|
$title = $self->_last_sheet; |
|
281
|
|
|
|
|
|
|
} |
|
282
|
|
|
|
|
|
|
} |
|
283
|
|
|
|
|
|
|
|
|
284
|
2
|
50
|
|
|
|
8
|
$title = $self->_last_sheet unless defined $title; |
|
285
|
2
|
|
50
|
|
|
21
|
$type ||= 'ASC'; |
|
286
|
|
|
|
|
|
|
|
|
287
|
2
|
|
|
|
|
6
|
$self->_last_sheet( $title ); |
|
288
|
|
|
|
|
|
|
|
|
289
|
2
|
50
|
|
|
|
2
|
unless(grep{$_->[0] eq $title}@{$self->{worksheets}}){ |
|
|
4
|
|
|
|
|
18
|
|
|
|
2
|
|
|
|
|
17
|
|
|
290
|
0
|
|
|
|
|
0
|
$errstr = qq~Worksheet $title does not exist at Spreadsheet::SimpleExcel sort_data() from |
|
291
|
|
|
|
|
|
|
$filename line $line\n~; |
|
292
|
0
|
|
|
|
|
0
|
return undef; |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
|
|
295
|
2
|
|
|
|
|
4
|
foreach my $worksheet(@{$self->{worksheets}}){ |
|
|
2
|
|
|
|
|
5
|
|
|
296
|
2
|
50
|
|
|
|
14
|
if($worksheet->[0] eq $title){ |
|
297
|
2
|
50
|
|
|
|
12
|
$worksheet->[1]->{sortstring} = '' unless(exists $worksheet->[1]->{sortstring}); |
|
298
|
2
|
50
|
|
|
|
16
|
my $join = $worksheet->[1]->{sortstring} =~ /\w/ ? ' || ' : ''; |
|
299
|
2
|
|
|
|
|
3
|
my @array = @{$worksheet->[1]->{'-data'}}; |
|
|
2
|
|
|
|
|
9
|
|
|
300
|
2
|
50
|
|
|
|
8
|
last unless(scalar(@array) > 0); |
|
301
|
2
|
100
|
|
|
|
21
|
if($index >= scalar(@{$array[0]})){ |
|
|
2
|
|
|
|
|
8
|
|
|
302
|
1
|
|
|
|
|
4
|
$errstr = qq~Index not in Array at Spreadsheet::SimpleExcel sort_data() from |
|
303
|
|
|
|
|
|
|
$filename line $line\n~; |
|
304
|
1
|
|
|
|
|
4
|
return undef; |
|
305
|
|
|
|
|
|
|
} |
|
306
|
1
|
50
|
33
|
|
|
6
|
if(not defined $index || $index =~ /\D/){ |
|
307
|
0
|
|
|
|
|
0
|
$errstr = qq~Index not in Array at Spreadsheet::SimpleExcel sort_data() from |
|
308
|
|
|
|
|
|
|
$filename line $line\n~; |
|
309
|
0
|
|
|
|
|
0
|
return undef; |
|
310
|
|
|
|
|
|
|
} |
|
311
|
1
|
50
|
|
|
|
4
|
if(_is_numeric(\@array,$index)){ |
|
312
|
0
|
0
|
0
|
|
|
0
|
if($type && $type eq 'DESC'){ |
|
313
|
0
|
|
|
|
|
0
|
$worksheet->[1]->{sortstring} .= "$join \$b->[$index] <=> \$a->[$index]"; |
|
314
|
|
|
|
|
|
|
} |
|
315
|
|
|
|
|
|
|
else{ |
|
316
|
0
|
|
|
|
|
0
|
$worksheet->[1]->{sortstring} .= "$join \$a->[$index] <=> \$b->[$index]"; |
|
317
|
|
|
|
|
|
|
} |
|
318
|
|
|
|
|
|
|
} |
|
319
|
|
|
|
|
|
|
else{ |
|
320
|
1
|
50
|
33
|
|
|
8
|
if($type && $type eq 'DESC'){ |
|
321
|
1
|
|
|
|
|
4
|
$worksheet->[1]->{sortstring} .= "$join \$b->[$index] cmp \$a->[$index]"; |
|
322
|
|
|
|
|
|
|
} |
|
323
|
|
|
|
|
|
|
else{ |
|
324
|
0
|
|
|
|
|
0
|
$worksheet->[1]->{sortstring} .= "$join \$a->[$index] cmp \$b->[$index]"; |
|
325
|
|
|
|
|
|
|
} |
|
326
|
|
|
|
|
|
|
} |
|
327
|
1
|
|
|
|
|
4
|
last; |
|
328
|
|
|
|
|
|
|
} |
|
329
|
|
|
|
|
|
|
} |
|
330
|
1
|
|
|
|
|
14
|
return 1; |
|
331
|
|
|
|
|
|
|
}# end sort_data |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
sub reset_sort{ |
|
334
|
0
|
|
|
0
|
1
|
0
|
my ($self,$title) = @_; |
|
335
|
0
|
|
|
|
|
0
|
my ($package,$filename,$line) = caller(); |
|
336
|
|
|
|
|
|
|
|
|
337
|
0
|
0
|
|
|
|
0
|
$title = $self->_last_sheet unless defined $title; |
|
338
|
0
|
|
|
|
|
0
|
$self->_last_sheet( $title ); |
|
339
|
|
|
|
|
|
|
|
|
340
|
0
|
0
|
|
|
|
0
|
unless(grep{$_->[0] eq $title}@{$self->{worksheets}}){ |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
341
|
0
|
|
|
|
|
0
|
$errstr = qq~Worksheet $title does not exist at Spreadsheet::SimpleExcel add_row_at() from |
|
342
|
|
|
|
|
|
|
$filename line $line\n~; |
|
343
|
0
|
|
|
|
|
0
|
return undef; |
|
344
|
|
|
|
|
|
|
} |
|
345
|
0
|
|
|
|
|
0
|
my (@worksheets) = grep{$_->[0] eq $title}@{$self->{worksheets}}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
346
|
0
|
|
|
|
|
0
|
for my $sheet(@worksheets){ |
|
347
|
0
|
|
|
|
|
0
|
$sheet->[1]->{sortstring} = ''; |
|
348
|
|
|
|
|
|
|
} |
|
349
|
|
|
|
|
|
|
}# reset_sort |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
sub errstr{ |
|
352
|
1
|
|
|
1
|
1
|
6
|
return $errstr; |
|
353
|
|
|
|
|
|
|
}# end errstr |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
sub sort_worksheets{ |
|
356
|
1
|
|
|
1
|
1
|
512
|
my ($self,$type) = @_; |
|
357
|
1
|
|
50
|
|
|
4
|
$type ||= 'ASC'; |
|
358
|
|
|
|
|
|
|
|
|
359
|
1
|
|
|
|
|
3
|
my @title_array = map{$_->[0]}@{$self->{worksheets}}; |
|
|
2
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
2
|
|
|
360
|
1
|
50
|
|
|
|
8
|
if( _is_title_numeric(\@title_array) ){ |
|
361
|
0
|
|
|
|
|
0
|
@{$self->{worksheets}} = sort{$a->[0] <=> $b->[0]}@{$self->{worksheets}}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
362
|
|
|
|
|
|
|
} |
|
363
|
|
|
|
|
|
|
else{ |
|
364
|
1
|
|
|
|
|
2
|
@{$self->{worksheets}} = sort{$a->[0] cmp $b->[0]}@{$self->{worksheets}}; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
7
|
|
|
365
|
|
|
|
|
|
|
} |
|
366
|
1
|
50
|
33
|
|
|
17
|
@{$self->{worksheets}} = reverse(@{$self->{worksheets}}) if($type && $type eq 'DESC'); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
2
|
|
|
367
|
1
|
|
|
|
|
2
|
return @{$self->{worksheets}}; |
|
|
1
|
|
|
|
|
4
|
|
|
368
|
|
|
|
|
|
|
}# end sort_worksheets |
|
369
|
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
sub _is_numeric{ |
|
371
|
1
|
|
|
1
|
|
2
|
my ($arref,$index) = @_; |
|
372
|
1
|
|
|
|
|
3
|
foreach(@$arref){ |
|
373
|
1
|
50
|
|
|
|
8
|
return 0 if($_->[$index] =~ /[^\d\.]/); |
|
374
|
|
|
|
|
|
|
} |
|
375
|
0
|
|
|
|
|
0
|
return 1; |
|
376
|
|
|
|
|
|
|
}# end _is_numeric |
|
377
|
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
sub _is_title_numeric{ |
|
380
|
1
|
|
|
1
|
|
3
|
my ($arref,$index) = @_; |
|
381
|
1
|
|
|
|
|
3
|
foreach(@$arref){ |
|
382
|
1
|
50
|
|
|
|
9
|
return 0 if($_ =~ /[^\d\.]/); |
|
383
|
|
|
|
|
|
|
} |
|
384
|
0
|
|
|
|
|
0
|
return 1; |
|
385
|
|
|
|
|
|
|
}# end _is_numeric |
|
386
|
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
sub _do_sort{ |
|
388
|
11
|
|
|
11
|
|
19
|
my ($worksheet) = @_; |
|
389
|
11
|
|
|
|
|
18
|
my @array = @{$worksheet->[1]->{'-data'}}; |
|
|
11
|
|
|
|
|
53
|
|
|
390
|
11
|
100
|
66
|
|
|
94
|
if(exists $worksheet->[1]->{sortstring} && |
|
|
|
|
100
|
|
|
|
|
|
391
|
|
|
|
|
|
|
defined $worksheet->[1]->{sortstring} && |
|
392
|
|
|
|
|
|
|
$worksheet->[1]->{sortstring} =~ /\w/){ |
|
393
|
4
|
|
|
|
|
23
|
$worksheet->[1]->{-data} = [sort{eval($worksheet->[1]->{sortstring})}@array]; |
|
|
12
|
|
|
|
|
800
|
|
|
394
|
|
|
|
|
|
|
} |
|
395
|
|
|
|
|
|
|
}# _do_sort |
|
396
|
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
sub output{ |
|
398
|
2
|
|
|
2
|
1
|
514
|
my ($self,$lines) = @_; |
|
399
|
2
|
|
|
|
|
5
|
my ($package,$filename,$line) = caller(); |
|
400
|
2
|
|
50
|
|
|
9
|
$lines ||= 32000; |
|
401
|
2
|
|
|
|
|
7
|
$lines =~ s/\D//g; |
|
402
|
2
|
|
|
|
|
8
|
my $excel = $self->_make_excel($lines); |
|
403
|
2
|
50
|
|
|
|
467
|
unless(defined $excel){ |
|
404
|
0
|
|
|
|
|
0
|
$errstr = qq~Could not create Spreadsheet at Spreadsheet::SimpleExcel output() from |
|
405
|
|
|
|
|
|
|
$filename line $line\n~; |
|
406
|
0
|
|
|
|
|
0
|
return undef; |
|
407
|
|
|
|
|
|
|
} |
|
408
|
2
|
|
|
|
|
91
|
print "Content-type: ".$self->{type}."\n\n", |
|
409
|
|
|
|
|
|
|
$excel; |
|
410
|
|
|
|
|
|
|
}# end output |
|
411
|
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
sub output_as_string{ |
|
413
|
1
|
|
|
1
|
1
|
7
|
my ($self,$lines) = @_; |
|
414
|
1
|
|
|
|
|
5
|
my ($package,$filename,$line) = caller(); |
|
415
|
1
|
|
50
|
|
|
9
|
$lines ||= 32000; |
|
416
|
1
|
|
|
|
|
4
|
$lines =~ s/\D//g; |
|
417
|
1
|
|
|
|
|
5
|
my $excel = $self->_make_excel($lines); |
|
418
|
1
|
50
|
|
|
|
214
|
unless(defined $excel){ |
|
419
|
0
|
|
|
|
|
0
|
$errstr = qq~Could not create Spreadsheet at Spreadsheet::SimpleExcel output_to_file() from |
|
420
|
|
|
|
|
|
|
$filename line $line\n~; |
|
421
|
0
|
|
|
|
|
0
|
return undef; |
|
422
|
|
|
|
|
|
|
} |
|
423
|
1
|
|
|
|
|
5
|
return $excel; |
|
424
|
|
|
|
|
|
|
}# end output_as_string |
|
425
|
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
sub output_to_file{ |
|
427
|
3
|
|
|
3
|
1
|
16
|
my ($self,$filename,$lines) = @_; |
|
428
|
3
|
|
|
|
|
13
|
my ($package,$file,$line) = caller(); |
|
429
|
3
|
|
100
|
|
|
21
|
$lines ||= 32000; |
|
430
|
3
|
|
|
|
|
11
|
$lines =~ s/\D//g; |
|
431
|
3
|
50
|
|
|
|
9
|
unless($filename){ |
|
432
|
0
|
0
|
|
|
|
0
|
if($self->{FILE}){ |
|
433
|
0
|
|
|
|
|
0
|
$filename = $self->{FILE}; |
|
434
|
|
|
|
|
|
|
} |
|
435
|
|
|
|
|
|
|
else{ |
|
436
|
0
|
|
|
|
|
0
|
$errstr = qq~No filename specified at Spreadsheet::SimpleExcel output_to_file() from |
|
437
|
|
|
|
|
|
|
$file line $line\n~; |
|
438
|
0
|
|
|
|
|
0
|
return undef; |
|
439
|
|
|
|
|
|
|
} |
|
440
|
|
|
|
|
|
|
} |
|
441
|
|
|
|
|
|
|
#$filename =~ s/[^A-Za-z0-9_\.\/]//g; #/ |
|
442
|
3
|
|
|
|
|
13
|
my $excel = $self->_make_excel($lines); |
|
443
|
3
|
50
|
|
|
|
773
|
unless(defined $excel){ |
|
444
|
0
|
|
|
|
|
0
|
$errstr = qq~Could not create $filename at Spreadsheet::SimpleExcel output_to_file() from |
|
445
|
|
|
|
|
|
|
$file line $line\n~; |
|
446
|
0
|
|
|
|
|
0
|
return undef; |
|
447
|
|
|
|
|
|
|
} |
|
448
|
3
|
50
|
|
|
|
276
|
open(EXCEL,">$filename") or die $!; |
|
449
|
3
|
|
|
|
|
9
|
binmode EXCEL; |
|
450
|
3
|
|
|
|
|
38
|
print EXCEL $excel; |
|
451
|
3
|
|
|
|
|
127
|
close EXCEL; |
|
452
|
3
|
|
|
|
|
14
|
return 1; |
|
453
|
|
|
|
|
|
|
}# end output_to_file |
|
454
|
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
sub output_to_XML{ |
|
456
|
2
|
|
|
2
|
1
|
340
|
my ($self,$filename) = @_; |
|
457
|
2
|
|
|
|
|
8
|
my ($package,$file,$line) = caller(); |
|
458
|
2
|
50
|
|
|
|
9
|
unless($filename){ |
|
459
|
0
|
|
|
|
|
0
|
$errstr = qq~No filename specified at Spreadsheet::SimpleExcel output_to_XML() from |
|
460
|
|
|
|
|
|
|
$file line $line\n~; |
|
461
|
0
|
|
|
|
|
0
|
return undef; |
|
462
|
|
|
|
|
|
|
} |
|
463
|
2
|
50
|
|
|
|
3
|
unless(scalar(@{$self->{worksheets}}) >= 1){ |
|
|
2
|
|
|
|
|
9
|
|
|
464
|
0
|
|
|
|
|
0
|
$errstr = qq~No worksheets in Spreadsheet~; |
|
465
|
0
|
|
|
|
|
0
|
return undef; |
|
466
|
|
|
|
|
|
|
} |
|
467
|
|
|
|
|
|
|
|
|
468
|
2
|
|
|
|
|
96
|
my $fh = IO::File->new(">$filename");
|
|
469
|
2
|
|
|
|
|
322
|
my $xml = XML::Writer->new(OUTPUT => $fh, DATA_MODE => 1, DATA_INDENT => 2);
|
|
470
|
2
|
|
|
|
|
434
|
$xml->xmlDecl('UTF-8','yes'); |
|
471
|
2
|
|
|
|
|
190
|
$xml->startTag('workbook'); |
|
472
|
2
|
|
|
|
|
114
|
for my $worksheet(@{$self->{worksheets}}){ |
|
|
2
|
|
|
|
|
5
|
|
|
473
|
2
|
|
|
|
|
5
|
my $name = $worksheet->[0]; |
|
474
|
2
|
|
|
|
|
11
|
$name =~ s~[^\w]~_~g; |
|
475
|
2
|
|
|
|
|
7
|
$xml->startTag($name); |
|
476
|
|
|
|
|
|
|
|
|
477
|
2
|
|
|
|
|
86
|
my @headers; |
|
478
|
2
|
|
|
|
|
4
|
my @datasets = @{$worksheet->[1]->{-data}}; |
|
|
2
|
|
|
|
|
25
|
|
|
479
|
2
|
50
|
|
|
|
15
|
if(exists $worksheet->[1]->{-headers}){ |
|
480
|
2
|
|
|
|
|
4
|
@headers = (@{$worksheet->[1]->{-headers}}); |
|
|
2
|
|
|
|
|
8
|
|
|
481
|
2
|
|
|
|
|
5
|
for(@headers){ |
|
482
|
6
|
|
|
|
|
15
|
s~[^\w]~_~g; |
|
483
|
|
|
|
|
|
|
} |
|
484
|
|
|
|
|
|
|
} |
|
485
|
|
|
|
|
|
|
else{ |
|
486
|
0
|
|
|
|
|
0
|
my $var = 'A'; |
|
487
|
0
|
|
|
|
|
0
|
for(0..scalar(@{$datasets[0]})-1){ |
|
|
0
|
|
|
|
|
0
|
|
|
488
|
0
|
|
|
|
|
0
|
++$var; |
|
489
|
0
|
|
|
|
|
0
|
push(@headers,$var); |
|
490
|
|
|
|
|
|
|
} |
|
491
|
|
|
|
|
|
|
} |
|
492
|
2
|
|
|
|
|
4
|
my $row = 0; |
|
493
|
2
|
|
|
|
|
5
|
for my $data(@datasets){ |
|
494
|
45
|
|
|
|
|
1370
|
$xml->startTag('Row'.(++$row)); |
|
495
|
45
|
|
|
|
|
2021
|
for my $i(0..scalar(@$data)-1){ |
|
496
|
90
|
|
|
|
|
1107
|
$xml->startTag($headers[$i]); |
|
497
|
90
|
|
|
|
|
4240
|
$xml->characters($data->[$i]); |
|
498
|
90
|
|
|
|
|
1720
|
$xml->endTag($headers[$i]); |
|
499
|
|
|
|
|
|
|
} |
|
500
|
45
|
|
|
|
|
981
|
$xml->endTag('Row'.$row); |
|
501
|
|
|
|
|
|
|
} |
|
502
|
|
|
|
|
|
|
|
|
503
|
2
|
|
|
|
|
67
|
$xml->endTag($name); |
|
504
|
|
|
|
|
|
|
} |
|
505
|
2
|
|
|
|
|
72
|
$xml->endTag('workbook'); |
|
506
|
2
|
|
|
|
|
66
|
$xml->end(); |
|
507
|
2
|
|
|
|
|
61
|
$fh->close(); |
|
508
|
|
|
|
|
|
|
}# output_to_XML |
|
509
|
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
sub _make_excel{ |
|
511
|
6
|
|
|
6
|
|
9
|
my ($self,$nr_of_lines) = @_; |
|
512
|
6
|
|
|
|
|
18
|
my ($package,$filename,$line) = caller(); |
|
513
|
6
|
|
50
|
|
|
20
|
my $c_lines = $nr_of_lines || 32000; |
|
514
|
6
|
50
|
|
|
|
9
|
unless(scalar(@{$self->{worksheets}}) >= 1){ |
|
|
6
|
|
|
|
|
21
|
|
|
515
|
0
|
|
|
|
|
0
|
$errstr = qq~No worksheets in Spreadsheet~; |
|
516
|
0
|
|
|
|
|
0
|
return undef; |
|
517
|
|
|
|
|
|
|
} |
|
518
|
6
|
|
|
|
|
10
|
my $output; |
|
519
|
6
|
|
|
|
|
55
|
tie(*XLS,'IO::Scalar',\$output); |
|
520
|
6
|
|
|
|
|
566
|
my $excel; |
|
521
|
6
|
50
|
|
|
|
47
|
unless($excel = new Spreadsheet::WriteExcel(\*XLS)){ |
|
522
|
0
|
|
|
|
|
0
|
$errstr = qq~Could not create spreadsheet object ($!) from |
|
523
|
|
|
|
|
|
|
$filename line $line~; |
|
524
|
0
|
|
|
|
|
0
|
return undef; |
|
525
|
|
|
|
|
|
|
} |
|
526
|
6
|
50
|
|
|
|
36309
|
if($self->{BIG}){ |
|
527
|
0
|
|
|
|
|
0
|
eval{require Spreadsheet::WriteExcel::Big}; |
|
|
0
|
|
|
|
|
0
|
|
|
528
|
0
|
0
|
|
|
|
0
|
if($@){ |
|
529
|
0
|
|
|
|
|
0
|
$errstr = $@; |
|
530
|
0
|
|
|
|
|
0
|
return undef; |
|
531
|
|
|
|
|
|
|
} |
|
532
|
0
|
0
|
|
|
|
0
|
unless($excel = new Spreadsheet::WriteExcel::Big(\*XLS)){#$fname)){ |
|
533
|
0
|
|
|
|
|
0
|
$errstr = qq~Could not create spreadsheet object ($!) from |
|
534
|
|
|
|
|
|
|
$filename line $line~; |
|
535
|
0
|
|
|
|
|
0
|
return undef; |
|
536
|
|
|
|
|
|
|
} |
|
537
|
|
|
|
|
|
|
} |
|
538
|
|
|
|
|
|
|
#else{ |
|
539
|
6
|
|
|
|
|
13
|
my @titles = map{$_->[0]}@{$self->{worksheets}}; |
|
|
11
|
|
|
|
|
42
|
|
|
|
6
|
|
|
|
|
23
|
|
|
540
|
6
|
|
|
|
|
11
|
foreach my $worksheet(@{$self->{worksheets}}){ |
|
|
6
|
|
|
|
|
20
|
|
|
541
|
11
|
|
|
|
|
66
|
my $sheet = $excel->addworksheet($worksheet->[0]); |
|
542
|
11
|
|
|
|
|
4373
|
_do_sort($worksheet); |
|
543
|
11
|
|
|
|
|
22
|
my $col = 0; |
|
544
|
11
|
|
|
|
|
16
|
my $row = 0; |
|
545
|
11
|
|
|
|
|
14
|
my $page = 2; |
|
546
|
11
|
|
|
|
|
68
|
_header2sheet($sheet,$worksheet->[1]->{-headers},$worksheet->[1]->{-headers_format}); |
|
547
|
11
|
100
|
66
|
|
|
57
|
$row++ if(exists $worksheet->[1]->{'-headers'} && scalar(@{$worksheet->[1]->{'-headers'}}) > 0); |
|
|
6
|
|
|
|
|
80
|
|
|
548
|
11
|
|
|
|
|
19
|
foreach my $data(@{$worksheet->[1]->{-data}}){ |
|
|
11
|
|
|
|
|
36
|
|
|
549
|
107
|
|
|
|
|
107
|
$col = 0; |
|
550
|
107
|
50
|
|
|
|
193
|
if($row >= $c_lines){ |
|
551
|
0
|
|
|
|
|
0
|
my $title = $worksheet->[0].'_p'.$page; |
|
552
|
0
|
|
|
|
|
0
|
while(grep{$_ eq $title}@titles){ |
|
|
0
|
|
|
|
|
0
|
|
|
553
|
0
|
|
|
|
|
0
|
$page++; |
|
554
|
0
|
|
|
|
|
0
|
$title = $worksheet->[0].'_p'.$page; |
|
555
|
|
|
|
|
|
|
} |
|
556
|
0
|
|
|
|
|
0
|
push(@titles,$title); |
|
557
|
0
|
|
|
|
|
0
|
$sheet = $excel->addworksheet($title); |
|
558
|
0
|
|
|
|
|
0
|
$row = 0; |
|
559
|
0
|
0
|
|
|
|
0
|
if(scalar(@{$worksheet->[1]->{'-headers'}}) > 0){ |
|
|
0
|
|
|
|
|
0
|
|
|
560
|
0
|
|
|
|
|
0
|
$row = 1; |
|
561
|
0
|
|
|
|
|
0
|
_header2sheet($sheet,$worksheet->[1]->{-headers},$worksheet->[1]->{-headers_format}); |
|
562
|
|
|
|
|
|
|
} |
|
563
|
|
|
|
|
|
|
} |
|
564
|
107
|
|
|
|
|
185
|
my $formatref = $worksheet->[1]->{-data_format}; |
|
565
|
107
|
|
|
|
|
161
|
foreach my $value(@$data){ |
|
566
|
214
|
50
|
33
|
|
|
467
|
if(defined $formatref && defined $formatref->[$col]){ |
|
567
|
0
|
0
|
|
|
|
0
|
if($formatref->[$col] eq 's'){ |
|
|
|
0
|
|
|
|
|
|
|
568
|
0
|
|
|
|
|
0
|
$sheet->write_string($row,$col,$value); |
|
569
|
|
|
|
|
|
|
} |
|
570
|
|
|
|
|
|
|
elsif($formatref->[$col] eq 'n'){ |
|
571
|
0
|
|
|
|
|
0
|
$sheet->write_number($row,$col,$value); |
|
572
|
|
|
|
|
|
|
} |
|
573
|
|
|
|
|
|
|
else{ |
|
574
|
0
|
|
|
|
|
0
|
$sheet->write($row,$col,$value); |
|
575
|
|
|
|
|
|
|
} |
|
576
|
|
|
|
|
|
|
} |
|
577
|
|
|
|
|
|
|
#elsif($value =~ /^=/){ |
|
578
|
|
|
|
|
|
|
# $sheet->write_string($row,$col,$value); |
|
579
|
|
|
|
|
|
|
#} |
|
580
|
|
|
|
|
|
|
else{ |
|
581
|
214
|
|
|
|
|
503
|
$sheet->write($row,$col,$value); |
|
582
|
|
|
|
|
|
|
} |
|
583
|
214
|
|
|
|
|
13805
|
$col++; |
|
584
|
|
|
|
|
|
|
} |
|
585
|
107
|
|
|
|
|
185
|
$row++; |
|
586
|
|
|
|
|
|
|
} |
|
587
|
|
|
|
|
|
|
} |
|
588
|
6
|
|
|
|
|
44
|
$excel->close(); |
|
589
|
|
|
|
|
|
|
#} |
|
590
|
6
|
|
|
|
|
47543
|
return $output; |
|
591
|
|
|
|
|
|
|
}# end _make_excel |
|
592
|
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
sub _header2sheet{ |
|
594
|
11
|
|
|
11
|
|
30
|
my ($sheet,$arref,$formatref) = @_; |
|
595
|
11
|
|
|
|
|
17
|
my $col = 0; |
|
596
|
11
|
|
|
|
|
32
|
foreach(@$arref){ |
|
597
|
14
|
50
|
33
|
|
|
44
|
unless(defined $formatref && defined $formatref->[$col]){ |
|
598
|
14
|
|
|
|
|
45
|
$sheet->write(0,$col,$_); |
|
599
|
|
|
|
|
|
|
} |
|
600
|
|
|
|
|
|
|
else{ |
|
601
|
0
|
0
|
|
|
|
0
|
if($formatref->[$col] eq 's'){ |
|
|
|
0
|
|
|
|
|
|
|
602
|
0
|
|
|
|
|
0
|
$sheet->write_string(0,$col,$_); |
|
603
|
|
|
|
|
|
|
} |
|
604
|
|
|
|
|
|
|
elsif($formatref->[$col] eq 'n'){ |
|
605
|
0
|
|
|
|
|
0
|
$sheet->write_number(0,$col,$_); |
|
606
|
|
|
|
|
|
|
} |
|
607
|
|
|
|
|
|
|
else{ |
|
608
|
0
|
|
|
|
|
0
|
$sheet->write(0,$col,$_); |
|
609
|
|
|
|
|
|
|
} |
|
610
|
|
|
|
|
|
|
} |
|
611
|
14
|
|
|
|
|
1172
|
$col++; |
|
612
|
|
|
|
|
|
|
} |
|
613
|
|
|
|
|
|
|
}# end _header2sheet |
|
614
|
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
sub sheets{ |
|
616
|
4
|
|
|
4
|
1
|
18
|
my ($self) = @_; |
|
617
|
4
|
|
|
|
|
6
|
my @titles = map{$_->[0]}@{$self->{worksheets}}; |
|
|
8
|
|
|
|
|
20
|
|
|
|
4
|
|
|
|
|
10
|
|
|
618
|
4
|
100
|
|
|
|
18
|
return wantarray ? @titles : \@titles; |
|
619
|
|
|
|
|
|
|
}# end sheets |
|
620
|
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
1; |
|
622
|
|
|
|
|
|
|
__END__ |