我需要使用 c# Interop 库解析一个 powerpoint 文件。
我知道如何获取文本值,但我不知道如何获取图片数据。
例如,PowerPoint幻灯片由文字和图片组成,如下所示。
使用此代码,我可以识别标题文本,但如何获取图像数据?
private static void parse(string pptPath)
{
Application app = new Application();
string presentation = pptPath;
Presentation p = app.Presentations.Open(presentation, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
foreach (Slide slide in p.Slides)
{
foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes)
{
if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue)
{
var textFrame = shape.TextFrame;
if (textFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
{
var textRange = textFrame.TextRange;
Console.WriteLine(textRange.Text.ToString());
}
}
}
}
}