antonmihaylov / OpenXmlTemplates

Word .docx templating system that is designer (no scripting tags) and server-friendly (no word installation required)
GNU Lesser General Public License v3.0
89 stars 25 forks source link

#14: Images #16

Closed dgwaldo closed 3 years ago

dgwaldo commented 3 years ago

I tried to fit this within the framework of how the rest of your component replacers work. It has a bit of an inefficiency in that it converts from a stream to base64 then out of base64 back to a string.

I haven't tested it on anything nested. I'm assuming based on how the rest of your stuff work it'll just work. Added one test that runs the code. I didn't take the time to figure out how to correctly assert that the PictureContentControl had been filled. Check out the test, and take a look at the result. Perhaps you will see a better way it could be done?

Also, apologize for moving the curlys, my VS settings get me when working on open source.

antonmihaylov commented 3 years ago

That looks pretty good. The inefficiency is there, but I guess that's the result of not accounting for images in the core way of doing replacements. But it shouldn't really be an issue unless you're doing a lot of image replacement.

The important part is that it works. I went ahead and tested for nested images. Didn't spend much time figuring out how to verify that the image is actually replaced, but at least visually - it works.

Thank you very much for contributing!