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#:

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ASP.NET 4 是微软推出的一种用于构建动态网站和 Web 应用程序的开发框架。它是ASP.NET技术的升级版本,提供了更多的高级编程功能。在ASP.NET 4高级编程,开发人员可以利用新特性和功能来更好地完成项目,并优化性能。 首先,在ASP.NET 4,引入了一些新的控件,如GridView、Repeater等,这些控件使开发人员能够更加方便地处理数据绑定和呈现,减少了编写重复代码的工作。另外,还可以自定义控件,并使用控件模板来定制页面外观。 其次,ASP.NET 4还引入了一些新的特性,如扩展语法,可以使用C#VB.NET编写更简洁的代码。还可以使用动态数据进行数据访问,简化了数据库操作。同时,还提供了新的验证控件和模型绑定,使数据验证和处理更加方便。 此外,ASP.NET 4还提供了一些性能优化功能。例如,输出缓存可以缓存页面输出,减少重复计算,提高页面加载速度。还可以使用新的ViewState模式来减少页面传输的数据量,提高页面的响应速度。 在安全方面,ASP.NET 4引入了更强大的安全功能。例如,可以使用表单验证和角色管理来实现用户认证和授权。还可以使用ASP.NET的内置防止跨站点脚本攻击功能,保护网站免受恶意脚本的攻击。 总之,ASP.NET 4高级编程为开发人员提供了更多的工具和功能来简化开发工作,并提高了网站和Web应用程序的性能和安全性。开发人员可以根据项目的需求和业务逻辑,灵活应用这些功能,打造出高质量的Web应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值