Articles in this section
Category / Section

How to edit or change the data in an existing PowerPoint Chart in C# and VB.NET?

5 mins read

The PowerPoint framework is a feature rich .NET PowerPoint class library that can be used by developers to create, read, edit and convert PowerPoint files to PDF and images programmatically without Office or interop dependencies. Using this library, you can edit or change the data in an existing PowerPoint chart in C# and VB.NET.

 

Steps to edit or change the data in an existing chart in PowerPoint Presentation document

  1. Create a new C# console application project.

Create a new console app

 

  1. Install the Syncfusion.Presentation.WinForms NuGet package as a reference to your .NET Framework applications from NuGet.org

Install NuGet package

 

  1. Include the following namespace in the Program.cs file.

C#

using Syncfusion.Presentation;
using Syncfusion.OfficeChart;

 

VB

Imports Syncfusion.Presentation
Imports Syncfusion.OfficeChart

 

  1. Use the following code example to edit or change the data in an existing chart in PowerPoint Presentation document.

C#

//Opens a Presentation
IPresentation pptxDoc = Presentation.Open(@"Sample.pptx");
 
//Adds a slide to the Presentation
ISlide slide = pptxDoc.Slides[0];
 
//Gets the chart in slide
IPresentationChart chart = slide.Shapes[0] as IPresentationChart;
 
//Modifies chart data - Row1
chart.ChartData.SetValue(1, 2, "Jan");
chart.ChartData.SetValue(1, 3, "Feb");
chart.ChartData.SetValue(1, 4, "March");
 
//Modifies chart data - Row2
chart.ChartData.SetValue(2, 1, 2010);
chart.ChartData.SetValue(2, 2, 90);
chart.ChartData.SetValue(2, 3, 80);
chart.ChartData.SetValue(2, 4, 70);
 
//Refreshes the chart
chart.Refresh();
 
//Saves the Presentation
pptxDoc.Save("Output.pptx");
 
//Closes the Presentation
pptxDoc.Close();

 

VB

'Opens a Presentation
Dim pptxDoc As IPresentation = Presentation.Open("Sample.pptx")
 
'Adds a slide to the Presentation
Dim slide As ISlide = pptxDoc.Slides(0)
 
'Gets the chart in slide
Dim chart As IPresentationChart = TryCast(slide.Shapes(0), IPresentationChart)
 
'Modifies chart data - Row1
chart.ChartData.SetValue(1, 2, "Jan")
chart.ChartData.SetValue(1, 3, "Feb")
chart.ChartData.SetValue(1, 4, "March")
 
'Modifies chart data - Row2
chart.ChartData.SetValue(2, 1, 2010)
chart.ChartData.SetValue(2, 2, 90)
chart.ChartData.SetValue(2, 3, 80)
chart.ChartData.SetValue(2, 4, 70)
 
'Refreshes the chart
chart.Refresh()
 
'Saves the Presentation
pptxDoc.Save("output.pptx")
 
'Closes the Presentation
pptxDoc.Close()

 

A complete working sample to edit or change the data in an existing chart in PowerPoint Presentation document using C# can be downloaded from here.

 

Input Presentation document with chart as follows:

input document

 

By executing the program, you will get the output Word document as follows.

Output document

 

Take a moment to peruse the documentation, where you can find basic PowerPoint Presentation document processing options along with features like animation, slide transitions, shapes, smart art, protect the Presentation documents, and most importantly PDF conversion and Image conversions with code examples.

 

Explore more about the rich set of Syncfusion PowerPoint Framework features.

 

See Also:

Working with charts using various operations

 

Note:

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

 

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