半岛权威十大直营(官方)网站

PPT处理控件Spire.Presentation常见问题解答

翻译|使用教程|编辑:吉炜炜|2025-01-14 14:27:22.230|阅读 11 次

概述:为方便使用者快速掌握和了解Spire.Presentation,本文列举了PPT处理控件Spire.Presentation常见问题及解答,欢迎下载最新版体验!

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

相关链接:

为方便使用者快速掌握和了解Spire.Presentation,本文列举了PPT处理控件Spire.Presentation常见问题及解答,欢迎下载最新版体验!

Spire.PDF for .NET最新下载

如何给PowerPoint文档添加密码保护?

请使用Encrypt方法给文档加密。全部代码:

Presentation presentation = new Presentation();
presentation.LoadFromFile("sample.pptx");
presentation.Encrypt("test");
presentation.SaveToFile("encrypt.pptx", FileFormat.Pptx2010);

如何转换PowerPoint文件到PDF?

只需要加载文件,然后保存成PDF即可。全部代码:

Presentation presentation = new Presentation();
//加载文件
presentation.LoadFromFile("ppt.ppt");
//把文件保存成PDF
presentation.SaveToFile("ToPdf.pdf", FileFormat.PDF);

如何将幻灯片保存成图片?

请使用SaveAsImage方法将幻灯片保存到Image中,然后将Image对象保存成图片。全部代码:

Presentation ppt = new Presentation();
ppt.LoadFromFile(@"F:\testing\Sample.pptx");
for (int i = 0; i < ppt.Slides.Count; i++)
{
  //将幻灯片保存到Image中
  Image image = ppt.Slides[i].SaveAsImage();
  String fileName = String.Format("5614-img-{0}.png", i);
  //将image保存成文件
  image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
}

如何设置文本框中文本的对齐方式?

请使用Alignment设置文本的对齐方式。全部代码:

Presentation presentation = new Presentation();
//添加一个shape
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 600, 400));
//设置shape里面第一段的对齐方式为左对齐
shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
shape.Fill.FillType = FillFormatType.None;
//添加文本
shape.TextFrame.Text = "Demo about Alignment";
presentation.SaveToFile("alignment.pptx", FileFormat.Pptx2010);

如何提取PowerPoint中的文本?

请您使用TextParagraph的Text属性。全部代码:

StringBuilder sb = new StringBuilder();

for (int i = 0; i < ppt.Slides.Count;i++ )
       {
           for (int j = 0; j < ppt.Slides[i].Shapes.Count;j++ )
           {
               if (ppt.Slides[i].Shapes[j] is IAutoShape)
               {
                   IAutoShape shape=ppt.Slides[i].Shapes[j] as IAutoShape;
                   if (shape.TextFrame != null)
                   {
                       foreach (TextParagraph tp in shape.TextFrame.Paragraphs)
                       {
                           sb.Append(tp.Text + Environment.NewLine);
                       }
                   }

               }
           }
       }

如何用图片填充形状?

请使用PictureShape的Url属性。全部代码:

Presentation ppt = new Presentation();
IAutoShape shape = (IAutoShape)ppt.Slides[0].Shapes.AppendShape(ShapeType.DoubleWave, new RectangleF(100, 100, 400, 200));
string picUrl = @"C:\Users\Administrator\Desktop\image.jpg";
shape.Fill.FillType = FillFormatType.Picture;
shape.Fill.PictureFill.Picture.Url = picUrl;
shape.Fill.PictureFill.FillType = PictureFillType.Stretch;
shape.ShapeStyle.LineColor.Color = Color.Transparent;
ppt.SaveToFile("shape.pptx", FileFormat.Pptx2010);

欢迎下载|体验更多E-iceblue产品

获取更多信息请咨询 ;技术交流Q群(767755948)


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@wqylolg.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP