Matlab Report Generator to be used on Standalone application

조회 수: 10 (최근 30일)
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?

채택된 답변

Sean de Wolski
Sean de Wolski 2017년 10월 16일
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);
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
Vijay A
Vijay A 2020년 1월 8일
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 :
  1. I have mentioned the main file path of matlab code
  2. I have attached the template file of the report by clicking the plus function
  3. created the exe file
  4. 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
Sample Project Screen Shot.jpg
Sean de Wolski
Sean de Wolski 2020년 1월 8일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

chakradhar Reddy Vardhireddy
chakradhar Reddy Vardhireddy 2020년 6월 19일
makeDOMCompilable();
you need to add that at the starting of the script, followed by
import mlreportgen.dom.*
import mlreportgen.report.*
it works that way.

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator Task Examples에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by