"Error building part DOM Part" by for HTML report
1 次查看(过去 30 天)
显示 更早的评论
I want to generate a HTML report. So far the following code works (I downloaded the MATLAB Report Generator; MATLAB Version R2020b) :
import mlreportgen.dom.*
import mlreportgen.report.*
% generate html report
rpt = Report('Report_test','html-file');
rpt.Locale = 'en'; % report language is English
% Add title
tp = TitlePage;
tp.Title = ['Test'];
tp.Subtitle = '123';
tp.Author = ''; % if not empty, default values are automatically taken
tp.PubDate = ''; % if not empty, default values are automatically taken
add(rpt,tp);
% Add chapter
ch1 = Chapter();
ch1.Title = sprintf('Chapter');
% Add section
sec1 = Section;
sec1.Title = 'Section';
add(ch1,sec1);
add(rpt, ch1);
% view report
rptview(rpt)
Unfortunately, the the output is not well formatted (the text has no margin to the left):
I tried to change the HTML template by doing following steps:
mlreportgen.report.Report.createTemplate('MyTemplate','html');
unzipTemplate('MyTemplate')
% now I made changes in ...MyTemplate\stylesheets\root.css in e.g. the body
% or heading section (see screenshot below; not able to upload css file)
unzipTemplate('MyTemplate')
% generate html report
rpt = Report('Report_1','html-file','..\MyTemplate.htmtx');
%% here the same as before
rpt.Locale = 'en'; % report language is English
% Add title
tp = TitlePage;
tp.Title = ['Test'];
tp.Subtitle = '123';
tp.Author = ''; % if not empty, default values are automatically taken
tp.PubDate = ''; % if not empty, default values are automatically taken
add(rpt,tp);
% Add chapter
ch1 = Chapter();
ch1.Title = sprintf('Chapter');
% Add section
sec1 = Section;
sec1.Title = 'Section';
add(ch1,sec1);
add(rpt, ch1);
% view report
rptview(rpt)
By using my own template, I get the follwing error:
Error building part DOM Part: ../MyTemplate.htmtx
Error: invalid byte '‚' at position 1 of a 1-byte sequence
Error in mlreportgen.report.internal.Document/open
Error in mlreportgen.report.ReportBase/openImpl
Error in mlreportgen.report.ReportBase/open
Error in mlreportgen.report.ReportBase/append
Error in mlreportgen.report.ReportBase/add
Error in generateTestReport (line 41)
add(rpt,tp);
Has anyone an idea how to fix this error? Or even a better solution how to fix my issue of changing the format of the generated HTML report?
%%
Screenshot from css file:
0 个评论
回答(1 个)
Rahul Singhal
2021-12-8
Hi Kristina,
I see that you are creating a single-file HTML report (report type is html-file), but creating a custom template for zipped HTML reports (type is html). I suggest creating the custom template as follows:
mlreportgen.report.Report.createTemplate('MyTemplate','html-file');
Thanks,
Rahul
0 个评论
另请参阅
类别
在 Help Center 和 File 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!