Hi guys,
I'm trying to print a bunch of barcodes, (PNG files I created earlier with GD::Barcode), using Word and the builtin setups for Avery labels. I reckoned this would be easier than getting out a ruler and messing with HTML::Table.
The following code creates a page of the appropriately sized labels, but just inserts all the barcodes into the first cell of the table, rather than a separate barcode into each cell. That's where I'm stuck. I don't have time right now to learn the Word object model, and I need the labels today. Can anyone help?
TIA
Perlcgi
#!perl
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Word';
$Win32::OLE::Warn = 2;
my $Word = Win32::OLE->GetActiveObject('Word.Application')
|| Win32::OLE->new('Word.Application', 'Quit');
$Word->{'Visible'} = 1;
$Word->Documents->Add || die("Unable to create document ",
Win32::OLE->LastError());
my $MyRange = $Word->ActiveDocument->Content;
#Label L7651 is the one we want
$Word->MailingLabel->CreateNewDocument({Name=>'L7651', Address=>"",
AutoText=>"ToolsCreateLabels1",
LaserTray=>wdPrinterManualFeed});
my ($row,$col)=(1,1);
#Each barcode is in a separate file like 99990000.png
for (my $x = 99990000; $x<99990065;$x++) {
my $file = "C:\\mbc\\$x.png";
if ($col > 5) {
$col = 1;
$row++;
}
$Word->ActiveDocument->Tables(1)->Cell($row,$col)->Select;
$Word->Selection->InlineShapes->AddPicture(
{FileName=>$file,
LinkToFile=>'False',
SaveWithDocument=>'True'});
}
print Win32::OLE->LastError();
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.