Matlab Report Generator to be used on Standalone application

30 views (last 30 days)
I have created a GUI where the final results are listed on a Word document that is created automatically by Matlab.
Therefore, I am using import mlreportgen.dom.*; code-line.
When I use it on Matlab (clicking Run button), it works ok and the Word document is created.
I have compiled the GUI by deploytool --> standalone application and I create the .exe file.
When I run the .exe it doesn't create the Word document. I have chased the error-source and I have seen that it fails at the code-line where it is written: moveToNextHole.
I have seen in other Q&A tags that I should write makeDOMCompilable() just before import mlreportgen.dom.*; in order to make DOM compilable.
However, it still doesn't work. (By the way, I am using Matlab 2016a)
Below I have attached part of my ReportGenerator code:
%function Report_StaticAnalysis
msgbox('Check 1: It enters generate_report')
import mlreportgen.dom.*;
reportnumber = datestr(now,'yyyy mm dd (HH MM SS)'); Report_name= strcat('Report_StaticAnalysis_',reportnumber);
%% Title
doc = Document(Report_name,'docx', 'ReportTemplate');
msgbox('Check 2: Report_name created')
msgbox('Check 3: moveToNextHole is done')
textObj = Text(evalin('base', 'title'));
% The code continues but it is too long to attach all of it
As you can see, I have put some msgbox in order to see where it stops running. Check 1 and 2 work ok, but Check 3 is not created when running the .exe. Therefore moveToNextHole(doc) is failing.
Why is it failing? I am using the makeDOMCompilable() code-line. Any ideas?

Accepted Answer

Sean de Wolski
Sean de Wolski on 16 Oct 2017
My guess it that it's failing to find the template. Two possible reasons:
  1. You didn't include the template in the Deployment Project.
  2. You're using a relative or fixed file path that is no longer present.
The first one is easy, in the Compiler App, hit the + button and add the templates.
The second one is a little trickier because you'll need to deal with flexible file paths. I've taken to including a helper function in my Report Gen projects that builds this path for me. You'll need to modify it to suit but in my case I keep all of my templates in a folder called 'Templates' that sits in the same directory as this function.
function template = templatePath(templatename)
% Where's my template?
whoAmI = mfilename('fullpath');
[fullpath, ~, ~] = fileparts(whoAmI);
template = fullfile(fullpath,'Templates',templatename);
For you use you would then call
D = Document(Report_name,'docx', templatePath('ReportTemplate'))
This ensures it will work on other computers etc.
Sean de Wolski
Sean de Wolski on 8 Jan 2020
Vijay, do you call makeDOMCompilable in the code anywhere? This is required to be called before DOM components are used in a compiled project.
If this is the issue, PLEASE contact tech support and complain so that development can hear from end users what a challenge discovering this is.

Sign in to comment.

More Answers (1)

chakradhar Reddy Vardhireddy
you need to add that at the starting of the script, followed by
import mlreportgen.dom.*
it works that way.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!