Hi all,
I'm a little bit confused about the following behavior of the
Win32::OLE Module.
My goal is to print a Word.doc by using
Win32::OLE. This is quite simple.
But now I want to be able to select a file from a menu and put some more Information to the file, print it and store the additional information in a DB.
This little example shows the problem:
use strict;
use Win32::OLE::Const 'Microsoft Word';
use Tk;
#### my $mw = MainWindow->new;
my $file = "c:\\TEMP\\test.doc";
my $Word = Win32::OLE->new('Word.Application', 'Quit');
$Word->Documents->Open($file) || die("Unable to open document", Win32:
+:OLE->LastError());
my $last_printer=$Word->{ActivePrinter};
$Word->{ActivePrinter} ='PS2FILE';
$Word->ActiveDocument->PrintOut({
Background => 0,
Append => 0,
Range => wdPrintAllDocument,
Item => wdPrintDocumentContent,
Copies => 1,
PageType => wdPrintAllPages,
});
$Word->{ActivePrinter} = $last_printer;
### MainLoop;
The upper example works great
use strict;
use Win32::OLE::Const 'Microsoft Word';
use Tk;
my $mw = MainWindow->new;
my $file = "c:\\TEMP\\test.doc";
my $Word = Win32::OLE->new('Word.Application', 'Quit');
$Word->Documents->Open($file) || die("Unable to open document", Win32:
+:OLE->LastError());
my $last_printer=$Word->{ActivePrinter};
$Word->{ActivePrinter} ='PS2FILE';
$Word->ActiveDocument->PrintOut({
Background => 0,
Append => 0,
Range => wdPrintAllDocument,
Item => wdPrintDocumentContent,
Copies => 1,
PageType => wdPrintAllPages,
});
$Word->{ActivePrinter} = $last_printer;
MainLoop;
and now it doesn't anymore
The only diffence between them is that I open a Tk MainWindow in the second example. Nothing else. You can bring the second one to run, if you delete either the
$mw = MainwWindow ... or the
$Word->{ActivePrinter} ='PS2FILE' line.
So what's going on here ? Why does this OLE-set-a-Active-Printer Action doesn't work with a Tk widget ?
Any suggestions are very welcome ..
-----------------------------------
--the good, the bad and the physi--
-----------------------------------
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.