如何从Windows 8.1应用程序打开powerpoint

时间:2021-08-15 03:40:44

I am trying to build an windows 8.1 app that open powerpoint file from local computer in full screen, and within that it contain three buttons to perform next ,previous and exit. I was able to do so using winform but not in WPF. In winform I used panel control in which I embedded the ppt. panel is replaced by canvas in WPF but I do not know how I can embed ppt in it. is there any other approach than this please share? I can not use XPS as it does not support any animation.

我正在尝试构建一个Windows 8.1应用程序,它可以全屏从本地计算机打开powerpoint文件,并在其中包含三个按钮,可以执行下一个,上一个和退出。我能够使用winform但不能在WPF中这样做。在winform中,我使用了面板控件,其中嵌入了ppt。在WPF中,canvas被canvas替换,但我不知道如何在其中嵌入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"**

2 个解决方案

#1


0  

Have a look at this article, it may be what you are looking for

看看这篇文章,它可能就是你要找的东西

How can I embed a PowerPoint presentation into a WPF application without opening another window?

如何在不打开另一个窗口的情况下将PowerPoint演示文稿嵌入到WPF应用程序中?

or a more comprehensive answer at:

或者更全面的答案:

http://www.codeproject.com/Articles/118676

http://www.codeproject.com/Articles/118676

#2


0  

You could convert your presentation to a video format on-the-fly:

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

// 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;
}

And then you would play it with MediaElement:

然后你会用MediaElement播放它:

<MediaElement Name="player" LoadedBehavior="Manual" UnloadedBehavior="Stop" />

public void PlayPresentation(string filename)
{
    var wmvfile = GetVideoFromPpt(filename);
    player.Source = new Uri(wmvfile);
    player.Play();
}

Don't forget to File.Delete(wmvfile) when you're done playing the video!

当你完成视频播放时,不要忘记File.Delete(wmvfile)!

#1


0  

Have a look at this article, it may be what you are looking for

看看这篇文章,它可能就是你要找的东西

How can I embed a PowerPoint presentation into a WPF application without opening another window?

如何在不打开另一个窗口的情况下将PowerPoint演示文稿嵌入到WPF应用程序中?

or a more comprehensive answer at:

或者更全面的答案:

http://www.codeproject.com/Articles/118676

http://www.codeproject.com/Articles/118676

#2


0  

You could convert your presentation to a video format on-the-fly:

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

// 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;
}

And then you would play it with MediaElement:

然后你会用MediaElement播放它:

<MediaElement Name="player" LoadedBehavior="Manual" UnloadedBehavior="Stop" />

public void PlayPresentation(string filename)
{
    var wmvfile = GetVideoFromPpt(filename);
    player.Source = new Uri(wmvfile);
    player.Play();
}

Don't forget to File.Delete(wmvfile) when you're done playing the video!

当你完成视频播放时,不要忘记File.Delete(wmvfile)!