如何通过C#/VB.NET代码将PowerPoint转换为HTML

科技资讯 投稿 5600 0 评论

如何通过C#/VB.NET代码将PowerPoint转换为HTML

    将PowerPoint演示文稿转换为HTML
  • 将特定的PowerPoint幻灯片转换为HTML

程序环境

本次测试时,在程序中引入Free Spire.Presentation for .NET。可通过以下方法引用 Free Spire.Presentation.dll文件:

方法1:将 Free Spire.Presentation for .NET下载到本地,解压,安装。安装完成后,找到安装路径下BIN文件夹中的 Spire.Presentation.dll。然后在Visual Studio中打开“解决方案资源管理器”,鼠标右键点击“引用”,“添加引用”,将本地路径BIN文件夹下的dll文件添加引用至程序。

方法2:通过NuGet安装。可通过以下2种方法安装:

(2)将以下内容复制到PM控制台安装。

Install-Package FreeSpire.Presentation -Version 7.8.0

将PowerPoint演示文稿转换为HTML

Presentation.SaveToFile(String, FileFormat 方法用于将PowerPoint演示文稿转换为其他文件格式,如PDF、XPS和HTML。在以下步骤中,我们将向您展示如何使用Free Spire.Presentation for .NET将PowerPoint演示文稿转换为HTML:

    初始化Presentation类的实例。
  • 使用Presentation.LoadFromFile(String 方法加载PowerPoint演示文稿。
  • 使用Presentation.SaveToFile(String, FileFormat 方法将PowerPoint演示文稿保存为HTML格式。

完整代码

using Spire.Presentation;
using System;

namespace ConvertPowerPointToHtml
{
    class Program
    {
        static void Main(string[] args
        {
            //初始化Presentation类的实例
            Presentation ppt = new Presentation(;
            //加载PowerPoint演示文稿
            ppt.LoadFromFile("柯基.pptx";

            //指定输出HTML文件的文件路径
            String result = " D:\\.NET\\PowerPoint\\PowerPointToHtml.html";

            //将PowerPoint演示文稿保存为HTML格式
            ppt.SaveToFile(result, FileFormat.Html;
        }
    }
}

VB.NET

Imports Spire.Presentation Namespace ConvertPowerPointToHtml Friend Class Program Private Shared Sub Main(ByVal args As String( '初始化Presentation类的实例 Dim ppt As Presentation = New Presentation( '加载PowerPoint演示文稿 ppt.LoadFromFile("柯基.pptx" '指定输出HTML文件的文件路径 Dim result = " D:\\.NET\\PowerPoint\\PowerPointToHtml.html" '将PowerPoint演示文稿保存为HTML格式 ppt.SaveToFile(result, FileFormat.Html End Sub End Class End Namespace

效果图

将特定的PowerPoint幻灯片转换为HTML

ISlide.SaveToFile(String, FileFormat 方法可以将PowerPoint幻灯片转换为HTML。具体步骤如下:

    初始化Presentation类的实例。
  • 使用Presentation.LoadFromFile( 方法加载PowerPoint演示文稿。
  • 通过Presentation.Slides[int] 属性按索引获取PowerPoint演示文稿中的特定幻灯片。
  • 使用ISlide.SaveToFile(String, FileFormat 方法将PowerPoint幻灯片保存为HTML格式。

完整代码

using Spire.Presentation;
using System;

namespace ConvertPowerPointSlideToHtml
{
    class Program
    {
        static void Main(string[] args
        {
            //初始化Presentation类的实例
            Presentation presentation = new Presentation(;
            //加载PowerPoint演示文稿
            presentation.LoadFromFile("柯基.pptx";

            //获取特定幻灯片
            ISlide slide = presentation.Slides[5];

            //指定输出HTML文件的文件路径
            String result = " D:\\.NET\\PowerPoint\\SlideToHtml.html ";

            //将第一张幻灯片保存为HTML格式
            slide.SaveToFile(result, FileFormat.Html;
        }
    }
}

VB.NET

Imports Spire.Presentation Namespace ConvertPowerPointSlideToHtml Friend Class Program Private Shared Sub Main(ByVal args As String( '初始化Presentation类的实例 Dim presentation As Presentation = New Presentation( '加载PowerPoint演示文稿 presentation.LoadFromFile("柯基.pptx" '获取特定幻灯片 Dim slide As ISlide = presentation.Slides(5 '指定输出HTML文件的文件路径 Dim result = " D:\.NET\PowerPoint\SlideToHtml.html " '将第一张幻灯片保存为HTML格式 slide.SaveToFile(result, FileFormat.Html End Sub End Class End Namespace

效果图

 

编程笔记 » 如何通过C#/VB.NET代码将PowerPoint转换为HTML

赞同 (29) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽