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

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

Do MS Excel file processing, currently using a wrapper around xlhtml.

  • 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# 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
56my $tmp=$html;
57$tmp =~ s/^.*?<BODY>//ms;
58$tmp =~ s/(&nbsp;)|\s//gims;
59if ($tmp !~ m/(>[^<]+<)/) {
60 print STDERR "No text found in extracted html file!\n";
61 exit(1);
62}
63open (NEWHTML, ">$output_html") || die "Can't create file:$!";
64print NEWHTML $html;
65close NEWHTML;
66exit (0);
67
Note: See TracBrowser for help on using the repository browser.