How to read a PPT file in ASP.NET MVC?

烈酒焚心 提交于 2019-12-01 08:53:09

问题


I have PPT file on desktop named as "slide.ppt". I want to read all slides of this PPT file in my ReadSlide function as below

public void ReadSlide(){


}

How can I read all slide from a PPT file in my C# code?


回答1:


Use as below

public void ReadSlide(){

            string filePath= @"C:\Users\UserName\Slide.pptx";

            Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations;
            Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

            string presentation_textforParent = "";
            foreach (var item in presentation.Slides[1].Shapes)
            {
                var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;
                if (shape.HasTextFrame == MsoTriState.msoTrue)
                {
                    if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                    {
                        var textRange = shape.TextFrame.TextRange;
                        var text = textRange.Text;

                        presentation_textforParent += text + " ";
                    }
                }
            }
}



回答2:


If it was an PPTX, you could read it using OpenXML. Since you specifically asked for PPT, it is a little harder.

You shouldn't use Automation / Interop for sure, since it isn't supported in a server environment.

That means you have to use third-party tools to read the PPT. If you google for them, you will see a long list of them. I have never worked with it, but Aspose seems to do the job very well.



来源:https://stackoverflow.com/questions/29006417/how-to-read-a-ppt-file-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!