in reply to Modifying an existing Excel file

By chance I also asked about facilities to modify Excel using Perl ealier today.
It may be worth your while looking at the replies to my questions that I found very useful.

Replies are listed 'Best First'.
Re^2: Modifying an existing Excel file
by Joost (Canon) on May 04, 2005 at 22:39 UTC
      Thanks guys. I am using a machine with office. I took a look at Win32::OLE. It should be able to do it. But Is there some sample code that can help me out? I tried the sample that was in the documentations. This is what I tried but it doesn't seem to work:
      use Win32::OLE; $doc = 'Smoke_Test.xls'; $ex = Win32::OLE->GetObject($doc); # get a new workbook $book = $ex->Workbooks->Add; # write to a particular cell $sheet = $book->Worksheets("Sheet1"); $sheet->Cells(1,1)->{Value} = "foo"; undef $book; undef $ex; __END__

      2005-05-05 code tags added by Arunbear

        I'm not sure exactly what your problem is - starting Excel, opening the file or entering data - and obviously I don't have your "smoke test" file. Amending the code to create a new spreadsheet, this works on my system:
        use strict; use Win32::OLE; #$doc = 'Smoke_Test.xls'; #$ex = Win32::OLE->GetObject($doc); my $ex = Win32::OLE->new('Excel.Application'); $ex->{Visible} = 1; $ex->{SheetsInNewWorkbook} = 1; # get a new workbook #$book = $ex->Workbooks->Add; my $book = $ex->Workbooks->Add; # write to a particular cell #$sheet = $book->Worksheets("Sheet1"); my $sheet = $book->Worksheets("Sheet1"); $sheet->Cells(1,1)->{Value} = "foo"; undef $book; undef $ex; exit(0);
        It works just as well without the "undef" commands.

        Regards,

        John Davies
        I have found another reference of an 'old' Monk's page.
        Sadly I do not know how to give you a link.
        However I can tell you that its title is
        Using Win32::OLE and Excel - Tips and Tricks
        and it was by cacharbe on Mar 22, 2002 at 04:56 UTC.
        This does have useful examples.