Adding sections by Report Generator doesn't work well after compiling

4 次查看(过去 30 天)
Hi, I'm using Report Generator in app designer to add sections to my .doc report. The code is something like :
makeDOMCompilable();
import mlreportgen.dom.*
import mlreportgen.report.*
function genrpt(app,docname)
...
app.rpt = Report(docname,'docx');
end
function gensec(app,secname,img)
...
app.sec = Section(secname);
add(app.sec,img)
end
function addsec(app,secname,addedname)
...
add(addedname,secname)
end
By calling these functions, I can generate a report like:
1.Section1
1.1 Subsection1
1.2 Subsection2
2.Section2
...
Which works fine inside app designer.
However, after it is compiled to standalone application (.exe), the numbering works incorrectly. And the generated report turns into:
1.Section1
1.1 Subsection1
1.1 Subsection2
1.Section2
...
Which confused me a lot. Can anyone help? Thx!

回答(3 个)

Inso
Inso 2019-12-27
编辑:Inso 2020-1-15
I just wrote a simple example to illustrate the problem:
f=waitbar(0,'waiting') ;
makeDOMCompilable();
import mlreportgen.dom.*
import mlreportgen.report.*
waitbar(0.2,f,'waiting')
rpt = Report('test','docx');
sec1 = Section('Section1');
waitbar(0.4,f,'waiting')
subsec1= Section('subSection1');
add(subsec1,'Weather is good') ;
add(sec1,subsec1) ;
waitbar(0.6,f,'waiting')
subsec2= Section('subSection2');
add(subsec2,'Let''s go hiking') ;
add(sec1,subsec2) ;
waitbar(0.8,f,'waiting')
add(rpt,sec1) ;
close(rpt)
waitbar(1,f,'waiting')
rptview(rpt);
close(f)
you can copy and run it. After compling the .mlapp or .m file, the numbering won't work.
  1 个评论
Inso
Inso 2020-1-9
编辑:Inso 2020-1-9
Just tried the scripts in 2019b. Still got the same issue (not numbering after compiling). What happened?

请先登录,再进行评论。


Inso
Inso 2020-1-10
编辑:Inso 2020-1-10
Also tried the example 'Number Section Headings, Table Titles, and Figure Captions Programmatically' in matlab documentation, which uses DOM API and 'getChapterTitle' function. It returns 'can't find the function 'getChapterTitle' for string type input'.

Vijay A
Vijay A 2020-1-25
编辑:Vijay A 2020-1-25
You need to create your own template as per your need I guess. Please refer to the manual on how to preapre your own template.
have a try with pdf format . I am not sure but have a try because MATLAB can generate reprots perfectly for N-Number of pages in PDF format and word doc has some limitations.
makeDOMCompilable();
import mlreportgen.dom.*
import mlreportgen.report.*
function genrpt(app,docname)
...
app.rpt = Report(docname,'pdf');
end
function gensec(app,secname,img)
...
app.sec = Section(secname);
add(app.sec,img)
end
function addsec(app,secname,addedname)
...
add(addedname,secname)
end
  1 个评论
Inso
Inso 2020-1-29
Yeah, pdf version works fine. But I need editable report :(
Also I'm afraid template is not a solution, since it is the user that decide the number/order of the sections.
Thanks for your help!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Reporting and Database Access 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by