I'm trying to figure out how to turn off totals in an Excel pivot table generated by a perl script. Anybody any ideas? I'v tried three different approaches, so far without success. See the example code below. The problem is with the code at the end... none of it actually turns off totals. Thanks!!
use strict; use warnings; use Win32::OLE qw( with); use constant xlColumnField => 2; use constant xlCount => -4112; use constant xlDatabase => 1; use constant xlHidden => 0; use constant xlPivotTableVersion10 => 1; use constant xlRowField => 1; use constant xlSum => -4157; sub Macro1; my $_app_object = (Win32::OLE->GetActiveObject('Excel.Application') + || Win32::OLE->new('Excel.Application')); $_app_object->{'Visible'} = 1; $_app_object->Workbooks->Add(); $_app_object->ActiveSheet->Cells(1, 1)->{Value} = "a"; $_app_object->ActiveSheet->Cells(1, 2)->{Value} = "b"; $_app_object->ActiveSheet->Cells(1, 3)->{Value} = "c"; $_app_object->ActiveSheet->Cells(2, 1)->{Value} = "1"; $_app_object->ActiveSheet->Cells(2, 2)->{Value} = "2"; $_app_object->ActiveSheet->Cells(2, 3)->{Value} = "3"; $_app_object->ActiveSheet->Cells(3, 1)->{Value} = "4"; $_app_object->ActiveSheet->Cells(3, 2)->{Value} = "5"; $_app_object->ActiveSheet->Cells(3, 3)->{Value} = "6"; Macro1; sub Macro1 { $_app_object->ActiveWorkbook->PivotCaches->Add({SourceType => xlDa +tabase, SourceData => 'Sheet1!R1C1:R4C3'})->CreatePivotTable({TableDe +stination => 'Sheet1!R8C3', TableName => 'PivotTable1', DefaultVersio +n => xlPivotTableVersion10}); ##$_app_object->ActiveSheet->PivotTables('PivotTable1')->AddDataFi +eld($_app_object->ActiveSheet->PivotTables('PivotTable1')->PivotField +s('a'), 'Sum of a', xlSum); $_app_object->ActiveSheet->PivotTables('PivotTable1')->AddDataFiel +d($_app_object->ActiveSheet->PivotTables('PivotTable1')->PivotFields( +'a') ); { my $_with001 = $_app_object->ActiveSheet->PivotTables('PivotTa +ble1')->PivotFields('b'); with ($_with001, Orientation => xlRowField, Position => 2, ); } { my $_with002 = $_app_object->ActiveSheet->PivotTables('PivotTa +ble1')->PivotFields('a'); with ($_with002, Orientation => xlRowField, Position => 1, ); } { my $_with003 = $_app_object->ActiveSheet->PivotTables('PivotTa +ble1')->PivotFields('c'); with ($_with003, Orientation => xlColumnField, Position => 1, ); } #------------------------------------------- # The following code does not work... Help! #------------------------------------------- # Attempt 1 #---------- $_app_object->ActiveSheet->PivotTables('PivotTable1')->PivotFields +('a')->{Subtotals} = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; # Attempt 2&3 #------------ for (my $i=0; $i <= $#{$_app_object->ActiveSheet->PivotTables('Piv +otTable1')->PivotFields('a')->{Subtotals}}; $i++ ) { print "$i ".$_app_object->ActiveSheet->PivotTables('PivotTable1 +')->PivotFields('a')->Subtotals($i+1); print $_app_object->ActiveSheet->PivotTables('PivotTable1 +')->PivotFields('a')->{Subtotals}[$i]; ##$_app_object->ActiveSheet->PivotTables('PivotTable1 +')->PivotFields('a')->Subtotals($i+1) = 0; $_app_object->ActiveSheet->PivotTables('PivotTable1 +')->PivotFields('a')->{Subtotals}[$i] = 0; print " ".$_app_object->ActiveSheet->PivotTables('PivotTable1 +')->PivotFields('a')->Subtotals($i+1); print $_app_object->ActiveSheet->PivotTables('PivotTable1 +')->PivotFields('a')->{Subtotals}[$i]."\n"; } }

In reply to WIN32::OLE Excel Pivot Table Grief by Anonymous Monk

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.