Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: need program to hang out awhile?

by tokpela (Chaplain)
on Dec 03, 2009 at 10:01 UTC ( #810793=note: print w/replies, xml ) Need Help??

in reply to need program to hang out awhile?

Use Win32::OLE to control Excel and print from within Excel.

I used the code below several years ago to print out an Excel sheet every day. Please note - this code is a snippet and is untested as is.

Hopefully, you can get the idea and adapt to your situation.

use strict; use warnings; use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; my $excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', + 'Quit'); my $book = $excel->Workbooks->Open("I:\\Path\\To\\File\\file +.xls"); my $sheet = $excel->Worksheets(1); #Sub PrintOut([From], [To], [Copies], [Preview], [ActivePrinter], [Pri +ntToFile], [Collate]) $sheet->PrintOut(1,1,1,0,"HP LaserJet IIIP",0,0); $book->Save; $book->Close; print "Done\n";

Replies are listed 'Best First'.
Re^2: need program to hang out awhile?
by cypress (Beadle) on Dec 03, 2009 at 14:22 UTC


    OLE might be a promising trail to follow, but unfortunately I'm on a Mac for this project.

    For a related Windows project, however, I'd like to see your PrintOut sub definition in full.

    Continued thanks,


      The PrintOut() method is defined somewhere inside MS Excel :-)

      Enoch was right!
      Enjoy the last years of Rome.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://810793]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2017-10-23 01:44 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (276 votes). Check out past polls.