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

前端 未结 2 1623
忘掉有多难
忘掉有多难 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 + " ";
                        }
                    }
                }
    }
    

提交回复
热议问题