Articles in this section
Category / Section

How to refresh an Excel pivot chart in C#, VB.NET

2 mins read

Syncfusion® Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. It also converts Excel documents to PDF files.

This library supports creating PivotTables and PivotCharts. PivotCharts are created using the IChart interface by setting their pivot source as a PivotTable.

Refreshing a PivotChart can be achieved by changing the pivot chart’s pivot table’s cache data source. The following complete code snippet explains this.

C#

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Xlsx;
 
    IWorkbook workbook = application.Workbooks.Open("../../Data/PivotChart.xlsx");
    IWorksheet worksheet = workbook.Worksheets[0];
    IWorksheet pivotsheet = workbook.Worksheets[1];
    IPivotTable pivotTable = pivotsheet.PivotTables[0];
 
    (pivotTable as PivotTableImpl).Cache.SourceRange = worksheet["A1:H40"];
 
    workbook.SaveAs("Output.xlsx");
    System.Diagnostics.Process.Start("Output.xlsx");
}

 

A complete working sample can be downloaded from RefreshPivotChart.zip.

Please go through the below screenshots .

Data source of pivot chart before refreshing

Data source of the pivot chart before refreshing

Data source of pivot chart after refreshing

Data source of the pivot chart after refreshing

Take a moment to peruse the documentation, where you can find basic worksheet data manipulation options along with features like Conditional Formatting, worksheet calculations through Formulas, adding Charts in worksheet or workbook, organizing and analyzing data through Tables and Pivot Tables, appending multiple records to worksheet using Template Markers, and most importantly PDF and Image conversions etc. with code examples.

Click here to explore the rich set of Syncfusion Excel (XlsIO) library features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

Conclusion

I hope you enjoyed learning about how to refresh an Excel pivot chart in C#, VB.NET.

You can refer to our XIsIO’s feature tour page to learn about its other groundbreaking features. Explore our UG documentation and online demos to understand how to manipulate data in Excel documents.

If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion® components.

If you have any queries or require clarification, please let us know in the comments below or contact us through our support forumsSupport Tickets, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied