Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am using Win32::OLE to format excel worksheet. But I can not find a way to set the $Sheet for View Zoom to 75% for example. Can you help to point this out?
  • Comment on Win32::OLE set worksheet view with Zoom 75%

Replies are listed 'Best First'.
Re: Win32::OLE set worksheet view with Zoom 75%
by guha (Priest) on May 09, 2004 at 19:40 UTC

    Zoom is a property of the Window-object. Assuming the application object is $ex.

    $ex->Windows(1)->{Zoom} = 75;

    Code not tested but HTHA.

Re: Win32::OLE set worksheet view with Zoom 75%
by jmcnamara (Monsignor) on May 09, 2004 at 19:51 UTC

    The zoom level is a property of the Window object which is in turn part of the Excel Application object. Here is a short example of how to set it:
    #!/usr/bin/perl -w use strict; use Cwd; use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; my $application = Win32::OLE->new("Excel.Application"); my $workbook = $application->Workbooks->Add; my $worksheet = $workbook->Worksheets(1); my $window = $application->Windows(1); # Set the sheet zoom level. $window->{Zoom} = 75; # Write some text. $worksheet->Cells(1,1)->{Value} = "Hello World"; my $dir = cwd(); $workbook->SaveAs({FileName => $dir . '/win32ole.xls'}); $workbook->Close; __END__

    --
    John.

Re: Win32::OLE set worksheet view with Zoom 75%
by Anonymous Monk on May 10, 2004 at 04:03 UTC
    Thanks all. Your suggestion works.
    Furthermore, any idea on formatting the whole Excel worksheet to use Arial font and font size 8 for example. I tried the following lines, they would not work: my $Sheet = $Book2->Worksheets($localcounter01); $Sheet->{Font} = "Arial"; $Sheet->{Size} = 8; $Sheet->Range($range)->Columns->AutoFit;
    Tommy