简体   繁体   English

如何使用OpenXml(MS Word)获取绘图的图像ID?

[英]How to get an image id of a Drawing with OpenXml (MS Word)?

I need to get relationship id of a Drawing object to extract images from Word using OpenXml . 我需要获取Drawing对象的关系id以使用OpenXml从Word中提取图像。 I saw Replace image in word doc using OpenXML and I'm using this code now: 使用OpenXML在word doc中看到了替换图像,我现在正在使用此代码:

string imageId = "default value";
Blip blipElement = selectedImage.Descendants<Blip>().First();
if (blipElement != null) {
    imageId = blipElement.Embed.Value;
}
document.MainDocumentPart.GetPartById(imageId);

Works perfectly for usual images, but doesn't work for powerpoint slides which are stored as EMF images inside docx, because EMF Drawing's don't have Blip . 适用于通常的图像,但不适用于在docx中存储为EMF图像的powerpoint幻灯片,因为EMF Drawing没有Blip But they have ImageParts just like the usual images and I can see them. 但他们有像常规图像一样的ImageParts ,我可以看到它们。 So, the question is, how do I find an imageId from a Drawing to get those EMF ImageParts? 所以,问题是,如何从Drawing中找到imageId来获取EMF ImageParts? Unfortunately, I can't extract images the other way, because I'm trying to inject my code into a huge existing codebase, so I need to get it from a Drawing object. 不幸的是,我无法以其他方式提取图像,因为我试图将我的代码注入到一个庞大的现有代码库中,所以我需要从Drawing对象中获取它。

Ok, so the problem was that I was looking at a wrong thing. 好吧,问题是我看错了。 The Drawing without a Blip that I saw was actually a chart (Insert->Chart), not a PP slide. 我看到的没有Blip的Drawing实际上是一个图表(Insert-> Chart),而不是PP幻灯片。 Here is the xml for it: http://pastebin.com/9vyBJDLh There is a chart relation for it pointing to chart1.xml in /charts/ folder. 这是它的xml: http ://pastebin.com/9vyBJDLh它有一个图表关系,指向/ charts /文件夹中的chart1.xml。 And there is no EMF generated for the chart. 并且没有为图表生成EMF。

The slides inserted via "Insert->Object->Microsoft PowerPoint Slide" have completely different format, they are not Drawings and must be handled separately: http://pastebin.com/JJ3piJi3 and rId in imageData element actually points to EMF file under /media/ folder. 通过“插入 - >对象 - > Microsoft PowerPoint幻灯片”插入的幻灯片具有完全不同的格式,它们不是绘图,必须单独处理: http ://pastebin.com/JJ3piJi3和imageData元素中的rId实际指向EMF文件/ media /文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM