"Error building part DOM Part" by for HTML report

3 vues (au cours des 30 derniers jours)
Kristina Kossarev
Kristina Kossarev le 2 Déc 2021
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:

Réponses (1)

Rahul Singhal
Rahul Singhal le 8 Déc 2021
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

Catégories

En savoir plus sur MATLAB Report Generator dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by