Skip to content

Commit 8c0402c

Browse files
authored
Merge pull request #2275 from syncfusion-content/994299-PivotChartUG
Documentation (994299): Update PivotChart UG — Refresh PivotChart by Updating PivotTable Cache
2 parents c217036 + c5f7dd8 commit 8c0402c

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

Document-Processing/Excel/Excel-Library/NET/Working-with-Pivot-Charts.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,59 @@ pivotChartSheet.Series(0).SerieFormat.CommonSerieOptions.Overlap = 100
153153
{% endhighlight %}
154154
{% endtabs %}
155155

156-
156+
## Refresh PivotChart
157+
158+
To refresh a PivotChart, update the PivotTable's cache data source so the chart uses the updated cached data.
159+
160+
{% tabs %}
161+
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/Pivot%20Charts/Refresh%20Pivot%20Chart/.NET/Refresh%20Pivot%20Chart/Refresh%20Pivot%20Chart/Program.cs,180" %}
162+
using (ExcelEngine excelEngine = new ExcelEngine())
163+
{
164+
IApplication application = excelEngine.Excel;
165+
application.DefaultVersion = ExcelVersion.Excel2013;
166+
IWorkbook workbook = application.Workbooks.Open("PivotChart.xlsx");
167+
168+
IWorksheet dataSheet = workbook.Worksheets[0];
169+
IWorksheet pivotSheet = workbook.Worksheets[1];
170+
171+
// Update pivot cache source range to refresh the PivotChart
172+
(pivotSheet.PivotTables[0] as PivotTableImpl).Cache.SourceRange = dataSheet["A1:H50"];
173+
174+
workbook.SaveAs("PivotChart_Refreshed.xlsx");
175+
}
176+
{% endhighlight %}
177+
178+
{% highlight c# tabtitle="C# [Windows-specific]" %}
179+
using (ExcelEngine excelEngine = new ExcelEngine())
180+
{
181+
IApplication application = excelEngine.Excel;
182+
application.DefaultVersion = ExcelVersion.Excel2013;
183+
IWorkbook workbook = application.Workbooks.Open("PivotChart.xlsx");
184+
185+
IWorksheet dataSheet = workbook.Worksheets[0];
186+
IWorksheet pivotSheet = workbook.Worksheets[1];
187+
188+
(pivotSheet.PivotTables[0] as PivotTableImpl).Cache.SourceRange = dataSheet["A1:H50"];
189+
190+
workbook.SaveAs("PivotChart_Refreshed.xlsx");
191+
}
192+
{% endhighlight %}
193+
194+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
195+
Using excelEngine As New ExcelEngine()
196+
Dim application As IApplication = excelEngine.Excel
197+
application.DefaultVersion = ExcelVersion.Excel2013
198+
Dim workbook As IWorkbook = application.Workbooks.Open("PivotChart.xlsx")
199+
200+
' set these to the actual sheets in your file
201+
Dim dataSheet As IWorksheet = workbook.Worksheets(0)
202+
Dim pivotSheet As IWorksheet = workbook.Worksheets(1)
203+
204+
DirectCast(pivotSheet.PivotTables(0), PivotTableImpl).Cache.SourceRange = dataSheet("A1:H50")
205+
206+
workbook.SaveAs("PivotChart_Refreshed.xlsx")
207+
End Using
208+
{% endhighlight %}
209+
{% endtabs %}
210+
211+
A complete working example to refresh pivot chart in C# is present on [this GitHub page](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Pivot%20Charts/Refresh%20Pivot%20Chart/.NET/Refresh%20Pivot%20Chart).

0 commit comments

Comments
 (0)