Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I try to modify a PowerPoint Slide, which contains two Charts. My goal is to find the Chart and modify its data.

I already got the GraphicFrame which contains the Chart, and I got the relative ID of the ChartSpace Element I want to modify. But how to get the actucal ChartSpace element?

 public void test()
{
    //// getting the SlidePart
      var slidepart = presPart.GetPartById(relId) as SlidePart;
    //// getting the Shape which contains the damned Chart
    var graphicFrame = GetGraphicFrameFromSlide(slidepart, ppChart, ppSlide);
    //// get the ChartReference
    DrawCharts.ChartReference child = GraphicFrame.Graphic.GraphicData.GetFirstChild<DrawCharts.ChartReference>();
                                var chartID = child.Id;
    //// this returns a ExtendedSomething, but no chart reference :(
                               var chartData = presDoc.GetPartById(chartID) ;
}
share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted

Christian, if you are still looking for an answer: I was able to find one for my question. I think it may be useful for you too.

Refer to post "Finding a graph part within a rich text control with OpenXML SDK".

Good luck!

share|improve this answer
    
Looks good! Thank you very much! –  Christian Sauer Jun 5 '13 at 7:50
add comment

Not sure if this helps you, but I am doing something like this in a Word document:

        foreach (ChartPart chartPart in mainDocumentPart.ChartParts)
        {
            Chart chart = chartPart.ChartSpace.Elements<Chart>().FirstOrDefault();

            if (chart != null)
            {

                DocumentFormat.OpenXml.Drawing.Charts.LineChart lineChart = chart.Descendants<DocumentFormat.OpenXml.Drawing.Charts.LineChart>().FirstOrDefault();

                if (lineChart != null)
                {
                    i++;

                    LineChartEx chartEx = new LineChartEx(chartPart, myChartData));
                    chartEx.Refresh();
                }
            }

            chartPart.ChartSpace.Save();

        }

For the moment I'm still trying to figure out how to retrieve a chart that resides within a given rich text control (using it's tag name). The above method works, but I'm not completely happy with it.

Anyway, good luck finding a solution to your problem!

share|improve this answer
    
Thank you,. that looks very similar to my own approach, which I build today. Good that my logic was not tottaly of the mark :) As a suggestion: you can give namepsaces aliases like: Draw = DocumentFormat.OpenXml.Drawing; that would shorten your query drastically. –  Christian Sauer May 29 '13 at 12:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.