I am trying to change Pivot table {Function} property to specify it is xlCount or xlAverage or xlSum etc. But I got the error msg below:

==========

Unable to set the Function property of the PivotField class

Win32::OLE(0.1711) error 0x80020009: "Exception occurred" in PROPERTYPUT "Function" at WeeklyRpt.pl line 138

==========

Here is the code. I am using Win32::OLE.

use strict; use Math::BigInt; use Cwd; use Time::Local; use POSIX qw(strftime); use Win32::OLE::Const 'Microsoft Excel'; # use OLE/Excel $Win32::OLE::Warn = 3; # die on errors... <<<...snip...>>> # Create worksheet after cases data sheet $act_sheet = $workbook->Worksheets->Add({After=>$ws_data}) or die Win3 +2::OLE->LastError(); #Get current active sheet name $act_sheet_name = $workbook->ActiveSheet->{Name}; #Get current acti +ve sheet name $act_sheet = $workbook -> Worksheets( "$act_sheet_name" ); $act_sheet->{name} = 'ClosedRegion'; #Change sheet name http://www. +perlmonks.org/bare/?node_id=417676 $pv_table = $ws_data->PivotTableWizard( { SourceType=>xlDatabase, Sour +ceData=>$data_rang, TableDestination=>'ClosedRegion!R3C1', TableNa +me=>"PivotTable2"} ); $pv_table->AddFields( "Owner Region" ); $pv_table->PivotFields("Owner Region")->{Orientation} = xlDataField; $pv_table->PivotFields("Owner Region")->{Function} = xlCount;

The last line code causes the problem. I have also ever tried

$pv_table->PivotFields("Owner Region")->SetProperty("Function",xlCount);

but does not work out either.

Could you help out?

Thank you!


In reply to Unable to set the Function property of the PivotField class by Michaelc

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.