- You didn't include the template in the Deployment Project.
- You're using a relative or fixed file path that is no longer present.
Matlab Report Generator to be used on Standalone application
12 views (last 30 days)
Show older comments
IKER ARRIEN
on 16 Oct 2017
Answered: chakradhar Reddy Vardhireddy
on 19 Jun 2020
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')
makeDOMCompilable()
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')
moveToNextHole(doc);
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?
0 Comments
Accepted Answer
Sean de Wolski
on 16 Oct 2017
My guess it that it's failing to find the template. Two possible reasons:
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);
end
For you use you would then call
D = Document(Report_name,'docx', templatePath('ReportTemplate'))
This ensures it will work on other computers etc.
5 Comments
Vijay A
on 8 Jan 2020
My Task
I am working on a project to intract with database and to fetch data from backend and to show of the result in front end in pdf format.
My project code
% Button pushed function: Button
import mlreportgen.dom.*
import mlreportgen.report.*
% To create a Word report, change the output type from "pdf" to "docx".
% To create an HTML report, change "pdf” to “html” or "html-file" for a
% multifile or single-file report, respectively.
% rpt = Document('Report_name','docx', templatePath('ReportTemplate'));
rpt = Report('myreport','pdf',templatePath('default'));
% rpt.OutputPath = 'D:\MATLAB\Projects\01'
tableStyle = { ...
Width('100%'), ...
Border('solid','black','1px'), ...
ColSep('solid','black','1px'), ...
RowSep('solid','black','1px') ...
};
datasource = 'xxxxxx';
conn = database(datasource,'yyyyy','zzzzzzz');
sqlquery = 'select * from test01';
rows = sqlread(conn,'test01');
table1 = Table(rows);
table1.TableEntriesHAlign = 'center';
table1.Style = tableStyle;
% table2 = Table(rows);
% table2.TableEntriesHAlign = 'center';
% table2.Style = tableStyle;
lo_table = Table({table1});
lo_table.entry(1,1).Style = {Width('3.2in')};
lo_table.entry(1,1).Style = {Width('.2in')};
lo_table.entry(1,1).Style = {Width('3.2in')};
lo_table.Style = {Width('100%'), ResizeToFitContents(false)};
add(rpt, lo_table);
close(rpt);
rptview(rpt.OutputPath);
My issues
My project was working like a charm in testing with guide as well as in app designer, but after creating an exe file it does not work but other functionalites other than reprot generator is working well. I tried your codes too but it is not working after creating the exe file. your suggested function works only before creating the app.
Function I tried
function template = templatePath(templatename)
% Generate path relative to m-file location
whoAmI = mfilename('fullpath');
[fullpath, ~, ~] = fileparts(whoAmI);
template = fullfile(fullpath,'Templates',templatename);
% If application is deployed, generate path relative to temp directory
if isdeployed
template = fullfile(ctfroot,'Templates',templatename);
end
end
after executing the function an error sound produced by the app window, with out any results. but other functions are working well and good. please help me in generationg a pdf report after generating a stand alone exe file.
Steps I have followed to create the exe file :
- I have mentioned the main file path of matlab code
- I have attached the template file of the report by clicking the plus function
- created the exe file
- additionally i tried pasted the template folder and even the file near to the setup file as well as in the same folder.
but sadly it does not help me executing the pdf file . :(
My project screen shot which works well before creating exe file
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.
More Answers (1)
chakradhar Reddy Vardhireddy
on 19 Jun 2020
makeDOMCompilable();
you need to add that at the starting of the script, followed by
import mlreportgen.dom.*
import mlreportgen.report.*
it works that way.
0 Comments
See Also
Categories
Find more on MATLAB Report Generator Task Examples in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!