【问题标题】:How to open powerpoint from Windows 8.1 app如何从 Windows 8.1 应用程序打开 powerpoint
【发布时间】:2016-11-11 20:23:45
【问题描述】:

我正在尝试构建一个 Windows 8.1 应用程序,它可以从本地计算机全屏打开 powerpoint 文件,其中包含三个按钮来执行下一个、上一个和退出。我可以使用winform做到这一点,但在WPF中却不行。在winform中,我使用了嵌入ppt的面板控件。面板被 WPF 中的画布取代,但我不知道如何将 ppt 嵌入其中。有没有除此之外的其他方法请分享?我不能使用 XPS,因为它不支持任何动画。

        //System.Diagnostics.Process.Start("POWERPNT.EXE",     "C:/Users/SAURABH/Desktop/office/Engineer's.pptx");
        //    Microsoft.Office.Interop.PowerPoint.Application   application;

        //    // For Display in Panel
        //    IntPtr screenClasshWnd = (IntPtr)0;
        //    IntPtr x = (IntPtr)0;


        //    application = new Microsoft.Office.Interop.PowerPoint.Application();

        //    Microsoft.Office.Interop.PowerPoint.Presentation presentation = application.Presentations.Open(@"C:\Users\delink\Documents\SAMPLE_PPT.pptx", MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
        //    pptViewPanel.Children.Add(application as Control);
        //    //pptViewPanel.Controls.Add(application as Control);
        //    Microsoft.Office.Interop.PowerPoint.SlideShowSettings sst1 = presentation.SlideShowSettings;

        //    sst1.LoopUntilStopped = Microsoft.Office.Core.MsoTriState.msoTrue;

        //    Microsoft.Office.Interop.PowerPoint.Slides objSlides = presentation.Slides;

        //    sst1.LoopUntilStopped = MsoTriState.msoTrue;

        //    sst1.StartingSlide = 1;
        //    sst1.EndingSlide = objSlides.Count;

        //   // pptViewPanel.Dock = DockStyle.Fill;

        //    sst1.ShowType = Microsoft.Office.Interop.PowerPoint.PpSlideShowType.ppShowTypeKiosk;

        //    Microsoft.Office.Interop.PowerPoint.SlideShowWindow sw = sst1.Run();
        //    //sw=Objssws
        //    oSlideShowView = presentation.SlideShowWindow.View;

        //    IntPtr pptptr = (IntPtr)sw.HWND;
        // SetParent(pptptr, pptViewPanel.handle);**"**this where I am getting-"in 'pptviewpanel.handle'"** rror"**

【问题讨论】:

    标签: wpf canvas powerpoint


    【解决方案1】:

    您可以即时将演示文稿转换为视频格式:

    // 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)!

    【讨论】:

    • Thanx,但我需要它与用户交互意味着用户可以切换下一张和上一张幻灯片的黑白
    • 恐怕,您可能需要使用下一个/上一个按钮在应用程序内部创建幻灯片作为控件。否则你为什么不直接从应用程序中打开ppt 文件?
    • 如果您准备好为此花点时间阅读这篇文章:codeproject.com/Articles/118676/…
    • 它有帮助....但现在我现在面临另一个问题。我无法在打开的 ppt 上设置按钮。当我启动应用程序时,按钮确实出现了,但是当我在幻灯片拍摄的整个屏幕上启动 ppt 时。我想在它上面设置按钮,这样我就可以控制 ppt 并且 ppt 动画也不起作用。
    猜你喜欢
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    • 2016-01-31
    • 2011-07-07
    • 1970-01-01
    • 1970-01-01
    • 2015-06-07
    • 2016-10-16
    相关资源
    最近更新 更多