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

That thread was "Reading & Writing Excel Spreadsheets"

Linked for your convenience :-)

Replies are listed 'Best First'.
Re^3: Modifying an existing Excel file
by toncelli (Initiate) on May 04, 2005 at 23:04 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.
        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.