Search code examples
openxml-sdk

How to insert image using openxml?


How to insert image into a word document where a word document consist of a table,that image should be inserted in one of the table cell how to do that?please help me out


Solution

  • Check How to: Insert a picture into a word processing document (Open XML SDK) article at MSDN . It will help you on inserting images to word docuemnt.

    Also Working with WordprocessingML tables (Open XML SDK) and How to: Insert a Table into a Word Processing Document will help you on working with Tables in OpenXml.

    Update :

    I assume you get your desired cell in the document by th code mentioned in http://msdn.microsoft.com/en-us/library/cc850841(v=office.14).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-6 (so you have your TableCell in tc2 variable) , And also I assume you have added your desired image to document by the code mentioned in http://msdn.microsoft.com/en-us/library/office/bb497430(v=office.15).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-5 (so you have image refrence in element varialbe)

    so simply run this code to add the image to your tc2 table cell :

    tc2.AppendChild(new Paragraph(new Run(element)));