当前位置:编程学习 > C#/ASP.NET >>

.net操作PPT的读取问题

 PowerPoint.Application pa = new PowerPoint.ApplicationClass();

                PowerPoint.Presentation pp = pa.Presentations.Open(fileName,
                      Microsoft.Office.Core.MsoTriState.msoTrue,
                      Microsoft.Office.Core.MsoTriState.msoFalse,
                      Microsoft.Office.Core.MsoTriState.msoFalse);
                Console.WriteLine("Open Success");
                PowerPoint.TextFrame frame;
                String text="";

                foreach (PowerPoint.Slide slide in pp.Slides)
                {
                    foreach (PowerPoint.Shape shape in slide.Shapes)
                    {
                        
                        if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue)
                        {
                            frame = shape.TextFrame;
                            if (frame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
                            {

                                text = frame.TextRange.Text.ToString();
                                Console.WriteLine(text);
             
                            }
                        }
上面是我读取PPT文本的代码,但是它是一行一行输出。。。我想一个PPT一下读取,全部输出。。而不是一行一行。 --------------------编程问答--------------------  Console.WriteLine(text);
那你把这行代码放第二个for循环外面 --------------------编程问答--------------------
引用 1 楼 hxlaccp168 的回复:
 Console.WriteLine(text);
那你把这行代码放第二个for循环外面

不行啊。。 --------------------编程问答-------------------- 加载引用Microsoft Power Point 12.0 object library 和morcosoft office12.0 object Library

其中的数字是版本号,低点不要紧。

代码:

    public string PptReader(string filename)
    {
        string fullname = DocPath+filename;     //绝对路径
        PowerPoint.Application papp = new PowerPoint.Application();
        PowerPoint.Presentation ppr = papp.Presentations.Open(fullname, Microsoft.Office.Core.MsoTriState.msoCTrue,
            MsoTriState.msoFalse, MsoTriState.msoFalse);
        string doc = "";
        foreach (PowerPoint.Slide slide in ppr.Slides)
        {
            foreach (PowerPoint.Shape shape in slide.Shapes)
            {
                if (shape.HasTextFrame == MsoTriState.msoTrue)
                {
                    if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                    {
                        doc += shape.TextFrame.TextRange.Text.ToString();
                        doc += "\n";
                    }
                }
                
            }
        }

        ppr.Close();
        System.Runtime.InteropServices.Marshal.ReleaseComObject(ppr);
        ppr = null;
        papp.Quit();
        System.Runtime.InteropServices.Marshal.ReleaseComObject(papp);
        papp = null;
        return doc;
    }

补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,