PPT管理工具Spire.Presentation这些常见问题你都解决了吗?

Spire.Presentation for .NET是专业的 PowerPoint组件,使用该组件,开发者可以在 .NET 平台上对 PowerPoint文档进行生成、读取、写入、修改、转换和打印等操作。

Spire.Presentation for .NET支持 PPT、PPS、PPTX、PPSX 格式的 PowerPoint文档,支持的主要功能有写入文本、插入图片、添加图形、表格、动画效果、音频和视频等元素到幻灯片。Spire.Presentation 也支持将幻灯片转换为 EMF、JPG、TIFF、PDF、XPS、SVG、HTML 格式文件。


PPT管理工具Spire.Presentation这些基本操作你都学会了吗 width=

1. 问:如何给PowerPoint文档添加密码保护/span>

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

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

2. 问:如何转换PowerPoint文件到PDF/span>

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

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

3. 问:如何将幻灯片保存成图片/span>

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

Presentation ppt = new Presentation();ppt.LoadFromFile(@"F:testingSample.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); }

4. 问:如何设置文本框中文本的对齐方式/span>

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

Presentation presentation = new Presentation();//添加一个shapeIAutoShape 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);

5. 问:如何提取PowerPoint中的文本/span>

答:请您使用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); } } } } }

6. 问:如何用图片填充形状/span>

答:请使用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:UsersAdministratorDesktopimage.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);

还想要更多吗可以点击阅读【2019 · E-iceblue最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时联系客服,我们很高兴为您提供查询和咨询
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年1月12日
下一篇 2020年1月12日

相关推荐

发表回复

登录后才能评论