1 | eval 'exec perl -x -- $0 $@'
|
---|
2 | if 0;
|
---|
3 | #! perl
|
---|
4 | # line 6
|
---|
5 |
|
---|
6 | sub usage() {
|
---|
7 | print "$0 <input.xls> <output.html>\n";
|
---|
8 | }
|
---|
9 |
|
---|
10 |
|
---|
11 | if (@ARGV != 2) {
|
---|
12 | usage();
|
---|
13 | exit(1);
|
---|
14 | }
|
---|
15 | my $input_xls=shift;
|
---|
16 | my $output_html=shift;
|
---|
17 |
|
---|
18 | # try to find xlhtml binary in GSDLHOME
|
---|
19 | my $xlhtml_binary="xlhtml";
|
---|
20 | my $os_exeext="";
|
---|
21 | my $GSDLOS=$ENV{'GSDLOS'};
|
---|
22 | my $GSDLHOME=$ENV{'GSDLHOME'};
|
---|
23 | if ($GSDLOS =~ /^windows$/i) {
|
---|
24 | $os_exeext=".exe";
|
---|
25 | }
|
---|
26 |
|
---|
27 | if (-x "$GSDLHOME/bin/$GSDLOS/xlhtml$os_exeext") {
|
---|
28 | $xlhtml_binary="$GSDLHOME/bin/$GSDLOS/xlhtml$os_exeext";
|
---|
29 | }
|
---|
30 |
|
---|
31 | if (! -r $input_xls) {
|
---|
32 | print STDERR "Unable to read file `$input_xls'\n";
|
---|
33 | exit (1);
|
---|
34 | }
|
---|
35 |
|
---|
36 | my $return_value=
|
---|
37 | system("$xlhtml_binary \"$input_xls\" > \"$output_html\"");
|
---|
38 |
|
---|
39 | if ($return_value != 0) {
|
---|
40 | exit (1);
|
---|
41 | }
|
---|
42 |
|
---|
43 | # Ok, we made an html file. Check to see if it has any content, and remove
|
---|
44 | # the little nag link at the the bottom.
|
---|
45 | my $html="";
|
---|
46 | open (HTML, "$output_html") || die "Can't read file:$!";
|
---|
47 | $html=join('', <HTML>);
|
---|
48 | close HTML;
|
---|
49 |
|
---|
50 | $html =~ s@<hr><FONT SIZE=-1>Created with.*\n</BODY></HTML>$@</BODY></HTML>@s;
|
---|
51 |
|
---|
52 | # HTMLPlug will use the first 100 chars instead if there's no title.
|
---|
53 | # Don't think that's a good idea with a spreadsheet, though...
|
---|
54 | # $html =~ s@<title>.*?\.xls</title>@<title></title>@i;
|
---|
55 |
|
---|
56 | my $tmp=$html;
|
---|
57 | $tmp =~ s/^.*?<BODY>//ms;
|
---|
58 | $tmp =~ s/( )|\s//gims;
|
---|
59 | if ($tmp !~ m/(>[^<]+<)/) {
|
---|
60 | print STDERR "No text found in extracted html file!\n";
|
---|
61 | exit(1);
|
---|
62 | }
|
---|
63 | open (NEWHTML, ">$output_html") || die "Can't create file:$!";
|
---|
64 | print NEWHTML $html;
|
---|
65 | close NEWHTML;
|
---|
66 | exit (0);
|
---|
67 |
|
---|