C#C#/VB.NET 向PowerPoint文书档案插入录制

最近,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官网下载安装。

下边是事无巨细步骤:

小心:在成立项目后,添加相关.dll文件作为项目引用。

代码片段:

步骤1:新建多个PPT文书档案。

Presentation presentation = new Presentation();

步骤2:使用presentation.Slides[0].Shapes.AppendVideoMedia()方法来插入录像。

presentation.Slides[0].Shapes.AppendVideoMedia(@"小毛驴.mp4", new RectangleF(100, 100, 20, 20));  //用户可以根据自己的需要来设置参数的大小

步骤3:增加形状来呈现文本并保存PPT文书档案。

IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 150, 600, 250));  //用户可以根据自己的需要来设置参数的大小

presentation.SaveToFile("video.pptx", FileFormat.Pptx2010);

 

效果图:

C# 1                       

 

C#,方方面面代码:

C#:

using System.Drawing;

using System.IO;

using Spire.Presentation;

using Spire.Presentation.Drawing;

namespace InsertVideo

{

    class Program

    {

        static void Main(string[] args)

        {

            Presentation presentation = new Presentation();



            //设置背景图片

            string ImageFile = @"花朵.jpg";

            RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);

            presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);

            presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;



            presentation.Slides[0].Shapes.AppendVideoMedia(@"小毛驴.mp4", new RectangleF(100, 100, 20, 20));



            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 150, 600, 250));

            shape.ShapeStyle.LineColor.Color = Color.White;

            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;

            shape.AppendTextFrame("我有一只小毛驴我从来也不骑,有一天我心血来潮骑着去赶集,");



            shape.TextFrame.Paragraphs.Append(new 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("video.pptx", FileFormat.Pptx2010);

            System.Diagnostics.Process.Start("video.pptx");

        }

    }

}

VB.NET:

Imports System.Drawing
Imports System.IO
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Module Module1

    Sub Main()
        Dim presentation As New Presentation()

        '设置背景图片
        Dim ImageFile As String = "花朵.jpg"
        Dim rect As New RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height)
        presentation.Slides(0).Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect)
        presentation.Slides(0).Shapes(0).Line.FillFormat.SolidFillColor.Color = Color.FloralWhite

        presentation.Slides(0).Shapes.AppendVideoMedia("小毛驴.mp4", New RectangleF(100, 100, 20, 20))

        Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 150, 600, 250))
        shape.ShapeStyle.LineColor.Color = Color.White
        shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None
        shape.AppendTextFrame("我有一只小毛驴我从来也不骑,有一天我心血来潮骑着去赶集,")

        shape.TextFrame.Paragraphs.Append(New TextParagraph())
        shape.TextFrame.Paragraphs(1).TextRanges.Append(New TextRange("我手里拿着小皮鞭我心里正得意,不知怎么哗啦啦啦我摔了一身泥。"))
        For Each para As TextParagraph 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
        Next

        presentation.SaveToFile("video.pptx", FileFormat.Pptx2010)
        System.Diagnostics.Process.Start("video.pptx")
    End Sub

End Module

 

相关文章