5

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

Vincent Hogendoorn
  • 700
  • 1
  • 7
  • 23
  • if you are looking for .netCore workaround you can visit https://stackoverflow.com/questions/29230853/add-image-to-word-docx-file-with-npoi/50133453 – Marcin J May 03 '18 at 06:53

1 Answers1

1

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

Vincent Hogendoorn
  • 700
  • 1
  • 7
  • 23
  • Please provide a link to that question. Also: someone ask if this has been fixed in version 2.3? (Re: https://stackoverflow.com/questions/48703936/cannot-add-image-to-docx-using-npoi-2-3) – Just a HK developer Apr 10 '18 at 02:31