After a little playing around with this code example, and Excel 2003, it appears that some of the methods seem to operate only on the active worksheet that was last used, or on-top (The view at 75%) is one of them. This leads me to believe that Excel needs a more in-depth pointer to the sheet you want to use the methods on. I am not overly familiar with how to manipulate these as you seem to need, but I did read that the structure available to access the sheets and their properties can be found in the Visual Basic Help.

I did however include the code that I found from CPAN. Definitely, read the Win32::OLE documentation and use the Excel package example as it handles the closing of files even on abortion of the perl script. Otherwise, the excel file gets locked for editing. Wish I could do more :-(

Hints for Microsoft Office automation

Documentation

The object model for the Office applications is defined in the Visual Basic reference guides for the various applications. These are typically not installed by default during the standard installation. They can be added later by rerunning the setup program with the custom install option. Class, Method and Property names

The names have been changed between different versions of Office. For example Application was a method in Office 95 and is a property in Office97. Therefore it will not show up in the list of property names keys %$object when querying an Office 95 object.

The class names are not always identical to the method/property names producing the object. E.g. the Workbook method returns an object of type Workbook in Office 95 and _Workbook in Office 97.

And it goes on...

#!perl use Excel; my $file = "C:\\perl_proj\\book1.xls"; my $ex = Excel->new('Excel.Application', sub {$_[0]->Quit;}) or die "O +ops, cannot start Excel"; my $Book = $ex->Workbooks->Open($file); my $Sheet1 = $Book->Worksheets(1); $Book->Windows(1)->{Zoom} = 75; $Sheet1->Columns->Font->{Size} = 12; my $Sheet2 = $Book->Worksheets(2); $Sheet2->Columns->{NumberFormat} = "#,##0.00"; $Book = $ex->Workbooks->Close();
The Excel Module from the CPAN page Win32::OLE
package Excel; use Win32::OLE; sub new { my $s = {}; if ($s->{Ex} = Win32::OLE->new('Excel.Application')) { return bless $s, shift; } return undef; } sub DESTROY { my $s = shift; if (exists $s->{Ex}) { print "# closing connection\n"; $s->{Ex}->Quit; return undef; } } sub AUTOLOAD { my $s = shift; $AUTOLOAD =~ s/^.*:://; $s->{Ex}->$AUTOLOAD(@_); } 1;

In reply to Re: Set the sheet #2 for View Zoom to 75% by Sagacity
in thread Set the sheet #2 for View Zoom to 75% by jinhuang1992

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.