我正在浏览docx,使用open xml来查找一些图像.
所以,我这样做是为了得到所有的图纸,它有一个docProperties作为孩子,标题包含
List<Drawing> sdtElementDrawing = wordDoc.MainDocumentPart.Document.Descendants<Drawing>()
.Where(element =>
element.GetFirstChild<Drawing>() != null
&& element.GetFirstChild<DocProperties>().Title.Value.Contains("IMAGE")).ToList();
Run Code Online (Sandbox Code Playgroud)
而docx作为xml看起来在第一部分看起来很喜欢(它通常更大,但我只复制相关部分):
<w:drawing>
<wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="1" locked="0" layoutInCell="1" allowOverlap="1" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing">
<wp:simplePos x="0" y="0" />
<wp:positionH relativeFrom="column">
<wp:posOffset>2171700</wp:posOffset>
</wp:positionH>
<wp:positionV relativeFrom="paragraph">
<wp:posOffset>-1168400</wp:posOffset>
</wp:positionV>
<wp:extent cx="2286000" cy="746760" />
<wp:effectExtent l="0" t="0" r="0" b="0" />
<wp:wrapNone />
<wp:docPr id="1" name="Image 1" descr="C:\Users\Pictures\IMAGERM.jpg" title="IMAGERM" />
</wp:anchor>
</w:drawing>
Run Code Online (Sandbox Code Playgroud)
但我没有找到sdtElementDrawing.
所以我想我错误地写了这个sdtElementDrawing查询.我必须错过一个明显的方式来告诉"得到绘图的孩子,哪里有一个像IMAGE这样的标题的DocProperties",但我找不到它.
我也试过这个,但效果不好:
List<Drawing> sdtElementDrawing = wordDoc.MainDocumentPart.Document.Descendants<Drawing>()
.Where(element =>
element.GetFirstChild<Drawing>() != null &&
element.GetFirstChild<Drawing>().Anchor.GetFirstChild<DocProperties>().Title.Value.Contains("IMAGE")).ToList();
Run Code Online (Sandbox Code Playgroud)
你试过这个吗?
List<Drawing> sdtElementDrawing = wordDoc.MainDocumentPart.Document.Descendants<Drawing>()
.Where(element => element.Descendants<DocProperties>().Any(
prop => prop.Title.Value.ToUpper().Contains("IMAGE")
)).ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1008 次 |
| 最近记录: |