【发布时间】:2021-01-29 13:39:28
【问题描述】:
我正在尝试使用 OpenXML 遍历 PowerPoint 演示文稿中的图像。
我已经想出了如何做到这一点。
我现在正在尝试获取图像替代文本标题....
这是我的代码:
List<ImagePart> imageParts = new List<ImagePart>();
part.GetPartsOfType<ImagePart>(imageParts);
foreach (ImagePart imagePart in imageParts)
{
if (imagePart != null)
{
// Get the Relationship Id
string oldRelID = part.GetIdOfPart(imagePart);
// Get the Alt-Text Tile relating to this image
}
}
有没有 OpenXML 专家可以给我一些指点?
谢谢
更新:
我已经尝试遍历 XML,但是当幻灯片上有多个图像时,我得到的相关图像的标题值不正确。
我想我需要能够使用 ImagePart Id 来找到相应的标题
下面的代码使标题乱序...
foreach (ImagePart imagePart in imageParts)
{
string mapReference = "";
XmlNode thisNode = pictureNodeList[imageCounter];
foreach (XmlNode xmlnode in thisNode)
{
foreach (XmlNode xmlchildnode in xmlnode)
{
foreach (XmlAttribute att in xmlchildnode.Attributes)
{
if (att.Name == "title")
{
mapReference = att.Value;
imageCounter += 1;
}
}
}
}
}
【问题讨论】:
-
这是我如何找到这些东西的方法:使用您想要的内容创建一个文档(带有替代文本的图像),然后在 XML 文件中查找它。这应该为您提供了足够的信息来弄清楚如何访问所需的信息。
标签: c# openxml openxml-sdk