facebooktwittermenuarrow-up

GemBox Support Forum

Add an image from a byte array into a cell

I have 20 tables in a DOCX file and I want to add images in a specific row using a byte[]

Screenshot_4

Hi Vitor,

Try using the following:

byte[] imageData = File.ReadAllBytes("image.png");

var document = DocumentModel.Load("input.docx");

// Get first table in the document.
var table = (Table)document.GetChildElements(true, ElementType.Table).First();

// Get desired cell in the table (second cell in the second row).
var cell = table.Rows[1].Cells[1];

// Create new paragraph with picture.
var paragraph = new Paragraph(document, new Picture(document, new MemoryStream(imageData)));

// Add paragraph to cell.
cell.Blocks.Add(paragraph);

document.Save("output.docx");

I hope this helps.

Regards,
Mario

1 Like

I love you mario, you save my work :grinning: :grinning: :grinning:

1 Like