in reply to Re: Perl r/w Excel with OLE
in thread Perl r/w Excel with OLE
To expand on this, the EXAMPLES section of the Win32::OLE documentation gives a complete walk-through example that shows the quit command for the destructor:
Note that the visible=1 is great for debugging, but shouldn't be used in a production environment once your script is complete. Note also that unless you do a clean quit, then it's possible to have many instances of Excel running, in which case you should make them exit with Task Manager. For cleanly working scripts using the quit idiom shown above, there should only be Excel running when the script is doing whatever it needs to do.use Win32::OLE; # use existing instance if Excel is already running eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')}; die "Excel not installed" if $@; unless (defined $ex) { $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Excel"; } # get a new workbook $book = $ex->Workbooks->Add; # write to a particular cell $sheet = $book->Worksheets(1); $sheet->Cells(1,1)->{Value} = "foo"; # write a 2 rows by 3 columns range $sheet->Range("A8:C9")->{Value} = [[ undef, 'Xyzzy', 'Plugh' ], [ 42, 'Perl', 3.1415 ]]; # print "XyzzyPerl" $array = $sheet->Range("A8:C9")->{Value}; for (@$array) { for (@$_) { print defined($_) ? "$_|" : "<undef>|"; } print "\n"; } # save and exit $book->SaveAs( 'test.xls' ); undef $book; undef $ex;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Perl r/w Excel with OLE
by dasgar (Priest) on Jun 28, 2012 at 17:07 UTC | |
by Sinistral (Monsignor) on Jun 29, 2012 at 16:20 UTC | |
Re^3: Perl r/w Excel with OLE
by davies (Prior) on Jun 28, 2012 at 20:37 UTC | |
by Sinistral (Monsignor) on Jun 29, 2012 at 16:26 UTC | |
by davies (Prior) on Jun 29, 2012 at 16:52 UTC | |
by dasgar (Priest) on Jun 29, 2012 at 18:21 UTC | |
by Sinistral (Monsignor) on Jul 02, 2012 at 15:57 UTC | |
by dasgar (Priest) on Jul 03, 2012 at 03:00 UTC | |
by Anonymous Monk on Jun 29, 2012 at 19:31 UTC |
In Section
Seekers of Perl Wisdom