in reply to Re^2: Modifying an existing Excel file
in thread Modifying an existing Excel file

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

Replies are listed 'Best First'.
Re^4: Modifying an existing Excel file
by davies (Monsignor) on May 05, 2005 at 09:11 UTC
    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
Re^4: Modifying an existing Excel file
by merrymonk (Hermit) on May 05, 2005 at 06:46 UTC
    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.
      It's here. There is a link to it in the tutorials section.

      Regards,

      John Davies

      Updated to format the link ITO Nkuvu's request.
        When providing links, please use the [id://153486] syntax. For an explanation of why, try checking out the What shortcuts can I use for linking to other information? documentation. Thanks.

        (In my case, work has Perlmonks.org blocked for some bizarre reason, but not Perlmonks.net or Perlmonks.com)