- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
目前我有一个用 C# 编写的 WPF 应用程序,但我发现很难找到任何有用的方法将 PowerPoint 演示文稿嵌入到我的窗口中。
我在这里找到了一个解决方案:Embedding a Powerpoint show into a C# application
此解决方案产生了让 PowerPoint 在另一个窗口中运行但仅在 WPF 应用程序中显示其 UI 的问题。这意味着当 WPF 窗口获得焦点时,PowerPoint 演示文稿没有,并停止播放。还有关闭窗口时PowerPoint崩溃的问题。
我在这里找到了另一个解决方案:http://www.codeproject.com/Articles/118676/Embedding-PowerPoint-presentation-player-into-a-WP
该解决方案很受欢迎,但我发现它很难使用。我不知道任何 Win32 编程或 C++,所以我发现修改起来非常困难。我设法让它停止显示 PowerPoint 的第二个副本(原始项目中的预期功能),但我还没有找到自动打开 PowerPoint 演示文稿的方法。
所以我需要的是一种在后台自动干净地打开 PowerPoint 演示文稿的方法(我不希望 PowerPoint UI 在任何时候都显示),并允许它自动运行(并且不响应输入)在应用程序运行时。如果我可以将它保留在 C# 和 WPF 中,而不必处理 Win32 和 C++,那就太好了。
这可能吗?在这一点上,我真的很后悔这个项目,因为 PowerPoint 集成令人头疼。
最佳答案
您可以即时将演示文稿转换为视频格式:
// not tested as I don't have the Office 2010, but should work
private string GetVideoFromPpt(string filename)
{
var app = new PowerPoint.Application();
var presentation = app.Presentations.Open(filename, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
var wmvfile = Guid.NewGuid().ToString() + ".wmv";
var fullpath = Path.GetTempPath() + filename;
try
{
presentation.CreateVideo(wmvfile);
presentation.SaveCopyAs(fullpath, PowerPoint.PpSaveAsFileType.ppSaveAsWMV, MsoTriState.msoCTrue);
}
catch (COMException ex)
{
wmvfile = null;
}
finally
{
app.Quit();
}
return wmvfile;
}
然后您将使用 MediaElement
播放它:
<MediaElement Name="player" LoadedBehavior="Manual" UnloadedBehavior="Stop" />
public void PlayPresentation(string filename)
{
var wmvfile = GetVideoFromPpt(filename);
player.Source = new Uri(wmvfile);
player.Play();
}
当您播放完视频后,不要忘记 File.Delete(wmvfile)
!
关于c# - 如何在不打开另一个窗口的情况下将 PowerPoint 演示文稿嵌入到 WPF 应用程序中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15725908/
我是一名优秀的程序员,十分优秀!