line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SWISH::Filters::XLtoHTML; |
2
|
1
|
|
|
1
|
|
690
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
3
|
|
|
|
|
|
|
require File::Spec; |
4
|
1
|
|
|
1
|
|
4
|
use vars qw( $VERSION @ISA ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
575
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.191'; |
6
|
|
|
|
|
|
|
@ISA = ('SWISH::Filters::Base'); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
1
|
|
|
1
|
0
|
22
|
my ($class) = @_; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
10
|
my $self |
12
|
|
|
|
|
|
|
= bless { |
13
|
|
|
|
|
|
|
mimetypes => [ qr!application/vnd.ms-excel!, qr!application/excel!, ], |
14
|
|
|
|
|
|
|
}, $class; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
12
|
return $self->use_modules(qw( Spreadsheet::ParseExcel )); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub filter { |
21
|
0
|
|
|
0
|
1
|
|
my ( $self, $doc ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# We need a file name to pass to the conversion function |
24
|
0
|
|
|
|
|
|
my $file = $doc->fetch_filename; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my ( $content_ref, $meta ) = $self->get_xls_content_ref( $file, $doc ); |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
return unless $content_ref; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# update the document's content type |
31
|
0
|
|
|
|
|
|
$doc->set_content_type('text/html'); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# If filtered must return either a reference to the doc or a pathname. |
34
|
0
|
|
|
|
|
|
return ( \$content_ref, $meta ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get_xls_content_ref { |
39
|
0
|
|
|
0
|
0
|
|
my ( $self, $file, $doc ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $oExcel = Spreadsheet::ParseExcel->new; |
42
|
0
|
0
|
|
|
|
|
return unless $oExcel; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
0
|
|
|
|
my $oBook = $oExcel->Parse($file) || return; |
45
|
0
|
|
|
|
|
|
my ( $iR, $iC, $oWkS, $oWkC, $ExcelWorkBook ); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# gather up all the workbook metadata |
48
|
0
|
|
|
|
|
|
my ( $vol, $dirs, $filename ) = File::Spec->splitpath( $oBook->{File} ); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
0
|
|
|
|
my $user_meta = $doc->meta_data || {}; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
0
|
|
|
|
my %meta = ( |
|
|
|
0
|
|
|
|
|
53
|
|
|
|
|
|
|
Filename => $filename, |
54
|
|
|
|
|
|
|
Version => $oBook->{Version} || '', |
55
|
|
|
|
|
|
|
Author => $oBook->{Author} || '', |
56
|
|
|
|
|
|
|
Sheetcount => $oBook->{SheetCount} |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$meta{$_} = $user_meta->{$_} for keys %$user_meta; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $title = join( ' ', |
62
|
|
|
|
|
|
|
$oBook->{Worksheet}[0]->{Name}, |
63
|
|
|
|
|
|
|
$filename, 'v.' . $meta{Version} ); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $html = join( "\n", |
66
|
|
|
|
|
|
|
'', '', |
67
|
|
|
|
|
|
|
'' . $self->escapeXML($title) . '', |
68
|
|
|
|
|
|
|
$self->format_meta_headers( \%meta ), '' ); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$html .= "\n"; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Here we collect content from each worksheet |
73
|
0
|
|
|
|
|
|
for ( my $iSheet = 0; $iSheet < $oBook->{SheetCount}; $iSheet++ ) { |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# For each Worksheet do the following |
76
|
0
|
|
|
|
|
|
$oWkS = $oBook->{Worksheet}[$iSheet]; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Name of the worksheet |
79
|
0
|
|
|
|
|
|
my $ExcelWorkSheet |
80
|
|
|
|
|
|
|
= "" . $self->escapeXML( $oWkS->{Name} ) . "\n"; |
81
|
0
|
|
|
|
|
|
$ExcelWorkSheet .= "\n";
82
|
|
|
|
|
|
|
|
83
|
0
|
|
0
|
|
|
|
for ( |
84
|
|
|
|
|
|
|
my $iR = $oWkS->{MinRow}; |
85
|
|
|
|
|
|
|
defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow}; |
86
|
|
|
|
|
|
|
$iR++ |
87
|
|
|
|
|
|
|
) |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# For each row do the following |
91
|
0
|
|
|
|
|
|
$ExcelWorkSheet .= " | \n";
92
|
|
|
|
|
|
|
|
93
|
0
|
|
0
|
|
|
|
for ( |
94
|
|
|
|
|
|
|
my $iC = $oWkS->{MinCol}; |
95
|
|
|
|
|
|
|
defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol}; |
96
|
|
|
|
|
|
|
$iC++ |
97
|
|
|
|
|
|
|
) |
98
|
|
|
|
|
|
|
{ |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# For each cell do the following |
101
|
0
|
|
|
|
|
|
$oWkC = $oWkS->{Cells}[$iR][$iC]; |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
my $CellData = $self->escapeXML( $oWkC->Value ) if ($oWkC); |
104
|
0
|
0
|
|
|
|
|
$ExcelWorkSheet .= "\t | " . $CellData . " | \n"
105
|
|
|
|
|
|
|
if $CellData; |
106
|
|
|
|
|
|
|
} |
107
|
0
|
|
|
|
|
|
$ExcelWorkSheet .= " | \n";
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Our last duty |
110
|
0
|
|
|
|
|
|
$ExcelWorkBook .= $ExcelWorkSheet; |
111
|
0
|
|
|
|
|
|
$ExcelWorkSheet = ""; |
112
|
|
|
|
|
|
|
} |
113
|
0
|
|
|
|
|
|
$ExcelWorkBook .= " | \n"; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$html .= <
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$ExcelWorkBook |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
EOF |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# include title in meta for return |
124
|
0
|
|
|
|
|
|
$meta{title} = $title; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
return ( $html, \%meta ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |