继续ppt!
加载引用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;
}
本文介绍了一种使用C#代码从PowerPoint演示文稿中提取文本内容的方法。该方法通过加载Microsoft PowerPoint 12.0 和 Microsoft Office 12.0 对象库,创建PowerPoint应用程序实例并打开指定文件来实现。对于演示文稿中的每张幻灯片,遍历其形状对象以检查是否有文本框,并将所有文本内容收集到字符串变量中。
3494

被折叠的 条评论
为什么被折叠?



