简体   繁体   English

在openxml c#中从docx中的表格单元格中获取图像

[英]get image from table cell in docx in openxml c#

Aim: I want to get image from inside of table cell in word document using OpenXML with C#.目标:我想使用 OpenXML 和 C# 从 Word 文档中的表格单元格内部获取图像。 But I dont know which method to use for it.但我不知道该使用哪种方法。

string questionText = cells[1].InnrerText
var questionImage = cells[1]. // <<------ What method to try here?

代码示例图片

The general approach for questions like this is to:此类问题的一般方法是:

  1. look at the Open XML markup (eg, using the Open XML Package Editor for Modern Visual Studios );查看 Open XML 标记(例如,使用Open XML Package Editor for Modern Visual Studios );
  2. identify the Open XML elements (eg, w:tc , w:p , w:drawing , a:graphic , a:blip ) you want to create, read, update, or delete;确定要创建、读取、更新或删除的 Open XML 元素(例如, w:tcw:pw:drawinga:graphica:blip );
  3. map those to the strongly typed classes of the Open XML SDK, eg:将它们映射到 Open XML SDK 的强类型类,例如:
    • TableCell (for w:tc ), TableCell (对于w:tc ),
    • Paragraph (for w:p ), Paragraph (对于w:p ),
    • Drawing (for w:drawing ), Drawing (对于w:drawing ),
    • Graphic (for a:graphic ), and Graphic (对于a:graphic ),和
    • Blip (for a:blip ); Blip (对于a:blip ); and
  4. use the desired class name, eg, as follows:使用所需的类名,例如,如下:

    var blip = cells[1].Descendants<Blip>().FirstOrDefault();

The above example assumes you want the Blip to identify the ImagePart that contains the image data.上面的示例假设您希望Blip识别包含图像数据的ImagePart

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

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