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

Hey there , I konw you can call notepad from a perl program as follow:
system ("notepad file");
but how can I call excel, I need to bring up excel and make it open and excel file.
system ("excel file.xls"); dosn't work
any idea?

Replies are listed 'Best First'.
Re: Calling Excel
by Corion (Patriarch) on May 11, 2004 at 06:39 UTC

    Most likely it didn't work from the command line for you either.

    This is because notepad.exe is in the program search path ($ENV{PATH}), while excel.exe is not.

    You should use fully qualified program names and the list form of system(), but you still have to find Excel for yourself:

    use strict; my $excel = 'c:/Programs/Microsoft Office/Excel/excel.exe'; my $file = "c:\\path\\to\\my test.xls"; # note that Excel might want the filename delimited # with backslashes system( $excel, $file ) == 0 or die "Couldn't start Excel: $^E / $! / $?";

    Another possibility is to rely on Windows to do the Right Thing and just let the default Windows action on a .xls file take place:

    use strict; my $file = "c:\\path\\to\\my test.xls"; # note that cmd.exe wants the filename delimited # with backslashes system( 'start', $file );

    And, if you need more control than that, there is always Win32::OLE, with which you can automate Excel:

    use strict; use Win32::OLE; my $excel = Win32::OLE->new( 'Excel.Application' ); my $file = "c:\\path\\to\\my test.xls"; $excel->Open( $file ); # or so I believe. Use the Macro Recorder to find out # what the function names are actually called
Re: Calling Excel
by saintmike (Vicar) on May 11, 2004 at 06:58 UTC
    If you're just looking for a way to create an Excel spreadsheet and manipulate its cells, check out Spreadsheet::WriteExcel and this article explaining (Achtung, German!) an application doing exactly that.