【问题标题】:How to get a list of all Embed values?如何获取所有嵌入值的列表?
【发布时间】:2015-09-15 20:23:01
【问题描述】:

我有一个包含多张图片的 docx 文件。 document.xml 看起来像这样(多次):

 .... 
 <w:drawing>
        <a:blip r:embed="rId12">
     ....
        </a:blip>
</w:drawing>

如何使用 LINQ 获取嵌入值列表?

我有这个,但不起作用:

string[] imageIds =                   
   (string[]) (from drawing in docx.MainDocumentPart.Document.Descendants<Drawing>()
    where drawing.Descendants<A.Blip>().First<A.Blip>() != null
    select drawing.Descendants<A.Blip>().First().Embed.Value);

【问题讨论】:

  • 没有解释docx 到底是什么以及是否应该在答案中使用它。

标签: c# linq openxml


【解决方案1】:

应该可以的:

XNamespace a = "http://youranamespaceurl.com";
XNamespace r = "http://yourrnamespaceurl.com";
var embedes = from el in docx.MainDocumentPart.Document.Descendants(a + "blip")
select (string)el.Attribute(r + "embed") 

【讨论】:

  • 不确定我是否理解你
  • .属性在 VS2013 中带有红色下划线。 blip 没有成员函数“属性”
猜你喜欢
  • 2018-06-30
  • 1970-01-01
  • 2020-03-14
  • 1970-01-01
  • 2013-04-17
  • 1970-01-01
  • 2023-02-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多