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一下读取,全部输出。。而不是一行一行。
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一下读取,全部输出。。而不是一行一行。
那你把这行代码放第二个for循环外面
{
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;
}