Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Modifying an existing Excel file

by toncelli (Initiate)
on May 04, 2005 at 21:37 UTC ( [id://454142]=perlquestion: print w/replies, xml ) Need Help??

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

I looked at the modules PERL offers to work with Excel files. It allows you to create a new file or parse an existing one but I found nothing that allows you to modify a specific cell in an existing file. Is there a way?

Replies are listed 'Best First'.
Re: Modifying an existing Excel file
by ikegami (Patriarch) on May 04, 2005 at 21:40 UTC
    It can be done using Win32::OLE, if Excel is installed on the system on which the Perl script is running. (I think it's even be possible to control an Excel on a different machine, if the Perl script is running on a Windows machine.)
Re: Modifying an existing Excel file
by merrymonk (Hermit) on May 04, 2005 at 21:47 UTC
    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.
        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

Re: Modifying an existing Excel file
by Limbic~Region (Chancellor) on May 05, 2005 at 12:57 UTC
      Thanks, I tried the with the sample and as mentioned in the documentation if you have graphs or macros in the same file they will be lost. If it's not possible to modify a the file if it includes graphs, is there a way to recreate the graphs? I can use Spreadsheet::WriteExcel to recreate all the data.
        toncelli,
        Spreadsheet::WriteExcel has experimental support for graphs and I have been able to get them to work. It takes a little practice so see the documentation and examples.

        Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://454142]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-23 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found