如今,Microsoft Office PowerPoint在我们日常生活中的应用已经很广泛了,利用Microsoft Office PowerPoint不仅可以创建演示文稿,还可以在互联网上召开面对面会议、远程会议或在网上给观众展示演示文稿等。那么,怎样做出有趣、生动、美观的PowerPoint文档呢?其中一个很好的选择就是向文档中插入视频。这样可以使读者更好地理解文档的内容,增加读者的兴趣。那么开发者如何通过编程的方式来实现这一功能呢?本文将给大家分享如何使用免费版PowerPoint组件—Spire.Presentation以C#/VB.NET编程的方式来向PPT文档插入视频。
Spire.Presentation简介
Spire.Presentation for .NET是一款专业的PowerPoint兼容组件,使开发人员能够在.NET平台(C#,VB.NET,ASP.NET)上创建,读,写,修改,转换和打印PowerPoint文档,并且不需要安装Microsoft PowerPoint软件。Spire.Presentation for .NET 支持的格式有PPT,PPS,PPTX及PPSX。它提供了很多实用的功能,如管理文本,图像,形状,表格,动画,音频和视频等。此外,它还支持将幻灯片导出为EMF,JPG,TIFF,PDF等格式。
有需要的朋友可以从E-iceblue官网下载安装。
下面是详细步骤:
代码片段:
步骤1:新建一个PPT文档。
Presentation presentation = new Presentation();
步骤2:使用presentation.Slides[0].Shapes.AppendVideoMedia()方法来插入视频。
presentation.Slides[0].Shapes.AppendVideoMedia(@"小毛驴.mp4",new RectangleF(100,20,1)">20)); //用户可以根据自己的需要来设置参数的大小
步骤3:添加形状来展示文本并保存PPT文档。
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle,1)">50,1)">150,1)">600,1)">250)); 用户可以根据自己的需要来设置参数的大小 presentation.SavetoFile("video.pptx效果图:
全部代码:
C#:
using System.Drawing; System.IO; Spire.Presentation; Spire.Presentation.Drawing; namespace InsertVideo { class Program { static void Main(string[] args) { Presentation presentation = new Presentation(); 设置背景图片 string ImageFile = 花朵.jpg"; RectangleF rect = 0,1)">0,presentation.SlideSize.Size.Width,presentation.SlideSize.Size.Height); presentation.Slides[].Shapes.AppendEmbedImage(ShapeType.Rectangle,ImageFile,rect); presentation.Slides[0].Shapes[0].Line.FillFormat.solidFillColor.Color = Color.floralWhite; presentation.Slides[20)); IAutoShape shape = presentation.Slides[250)); shape.Shapestyle.LineColor.Color = Color.White; shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None; shape.AppendTextFrame(我有一只小毛驴我从来也不骑,有一天我心血来潮骑着去赶集,); shape.TextFrame.Paragraphs.Append( TextParagraph()); shape.TextFrame.Paragraphs[1].TextRanges.Append(new TextRange(我手里拿着小皮鞭我心里正得意,不知怎么哗啦啦啦我摔了一身泥。)); foreach (TextParagraph para in shape.TextFrame.Paragraphs) { para.TextRanges[0].LatinFont = new TextFont(Arial Rounded MT Bold); para.TextRanges[0].Fill.FillType = FillFormatType.solid; para.TextRanges[0].Fill.solidColor.Color = Color.Black; para.Alignment = TextAlignmentType.Left; para.Indent = 35; } presentation.SavetoFile(stem.Diagnostics.Process.Start(); } } }VB.NET:
Imports System.Drawing System.IO Spire.Presentation Spire.Presentation.Drawing Module Module1 Sub Main() Dim presentation As New Presentation() '设置背景图片 Dim ImageFile String = " Dim rect New RectangleF().Shapes.AppendEmbedImage(ShapeType.Rectangle,rect) presentation.Slides(0).Shapes(0).Line.FillFormat.solidFillColor.Color = Color.floralWhite presentation.Slides(0).Shapes.AppendVideoMedia()) Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle,1)">)) shape.Shapestyle.LineColor.Color = Color.White shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None shape.AppendTextFrame() shape.TextFrame.Paragraphs.Append( TextParagraph()) shape.TextFrame.Paragraphs(1).TextRanges.Append(New TextRange()) For Each para As TextParagraph In shape.TextFrame.Paragraphs para.TextRanges(0).LatinFont = New TextFont() para.TextRanges(0).Fill.FillType = FillFormatType.solid para.TextRanges(0).Fill.solidColor.Color = Color.Black para.Alignment = TextAlignmentType.Left para.Indent = 35 Next presentation.SavetoFile(stem.Diagnostics.Process.Start() End Sub End Module
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。