source: trunk/gsdl/bin/script/xlstohtml.pl@ 2993

Last change on this file since 2993 was 2993, checked in by jrm21, 22 years ago

Decided we should not use the filename as the title, and leave it for HTMLPlug
to guess...

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.5 KB
Line 
1eval 'exec perl -x -- $0 $@'
2 if 0;
3#! perl
4# line 6
5
6sub usage() {
7 print "$0 <input.xls> <output.html>\n";
8}
9
10
11if (@ARGV != 2) {
12 usage();
13 exit(1);
14}
15my $input_xls=shift;
16my $output_html=shift;
17
18# try to find xlhtml binary in GSDLHOME
19my $xlhtml_binary="xlhtml";
20my $os_exeext="";
21my $GSDLOS=$ENV{'GSDLOS'};
22my $GSDLHOME=$ENV{'GSDLHOME'};
23if ($GSDLOS =~ /^windows$/i) {
24 $os_exeext=".exe";
25}
26
27if (-x "$GSDLHOME/bin/$GSDLOS/xlhtml$os_exeext") {
28 $xlhtml_binary="$GSDLHOME/bin/$GSDLOS/xlhtml$os_exeext";
29}
30
31if (! -r $input_xls) {
32 print STDERR "Unable to read file `$input_xls'\n";
33 exit (1);
34}
35
36my $return_value=
37 system("$xlhtml_binary \"$input_xls\" > \"$output_html\"");
38
39if ($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.
45my $html="";
46open (HTML, "$output_html") || die "Can't read file:$!";
47$html=join('', <HTML>);
48close HTML;
49
50$html =~ s@<hr><FONT SIZE=-1>Created with.*\n</BODY></HTML>$@</BODY></HTML>@s;
51
52# xlHtml uses the filename as the title.
53# HTMLPlug will use the first 100 chars instead if there's no title.
54# Don't know if that's a good idea with a spreadsheet, though...
55$html =~ s@<title>.*?\.xls</title>@<title></title>@i;
56
57my $tmp=$html;
58$tmp =~ s/^.*?<BODY>//ms;
59$tmp =~ s/(&nbsp;)|\s//gims;
60if ($tmp !~ m/(>[^<]+<)/) {
61 print STDERR "No text found in extracted html file!\n";
62 exit(1);
63}
64open (NEWHTML, ">$output_html") || die "Can't create file:$!";
65print NEWHTML $html;
66close NEWHTML;
67exit (0);
68
Note: See TracBrowser for help on using the repository browser.