Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
while invoking Excel through perl I am getting the following error?? Any ideas ? Please let me know.

Win32::OLE(0.1501) error 0x800401f3: "Invalid class string" at c:\test1.cgi line 21
eval {...} called at c:\test1.cgi line 21

*** I am invoking the following in cgi
use strict; use CGI qw(:standard); use Cwd; use Win32::OLE; use Win32::OLE qw(in with); $Win32::OLE::Warn = 3; my $application = Win32::OLE->new('Excel.Application', 'Quit') || die "Oops, cannot start Excel";
Thanks in advance,

Edit kudra, 2002-05-06 Added code tags

Replies are listed 'Best First'.
(jeffa) Re: Error invoking Excel through cgi
by jeffa (Bishop) on May 06, 2002 at 22:14 UTC
    Hi Raj. This is possibly Off-Topic, but here goes!

    I was successfully able to serve up dynamic Excel files via the Apache Web Server to a web browser about a year ago. I went digging up through my file system and found this snippet. This is meant for a *NIX box, by the way - this might cause a problem when trying to write the temporary file on Win32 boxes.

    use strict; use CGI qw(header); use POSIX; use Spreadsheet::WriteExcel; my $tmp_file = tmpnam(); { my $workbook = Spreadsheet::WriteExcel->new($tmp_file) or die; my $worksheet = $workbook->addworksheet() or die; my $format = $workbook->addformat() or die; $format->set_bold(); $format->set_color('red'); $format->set_align('center'); $worksheet->write(0, 0, "Hi Excel!"); $worksheet->write(1, 0, 1.2345); $worksheet->write(2, 0, "Hi Excel!", $format); } open(FH,$tmp_file) or die; print header(-type=>'application/'); print while <FH>; unlink $tmp_file;
    If the user's Win32 box has Excel installed, Internet Explorer will use OLE to display the spreadsheet right in the browser. A catch is that the .cgi extension will confuse non-savvy users who don't know to save the file with a .xls extension instead. But ...

    A really nice feature of the Apache web server is being able to specify your own extensions for CGI scripts. By adding this line to your <Directory> directive:

    AddHandler cgi-script .xls
    Now the Excel file can be saved 'as-is' without having to worry about getting the extension right.


    (the triplet paradiddle with high-hat)
Re: Error invoking Excel through cgi
by schumi (Hermit) on May 06, 2002 at 19:50 UTC
    Hi there!

    The only thing I can see this bit of code that I'd change is the following:

    $Win32::OLE::Warn = 3;

    looks better to me written like

    Win32::OLE->Option(Warn => 3);

    Apart from that, I think without getting the ominous line 21, it seems hard to help you there.


    There are nights when the wolves are silent and only the moon howls. - George Carlin