none
Unable to set ThreeD format on PowerPoint chart RRS feed

  • Question

  • I'm using the below code to format my chart from C#.  If I uncomment any of those lines, PPT throws a com exception.  Why?

    PPT.ChartFormat format = chart.SeriesCollection(1).Format;
    format.Shadow.Type = MsoShadowType.msoShadow41;
    format.ThreeD.BevelTopType = MsoBevelType.msoBevelCircle;
    //format.ThreeD.BevelTopInset = 512f;
    //format.ThreeD.BevelTopDepth = 512f;
    //format.ThreeD.BevelBottomType = MsoBevelType.msoBevelCircle;
    //format.ThreeD.BevelBottomInset = 512f;
    //format.ThreeD.BevelBottomDepth = 512f;
    //format.ThreeD.PresetMaterial = MsoPresetMaterial.msoMaterialPlastic2;

    Friday, April 21, 2017 6:55 PM

Answers

  • Hello,

    What exception do you get? I would get "Specified cast is not valid" using your code.

    Please test the following code, it could successfully set ThreeD format.

      var shapes = slide.Shapes;
                var chart = shapes.AddChart(XlChartType.xlPie, 66, 113, 828, 384).Chart;
                
                //PowerPoint.ChartFormat format = chart.SeriesCollection(1).Format;
                chart.SeriesCollection(1).Format.Shadow.Type = MsoShadowType.msoShadow41;
                chart.SeriesCollection(1).Format.ThreeD.BevelTopType = MsoBevelType.msoBevelCircle;
                chart.SeriesCollection(1).Format.ThreeD.BevelTopInset = 512f;
                chart.SeriesCollection(1).Format.ThreeD.BevelTopDepth = 512f;
                chart.SeriesCollection(1).Format.ThreeD.BevelBottomType = MsoBevelType.msoBevelCircle;
                chart.SeriesCollection(1).Format.ThreeD.BevelBottomInset = 512f;
                chart.SeriesCollection(1).Format.ThreeD.BevelBottomDepth = 512f;
                chart.SeriesCollection(1).Format.ThreeD.PresetMaterial = MsoPresetMaterial.msoMaterialPlastic2;

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 24, 2017 10:07 AM
    Moderator

All replies

  • Hello,

    What exception do you get? I would get "Specified cast is not valid" using your code.

    Please test the following code, it could successfully set ThreeD format.

      var shapes = slide.Shapes;
                var chart = shapes.AddChart(XlChartType.xlPie, 66, 113, 828, 384).Chart;
                
                //PowerPoint.ChartFormat format = chart.SeriesCollection(1).Format;
                chart.SeriesCollection(1).Format.Shadow.Type = MsoShadowType.msoShadow41;
                chart.SeriesCollection(1).Format.ThreeD.BevelTopType = MsoBevelType.msoBevelCircle;
                chart.SeriesCollection(1).Format.ThreeD.BevelTopInset = 512f;
                chart.SeriesCollection(1).Format.ThreeD.BevelTopDepth = 512f;
                chart.SeriesCollection(1).Format.ThreeD.BevelBottomType = MsoBevelType.msoBevelCircle;
                chart.SeriesCollection(1).Format.ThreeD.BevelBottomInset = 512f;
                chart.SeriesCollection(1).Format.ThreeD.BevelBottomDepth = 512f;
                chart.SeriesCollection(1).Format.ThreeD.PresetMaterial = MsoPresetMaterial.msoMaterialPlastic2;

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 24, 2017 10:07 AM
    Moderator
  • That does work, yes.  Thanks.  But I don't understand the difference?  Why can't I "dot walk" down into the ThreeD format after assigning a temp variable to it?
    Monday, April 24, 2017 1:59 PM