How do I add a high resolution figure to a Word template using Report Generator?
Ältere Kommentare anzeigen
I am using Report Generator to populate a Word template with text/numerical data and plots from laboratory testing. The template has Word-formatted tables with fillable holes followed by holes between tables to fill with figures. I'm currently using the approach below to sequentially fill holes. The entry below shows a text entry followed by a figure.
import mlreportgen.dom.*
D = Document('FromTemplate','docx', 'UCS_Word_Template.dotx');
open(D)
moveToNextHole(D);
append(D, app.ProjectEditField.Value);
moveToNextHole(D);
myfig=figure();
%plot code in this section working as intended. Not included here to
%simplify description.
fontsize(myfig,0.25,"centimeters")
myfig.PaperPositionMode = 'manual';
myfig.PaperUnits = 'inches';
myfig.PaperPosition = [0 0 4.75 3];
saveas(myfig,'myfig','png');
imgPath = which("myfig.png");
img1 = Image(imgPath);
append(D,img1);
This code is working as intended, but saveas uses a set resolution that is not adjustable (to my knowledge). The resulting figure has fine detail that is blurry in the printed report.
I have also tried using the exportgraphics function and setting the size as shown below:
import mlreportgen.dom.*
D = Document('FromTemplate','docx', 'UCS_Word_Template.dotx');
open(D)
moveToNextHole(D);
append(D, app.ProjectEditField.Value);
moveToNextHole(D);
t = tiledlayout(1,1, 'Padding','tight');
t.Units = 'inches';
t.OuterPosition = [0.25 0.25 4.75 3];
nexttile;
%plot code in this section working as intended. Not included here to
%simplify description.
exportgraphics(t, 'myfig.png','Resolution', 600);
imgPath = which("myfig.png");
img1 = Image(imgPath);
append(D,img1);
This code also works, but the figure filled into the word template is approximately 18x22 inches.
Is there a way to append an image into the template with both a set size and set resolution?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu MATLAB Report Generator Task Examples finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!