Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents from any .NET(C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

Thu Dec 18, 2014 1:58 pm

Hello,

I have made a template using Microsoft Powerpoint and my presentation has a pie chart.
With the help of Free Spire.Presentation I now try to fill the pie chart with data, but when saved
and opened, I get an error saying the presentation needs to be repaired.
My conclusion is that this occurs as soon as I try to change the data of the pie chart.

This is my code:
Code: Select all
       private void UpdatePieChart2(ISlide slide, int row, int col, DataRow data)
        {
            IChart chart = null;
            Double column1 = 0;
            Double column2 = 0;

            for (int i = 0; i < slide.Shapes.Count; i++)
            {
                if (slide.Shapes[i].Name == string.Format("ChartR{0}C{1}", row, col))
                {
                    chart = (IChart)slide.Shapes[i];
                    break;
                }
            }

            if (chart != null)
            {
                column1 = (object)data[10] != System.DBNull.Value ? (Double)data[10] : 0;
                column2 = (object)data[11] != System.DBNull.Value ? (Double)data[11] : 0;

                chart.ChartData[1, 1].Value = column1;
                chart.ChartData[2, 1].Value = column2 - column1;
                chart.ChartData[3, 1].Value = (Double)1.0 - column2;
                chart.ChartData[4, 1].Value = (Double)1.0;
            }
        }


Have I done anything wrong?

anders@mmpab.com
 
Posts: 4
Joined: Mon Dec 08, 2014 9:25 am

Fri Dec 19, 2014 2:48 am

Hello,

Thanks for your inquiry.
Please share your template and the data you used.
I did a simple testing for updating the pie chart with data by Free Spire.Presentation 2.1 and it was working properly, attached test.pptx.
Code: Select all
   Presentation pre = new Presentation();
            pre.LoadFromFile("..\\..\\test.pptx");
            IChart chart = pre.Slides[0].Shapes[0] as IChart;
            Double[] data = { 7.2, 2.0, 1.4, 5.4 };

            for (int i = 0; i < 4; i++)
            {
                chart.ChartData[i + 1, 1].Value = data[i];
            }
            string output = "chart.pptx";
            pre.SaveToFile(output, FileFormat.Pptx2007);


Best wishes,
Amy
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar

amy.zhao
 
Posts: 2428
Joined: Wed Jun 27, 2012 8:50 am

Fri Dec 19, 2014 2:44 pm

Hello,

After making some test with your template I now understand what my template crashes.
Test this:
1. Edit your template and add labels to your chart.
2. Remove one of the four labels.
3. Save and run your testprogram.
4. Open your presentation and you will be asked to repair your presentation.

Of course you cold always ask why I remove one of the labels but I try to make something that looks
lika a speed meter by placing two pie charts on top of each other.

Best regards
Anders

anders@mmpab.com
 
Posts: 4
Joined: Mon Dec 08, 2014 9:25 am

Mon Dec 22, 2014 2:44 am

Dear Anders,

I followed your steps to do the test but still didn't reproduce your issue.
After the first two steps, I generated the presentation in attachment. And I ran my previous testprogram with it, the output presentation was working well.

To help us to reproduce your issue quickly and resolve it, would you please send your test presentation?

Thank you.

Best wishes,
Amy
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar

amy.zhao
 
Posts: 2428
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Presentation