Michaelc has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|