Question

I was already using the NPOI Library for creating Excel Documents(which is the .NET version of POI Java project), but now I also want to create a Word (Docx document).

I want to add an image to the document, but somehow it won't work. It looks like it's adding the image, but when I open the downloaded doc

“The file <document filename> cannot be opened because there are problems with the contents”

this is the code for adding the image in the document:

XWPFParagraph p2 = wordDoc.CreateParagraph();
XWPFRun r2 = p2.CreateRun();
r2.AddPicture(pictureData, (int)PictureType.PNG, "image1", 800, 600);

where pictureData is a memoryStream of the pictureData. the memoryStrean is correct, because I can get the base64 String from it and this shows the correct output, but all I want is this image into a word document.

So my question is, what am I missing, what am I doing wrong? Couldn't find any documentation about images into a XWPF document.

thanks in advance

Was it helpful?

Solution

I asked this question also on codeplex.com, where you can download the library, and the coordinator for the NPOI library, tonyqus, answered with the folllowing:

This is a bug in NPOI 2.0.6. It will be fixed in NPOI 2.1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top