Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Excel FitToPages bizarrity

by esr (Scribe)
on Aug 25, 2005 at 21:01 UTC ( #486722=perlquestion: print w/replies, xml ) Need Help??
esr has asked for the wisdom of the Perl Monks concerning the following question:

I have a Perl program which writes some data into an Excel spreadsheet and does some formatting. I had some code in it to scale the spreadsheet using the PageSetup "adjust to percentage" which I needed to modify to use the "fit to pages" function instead. The VBA macro which I generated to see what code was needed indicated that I needed to set the "Zoom" property to "False". The original Perl code I tried was something like:
which gave me an Exception error and didn't work. So I tried setting the value to zero. Same error. Setting the zoom value to a numeric value worked correctly so I knew the rest of the syntax was correct.

The frequently referred to "Using Win32::OLE and Excel - Tips and Tricks" document posted here indicated that the code needed to look like this:

my $vtfalse = Variant(VT_BOOL,0); $sheet->PageSetup->{Zoom}=$vtfalse;
I find this really bizarre. What is the difference between setting the value to zero or "false" and setting it using the variant value? I realize this is only partially a Perl question as it seems the apparent absurity is in the way Microsoft has "designed" the Office object package but I would appreciate any help anyone might be able to offer in understanding this.

Replies are listed 'Best First'.
Re: Excel FitToPages bizarrity
by InfiniteSilence (Curate) on Aug 25, 2005 at 21:20 UTC
    If you have Excel open and open the Visual Basic Editor (macro, edit) try hitting F2 for the object browser window. Type in "Zoom" and Then click on the "Page Setup" Class line...the one with the "Zoom" member. Now look below that pane. Do you notice that the property is a Variant?

    Celebrate Intellectual Diversity

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://486722]
Approved by InfiniteSilence
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2018-06-25 19:49 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (128 votes). Check out past polls.