Powerpoint Viewer控件C#/ VB / .NET

时间:2012-03-08 17:08:38

标签: .net powerpoint

任何人都知道如何制作一个或如何下载控件以查看powerpoint文档?

我已经搜索过,但唯一出现的是this,这显然不是免费的。我确信微软必须拥有一个可以执行此操作的控件。

让一个控件做到这一点也欢迎。

2 个答案:

答案 0 :(得分:4)

这里有解决我所关注的问题的方法。  如果有人遇到同样的问题,我会在这里离开这里,经过几个小时的工作后,我就得到了解决方案。

        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        static extern IntPtr FindWindow(IntPtr ZeroOnly, string lpWindowName);

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern bool SetWindowText(IntPtr hwnd, String lpString);


        private string FileName = "";
        PowerPoint.Application application;
        PowerPoint.Presentation presentation;
        bool flag = false;

        public UserControl1()
        {
            InitializeComponent();
        }


        public void open()
        {
            sair();

            openFileDialog1.Filter = "Powerpoint file (*.ppt)|*.ppt|All files (*.*)|*.*";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileName = openFileDialog1.FileName;

                IntPtr screenClasshWnd = (IntPtr)0;
                IntPtr x = (IntPtr)0;

                flag = true;

                application = new PowerPoint.Application();
                presentation = application.Presentations.Open2007(FileName, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue);
                PowerPoint.SlideShowSettings sst1 = presentation.SlideShowSettings;


                sst1.ShowType = (PowerPoint.PpSlideShowType)1;
                PowerPoint.SlideShowWindow sw = sst1.Run();


                sw.Height = (panel1.Height) - 64;
                sw.Width = (panel1.Width) - 130;

                IntPtr formhWnd = FindWindow(x, "Form1");
                IntPtr pptptr = (IntPtr)sw.HWND;
                screenClasshWnd = FindWindow(x, "screenClass");
                SetParent(pptptr, panel1.Handle);

                this.Focus();

                this.application.SlideShowEnd += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowEndEventHandler(SlideShowEnds);
            }
        }

答案 1 :(得分:1)

最简单的方法是使用PowerPoint Interop命名空间。您可以在MSDN site上阅读相关内容。需要注意的是,它需要您安装PowerPoint。因此,如果这将是商业软件,那将是没有意义的,因为客户不得不购买PowerPoint。但是对于许多任务来说,它非常漂亮,并且使用.NET 4.0可以轻松地使用MS Office。