title: Python: Refresh PivotTables in worksheet
body: <p>I'm building a python script that will allow me to open a Excel 2010 worksheet and print it out.</p>
  <p>I got most of the way</p>
  <pre><code>import win32com.client
  
  office = win32com.client.Dispatch(&quot;Excel.Application&quot;)
  wb = office.Workbooks.Open(r&quot;path\to\excel\file\to\print.xlsm&quot;)
  
  count = wb.Sheets.Count
  for i in range(count):
      ws = wb.Worksheets[i]
  
      pivotCount = ws.PivotTables().Count
      for j in range(1, pivotCount+1):
          #TODO code to refresh each pivot table
  
      ws.PrintOut()
      print &quot;Worksheet: %s - has been sent to the printer&quot; % (ws.Name)
  </code></pre>
  <p>As you can see I'm still missing the refreshing of the pivot tables in the worksheet.</p>
  <p>The VBA code for refreshing is:</p>
  <pre><code>ActiveSheet.PivotTables(1).PivotCache.Refresh
  </code></pre>
  <p>I can't seem to break the code into python win32com syntax. The closest I got is:</p>
  <pre><code>wb.WorkSheets(5).PivotTables(1).PivotCache.Refresh
  </code></pre>
  <p>which gives <code>&lt;bound method CDispatch.Refresh of &lt;COMObject PivotCache&gt;&gt;</code> but no result in the the worksheet.</p>