How to print (on Windows ) from perl

Hi gurus -

I have a program that reads a mysql database and outputs a spreadsheet -

Is there a way to get it to print off to the default printer automatically -

Or maybe write out the file - then get a 2nd program to read the directory and if there is a document , then print it out .....

Can you give me a few pointers ?

thanks in advance .....

    Rab
rab54Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RanjeetRainCommented:
Which spreadsheet format are you going to output it to? Of course you need to tell us, your OS platform too.

On windows you can simple shell out the document with a '/P' switch. Generally, on Windows platform that switch causes the host application to print it using the default printer.

If your OS/spreadsheet doesn't support that, let us know.
0
RanjeetRainCommented:
Oh my!! Sorry, i see that you wrote "print (on Windows ) from "...

Need galsses????
0
rab54Author Commented:
I have used the system command within perl to print a test file

eg - system "type $file > $printer";

This works ok until I try a spreadsheet - doh !

I just need a dos command to print say -

c:/test.xls

I had no joy with PRINT and /P either .....

cheers
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

RanjeetRainCommented:
Nope. Try this:

cmd start %1 /p
0
rab54Author Commented:
Can you tell me what this actually does ?

eg 'start' ,%1 /p etc ...

sorry to be numb ...
0
RanjeetRainCommented:
cmd is the command line processor on Windows NT. Its equivalent on Windows 9x is Command.com Its kind of a shell program. It can be used to execute other programs as well.

'Start' is a means to launch an executable file or a document file with the help of an application registered to handle that particular document type.

/P is a switch generally used by Windows applications to quitely print a document.

Hope that helps!
0
rab54Author Commented:
ok i am trying this within my perl program -

system "cmd start perl.exe $file/P";

But still having no joy -

Does the above mean use perl to run the program in $file ?

But $file is a spreadsheet .... not a perl program -

Thanks for the continued help .... I feel like a blindman in the dark ..... ;~)
0
rab54Author Commented:
OK cheers guys -

Got it sorted using Win32::OLE

rab
0
RanjeetRainCommented:
Its good that you found a solution. Can you please post your relevent code for us.
0
rab54Author Commented:
No problem mate -

If you see the code below - it reads in the selected spreadsheet -
we get the default printer using the ActivePrinter method - assign it and bingo !

There is an option to output to another file if needed -

Hope this is of help to others -

cheers

 Rab

ps - Obviously you will need to install the Win32::OLE module first ;~)

################### code #########################
$Win32::OLE::Warn = 3;                                # die on errors...

use Win32::OLE qw(in);
    use Win32::OLE::Const;
    my $Class = "Excel.Application";
   
    my $File  = "path\to_file";
   
    my $Excel = Win32::OLE->GetActiveObject( $Class );
    if (!($Excel))
    {
        $Excel = new Win32::OLE($Class, \&QuitApp ) ||
                 die "Could not cretate an OLE '$Class' object";
    }
    $Excel->{Visible} = 1;
#    my $Book = $Excel->Workbooks->Open( $File ); # open the file
#    my $count = $Book->Worksheets()->{Count};
#    print("There's $count worksheets in $File\n\n");
 
 my $Book = $Excel->Workbooks->Open( $File);
# above line opens the file
print("Opened file $File...\n");
if (!($Book))
{
    print("Error during open, filename=$File. returning 0.");
    return 0;
}

my $count = $Book->Worksheets()->{Count} || 0;

 
my $pobj = $Excel->ActivePrinter;

## check for correct printer
if ($pobj) { print("Name of default printer =>>$pobj<<\n"); }

$Book->ActiveSheet->Activate();
my @thing = $Book->PrintOut(
{
 #   PrintToFile   => 1,
  # PrToFileName  => "$outfile",
  #  PrToFileName  => "$pobj",
    ActivePrinter => "$pobj",
    Copies        => 1
});

################# end code ########################

0
RanjeetRainCommented:
Your code looks okay. Just that it only prints Excel files. For your question it seemed you wanted to use shell to print *ANY* file in a generic way. Anyway, glad for you that you solved your probolem.
0
moduloCommented:
PAQed with points refunded (125)

modulo
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.