how to add one report to another report with MATLAB report generator
15 views (last 30 days)
Show older comments
I have made a document with mlreportgen like this:
import mlreportgen.report.*
import mlreportgen.dom.*
Rprt = Document(FileName, Type, Template);
.
.
.
close(Rprt);
now I want to make another report that contains the previous report:
new_Rprt = Document(new_FileName, Type, Template);
how can I add Rprt to new_Rprt?
I have tried append(new_Rprt,Rprt) and add(new_Rprt,Rprt) but it didn't work.
thanks for any help.
0 Comments
Answers (1)
Mary Abbott
on 23 Aug 2022
Adding a Document or Report object to another Document or Report object is not supported. However, depending on the type of document you created, there are a few different options that might help.
If you still have the data and code used to generate the original document, the simplest method is to use the original code to generate the same content in the new document.
If both the original and new documents are DOCX documents, you can use the mlreportgen.dom.DOCXSubDoc class to insert the original report as a subdocument:
If the original document is an HTML document, you can use the mlreportgen.dom.HTML class to insert the content of the original document into the new document:
The following steps show how to do this:
(Only necessary if the original document is a multifile HTML document. Skip if you used html-file as the report type) Unzip the HTML package:
originalFilename = "myFile.htmx";
unzippedFolder = "myFile";
unzipTemplate(originalFilename, unzippedFolder);
Get the HTML string to pass to the HTML object:
preppedHTML = mlreportgen.utils.html2dom.prepHTMLFile(fullfile(unzippedFolder,"root.html"));
If the original document contains any images, you'll need to copy the images folder from the unzipped original report to the working directory. Then, add the HTML to the new document:
import mlreportgen.dom.*
Rprt = Document("newDocument", "html"); % You can use any type of report for the new document.
originalHTMLObj = HTML(preppedHTML);
append(Rprt, originalHTMLObj);
% ... add other content...
close(Rprt);
rptview(Rprt);
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!