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 $GSDLOS=$ENV{'GSDLOS'};
|
---|
21 | my $GSDLHOME=$ENV{'GSDLHOME'};
|
---|
22 | if ($GSDLOS =~ /^windows/i) {
|
---|
23 | $xlhtml_binary.=".exe";
|
---|
24 | }
|
---|
25 |
|
---|
26 | # Trouble happens if there are spaces in GSDLHOME. Assume that on windows
|
---|
27 | # the program is found in the path.
|
---|
28 | if ($GSDLOS !~ /windows/i && -x "$GSDLHOME/bin/$GSDLOS/$xlhtml_binary") {
|
---|
29 | $xlhtml_binary="$GSDLHOME/bin/$GSDLOS/$xlhtml_binary";
|
---|
30 | }
|
---|
31 |
|
---|
32 | if (! -r $input_xls) {
|
---|
33 | print STDERR "Unable to read file `$input_xls'\n";
|
---|
34 | exit (1);
|
---|
35 | }
|
---|
36 |
|
---|
37 | my $return_value=
|
---|
38 | system("$xlhtml_binary \"$input_xls\" > \"$output_html\"");
|
---|
39 |
|
---|
40 | if ($return_value != 0) {
|
---|
41 | exit (1);
|
---|
42 | }
|
---|
43 |
|
---|
44 | # Ok, we made an html file. Check to see if it has any content, and remove
|
---|
45 | # the little nag link at the the bottom.
|
---|
46 | my $html="";
|
---|
47 | open (HTML, "$output_html") || die "Can't read file:$!";
|
---|
48 | $html=join('', <HTML>);
|
---|
49 | close HTML;
|
---|
50 |
|
---|
51 | $html =~ s@<hr><FONT SIZE=-1>Created with.*\n</BODY></HTML>$@</BODY></HTML>@s;
|
---|
52 |
|
---|
53 | # xlHtml uses the filename as the title.
|
---|
54 | # HTMLPlug will use the first 100 chars instead if there's no title.
|
---|
55 | # Don't know if that's a good idea with a spreadsheet, though...
|
---|
56 | $html =~ s@<title>.*?\.xls</title>@<title></title>@i;
|
---|
57 |
|
---|
58 | my $tmp=$html;
|
---|
59 | $tmp =~ s/^.*?<BODY>//ms;
|
---|
60 | $tmp =~ s/( )|\s//gims;
|
---|
61 | if ($tmp !~ m/(>[^<]+<)/) {
|
---|
62 | print STDERR "No text found in extracted html file!\n";
|
---|
63 | exit(1);
|
---|
64 | }
|
---|
65 | open (NEWHTML, ">$output_html") || die "Can't create file:$!";
|
---|
66 | print NEWHTML $html;
|
---|
67 | close NEWHTML;
|
---|
68 | exit (0);
|
---|
69 |
|
---|