引言
优化 powerpoint 演示文稿中的幻灯片顺序是一项简单但实用的技能。通过重新排列幻灯片,你可以完善演示文稿的逻辑与流程,将相关内容归类,或将某些幻灯片移动到更具影响力的位置。这种灵活性使你能够打造连贯且引人入胜的叙事,让观众更专注于你的演示内容。
本文将演示如何使用 spire.presentation for .net 库,通过 c# 编程方式更改 powerpoint 文档中的幻灯片顺序。
安装 spire.presentation for .net
首先,需要将 spire.presentation for .net 包中包含的 dll 文件添加为 .net 项目的引用。这些 dll 文件可以通过指定链接下载,或通过 nuget 进行安装。
pm> install-package spire.presentation
在 c# 中更改 powerpoint 文档的幻灯片顺序
要重新排列 powerpoint 演示文稿中的幻灯片顺序,可以创建两个 presentation 对象——一个用于加载原始文档,另一个用于创建新文档。通过按所需顺序将原始文档中的幻灯片复制到新文档中,你可以轻松地调整幻灯片的排列顺序。
示例代码如下:
using spire.presentation;
namespace changeslideorder
{
class program
{
static void main(string[] args)
{
//创建一个 presentation 对象
presentation presentation = new presentation();
//加载 powerpoint 文件
presentation.loadfromfile("c:\\users\\administrator\\desktop\\input.pptx");
//在数组中指定新的幻灯片顺序
int[] newslideorder = new int[] { 4, 2, 1, 3 };
//创建另一个 presentation 对象
presentation new_presentation = new presentation();
//删除默认幻灯片
new_presentation.slides.removeat(0);
//遍历数组
for (int i = 0; i < newslideorder.length; i++)
{
//按新的顺序将原 powerpoint 文件中的幻灯片添加到新文档中
new_presentation.slides.append(presentation.slides[newslideorder[i] - 1]);
}
//将新演示文稿保存到文件
new_presentation.savetofile("neworder.pptx", fileformat.pptx2019);
//释放资源
presentation.dispose();
new_presentation.dispose();
}
}
}申请临时许可证
如果你希望从生成的文档中去除评估信息,或解除功能限制,请为自己申请一个 30 天的试用许可证。
到此这篇关于使用c#代码更改powerpoint文档中的幻灯片顺序的文章就介绍到这了,更多相关c#更改powerpoint幻灯片顺序内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论