# GrapeCity.Documents.Excel.IPivotTable.Refresh

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="GrapeCity_Documents_Excel_IPivotTable_Refresh_" data-uid="GrapeCity.Documents.Excel.IPivotTable.Refresh*">Refresh Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="GrapeCity_Documents_Excel_IPivotTable_Refresh_" data-uid="GrapeCity.Documents.Excel.IPivotTable.Refresh*"></a>
<h4 id="GrapeCity_Documents_Excel_IPivotTable_Refresh" data-uid="GrapeCity.Documents.Excel.IPivotTable.Refresh">Refresh()</h4>
<div class="markdown level1 summary"><p>Refreshes the PivotTable report from its source data.</p>
<p>
Use this method after the source data has changed and you need the PivotTable to
reflect the latest data.
</p><p>
This method performs the following actions:
</p><ol><li>Refreshes the underlying <code>PivotCache</code>.</li><li>Synchronizes <code>PivotFields</code> with the refreshed cache.</li><li>Recalculates and updates the PivotTable report on the worksheet.</li></ol><p>
If only the PivotTable layout or display settings have changed and the source data
has not changed, use <a class="xref" href="GrapeCity.Documents.Excel.IPivotTable.Update.html#GrapeCity_Documents_Excel_IPivotTable_Update">Update()</a> instead.
</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">bool Refresh()</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Function Refresh() As Boolean</code></pre>
</div>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></td>
      <td><code>
    <a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">true</a>
</code> if the refresh succeeds.
</td>
    </tr>
  </tbody>
</table>
<h5 id="GrapeCity_Documents_Excel_IPivotTable_Refresh_examples">Examples</h5>
<pre><code class="lang-csharp">worksheet.Range["A1:B4"].Value = new object[,] {
    {"Product", "Amount"},
    {"Apple", 100},
    {"Apple", 200},
    {"Orange", 150}
};
IPivotCache pivotCache = workbook.PivotCaches.Create(worksheet.Range["A1:B4"]);
IPivotTable pivotTable = worksheet.PivotTables.Add(pivotCache, worksheet.Range["D1"], "PivotTable1");
pivotTable.PivotFields["Product"].Orientation = PivotFieldOrientation.RowField;
pivotTable.PivotFields["Amount"].Orientation = PivotFieldOrientation.DataField;
worksheet.Range["B2"].Value = 120;
bool refreshed = pivotTable.Refresh();</code></pre>

<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Condition</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.invalidoperationexception">InvalidOperationException</a></td>
      <td><p>if the source sheet of the PivotTable cannot be found.</p>
</td>
    </tr>
  </tbody>
</table>
</div>
