C# 操作PPT图形

 时间:2026-02-12 19:00:45

1、下载并安装Spire.Presentation for .NET, 并将Spire.Presentation.dll文件引用到项目中。

2、 将代码放入Visual Studio中:

旋转图形

【C#】

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Spire.Presentation;

namespace Rotate_Shapes

{  

    class Program   

        {       

               static void Main(string[] args)     

                  {           

                    //创建一个PowerPoint文档并加载示例文档            

                    Presentation ppt = new Presentation();           

                    ppt.LoadFromFile("Sample.pptx");           

                   //获取第一个幻灯片里的第一个图形           

                   IShape shape = ppt.Slides[0].Shapes[0];           

                   //旋转180度           

                    shape.Rotation = 180;           

                   //保存文档           

                   ppt.SaveToFile("Rotate.pptx", FileFormat.Pptx2010);       

                }   

         }

}

3、前后效果对不图如下:

C# 操作PPT图形

1、重置图形的大小

【C#】

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Spire.Presentation;

using System.Drawing;

namespace Reset_Shape_Size

{   

      class Program   

            {       

                 static void Main(string[] args)       

                   {          

                    //创建一个PowerPoint文档并加载示例文档           

                    Presentation ppt = new Presentation();           

                    ppt.LoadFromFile("Sample.pptx");           

                    //获取原始幻灯片高度和宽度          

                   float currentHeight = ppt.SlideSize.Size.Height;           

                   float currentWidth = ppt.SlideSize.Size.Width;          

                   //将幻灯片大小设置为A3.           

                   ppt.SlideSize.Type = SlideSizeType.A3;          

                   //获取新幻灯片的高度和宽度           

                   float newHeight = ppt.SlideSize.Size.Height;           

                   float newWidth = ppt.SlideSize.Size.Width;          

                   //指定高度和宽度的比例           

                   float ratioHeight = newHeight / currentHeight;           

                   float ratioWidth = newWidth / currentWidth;           

      //重新设置图形大小和位置           

     foreach (ISlide slide in ppt.Slides)           

         {               

            foreach (IShape shape in slide.Shapes)               

               {                   

                    //重置图形大小                   

                   shape.Height = shape.Height * ratioHeight;                  

                   shape.Width = shape.Width * ratioWidth;                   

                   //重置图形位置                  

                   shape.Left = shape.Left * ratioHeight;                   

                   shape.Top = shape.Top * ratioWidth;               

                   }               

                    //保存文档               

                ppt.SaveToFile("ResetSizePosition.pptx", FileFormat.Pptx2010);          

                }       

         }   

     }

}

2、前后效果对比图如下:

C# 操作PPT图形

3、重新排列重叠图形的顺序

【C#】

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Spire.Presentation;

namespace Reorder_Shapes

      {   

            class Program  

                 {       

                   static void Main(string[] args)      

                        {           

                           //创建一个PowerPoint文档并加载示例文档           

                           Presentation ppt = new Presentation();           

                           ppt.LoadFromFile("Sample.pptx");          

                            //获取第二个幻灯片里的第一个图形           

                           IShape shape = ppt.Slides[1].Shapes[0];           

                           //重新设置图形的顺序.          

                           ppt.Slides[1].Shapes.ZOrder(1, shape);          

                           //保存文档           

                            ppt.SaveToFile("Reorder.pptx", FileFormat.Pptx2010);                       }   

           }

}

4、前后效果对比图如下:

C# 操作PPT图形

  • PPT彩球魔幻旋转效果制作
  • 如何设置PPT只能看不能修改
  • PPT 2013如何设置多个对象同时运动效果
  • 如何设置PPT圆形圆周动画
  • 在ppt中给上弧形箭头添加彩虹出岫渐变色
  • 热门搜索
    冬季九寨沟旅游攻略 汕尾红海湾旅游攻略 拉萨旅游网 太湖旅游 长白山天池旅游攻略 古城旅游 放鸡岛旅游攻略 儋州旅游 去欧洲旅游 天水旅游景点大全