How do you insert a PNG image with Matlab Report Generator when using a Word Document Template?
Show older comments
I'm unable to add images (png... etc) or figures (or even snapshots of figures) into my report made using MATLAB Report Generator and a Microsoft Word Template with 2 'holes' in it. Everything else works fine. Text is able to go into this template without trouble (hole 1) but the image labeled "myfig.png" or img1 won't append or add into the 2nd hole.
import mlreportgen.dom.* %import matlab report generator dom package
import mlreportgen.report.* %import matlab report generator report package
D = Document('FromTemplate','docx','RW_Template_Practice.dotx'); %Name the document D and use a template made in Microsoft Word with 2 "holes"
open(D); %open document D
moveToNextHole(D); %goes to the first hole
append(D,"SN001"); %Text in First hole -- shows up fine in FromTemplate.docx
moveToNextHole(D); %goes to the second hole, made just like the first, but with a different name/tag from first hole
myfig = B_Plot_PWM_CvS_Single_P(345) %runs custom function that returns a 1x1 Figure
saveas(myfig,'myfig','png') %saves my figure as a png image
imgPath = which("myfig.png") %gives full path of image file
img1 = Image(imgPath) %make it into an image object
append(D,img1) %THIS IS WHERE THINGS GO WRONG?? I want to put an image object into the 'hole' but nothing shows up in FromTemplate.docx
close(D); %Document closes normally
rptview(D); %Document opens in Microsoft Word and "myfig.png" or img1 is nowhere to be seen
2 Comments
Rahul Singhal
on 3 Aug 2021
Hi Tanya,
Can you share the 'RW_Template_Practice.dotx' template file, which can help us investigate the issue you are facing?
-Rahul
Tanya Mittal
on 3 Aug 2021
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Report Generator Task Examples in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!