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

前端 未结 2 1624
忘掉有多难
忘掉有多难 2021-01-14 22:03

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 Read         


        
相关标签:
2条回答
  • 2021-01-14 22:05

    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 + " ";
                        }
                    }
                }
    }
    
    0 讨论(0)
  • 2021-01-14 22:13

    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.

    0 讨论(0)
提交回复
热议问题