Hi I had this unique issue with setting page margins for a word file using Win32::OLE
The ides is to set right and left margins for any word document.
here is the snippet of code i am having trouble with :
$margins_hash{LeftMargin} = $left_margin;
$margins_hash{RightMargin} = $right_margin);
with(
$ExcelObject->{ActiveDocument}->{PageSetup},
%margins_hash
);
The issue with this is that if the papersize is such that width is 8 and the initial right margin for the document before editing was 7.
the Win32::OLE::with function sets the margins in sequence and not together. so if i want to set margins to 2 and 2 in the file, I won't be able to do that since when OLE tries to set the left margin to 2 the word app croaks, since the right margin is still 7 and paper size is 8 so can't have left and right margins of 7 and 2 for a paper width of 8.
the with in VBA allows this adjustment when we pass multiple params to the VBA with() , so I looked into the Win32/OLE/Lite.pm and saw that the with() function is simply a perl implementation of the VBA function which traverses the hash the perl way without any adjustments as required above. Does anyone know a way I can resolve the issue. An obvious hack around this issue is to set both margins to 0 first and then to the desired value but i wish there was a cleaner way to do this. Maybe by calling the VBA with() directly in some way. Just blurbing in the dark here, would appreciate some pointers.
Regards,
Shantanu Bhadoria
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.