问题描述
PowerPoint.Applicationpa=newPowerPoint.ApplicationClass();PowerPoint.Presentationpp=pa.Presentations.Open(fileName,Microsoft.Office.Core.MsoTriState.msoTrue,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoFalse);Console.WriteLine("OpenSuccess");PowerPoint.TextFrameframe;Stringtext="";foreach(PowerPoint.Slideslideinpp.Slides){foreach(PowerPoint.Shapeshapeinslide.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循环外面
不行啊。。
解决方案四:
加载引用MicrosoftPowerPoint12.0objectlibrary和morcosoftoffice12.0objectLibrary其中的数字是版本号,低点不要紧。代码:publicstringPptReader(stringfilename){stringfullname=DocPath+filename;//绝对路径PowerPoint.Applicationpapp=newPowerPoint.Application();PowerPoint.Presentationppr=papp.Presentations.Open(fullname,Microsoft.Office.Core.MsoTriState.msoCTrue,MsoTriState.msoFalse,MsoTriState.msoFalse);stringdoc="";foreach(PowerPoint.Slideslideinppr.Slides){foreach(PowerPoint.Shapeshapeinslide.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;returndoc;}