简体   繁体   中英

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#. 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 );
  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;
  3. map those to the strongly typed classes of the Open XML SDK, eg:
    • TableCell (for w:tc ),
    • Paragraph (for w:p ),
    • Drawing (for w:drawing ),
    • Graphic (for a:graphic ), and
    • Blip (for 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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