Can we use DocumentPart in Report Generation?

I want to generate a Report with template. Can I use DocumentPart in report generation? Does DocumentPart support to report? if not please suggest some alternative solution. Thank you.
Here I am attaching small example
import mlreportgen.report.*
import mlreprtgen.dom.*
R = Report('Report', 'docx', 'Template');
append(R, DocumentPart(R, 'Content'))
close(R)
rptview(R)

 Respuesta aceptada

SRUSHTI KHATAU
SRUSHTI KHATAU el 11 de Nov. de 2021
This code works
import mlreportgen.report.*
import mlreportgen.dom.*
D = Template('NewTemplateName','docx','TemplateFromWhichWeAreAddingPart')
open(D)
dp = DocumentPart(D,'DocumenPartName');
append(D,dp)
close(D)
R = Report('Report','docx','NewTemplateName')
open(R)
append(R, TableOfContents)
close(R)
rptview(R)

Más respuestas (1)

Kevin Holly
Kevin Holly el 9 de Nov. de 2021

0 votos

It looks like it can from the example from the documentation.

4 comentarios

SRUSHTI KHATAU
SRUSHTI KHATAU el 9 de Nov. de 2021
Thank you for replying. But I was asking for mlreportgen.report class. If you run above code then I get error as
Error using mlreportgen.dom.DocumentPart
No constructor 'mlreportgen.dom.DocumentPart' with matching signature found.
import mlreportgen.report.*;
import mlreportgen.dom.*;
d = Report('Report', 'docx', 'Template');
append(d,DocumentPart(d,'Content'))
Error using mlreportgen.dom.DocumentPart
No constructor 'mlreportgen.dom.DocumentPart' with matching signature found.
close(d)
rptview(d)
Ah, reporter class... the example I linked appends it to a document class, but I believe you can append the document container to the reporter container. I think you need to append the DocumentPart to the Document container. Then I believe you could append that to the report. I haven't used this before, let me know if this works.
import mlreportgen.report.*
import mlreportgen.dom.*
R = Report('Report', 'docx', 'Template');
D = Document('test','docx');
append(D, DocumentPart(D.Type))
append(R,D)
close(R)
rptview(R)
SRUSHTI KHATAU
SRUSHTI KHATAU el 11 de Nov. de 2021
Thank you for replying. The above code was helpful.

Iniciar sesión para comentar.

Preguntada:

el 9 de Nov. de 2021

Comentada:

el 11 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by