Has anyone had success in creating a Report generator class to properly fill holes in a Word document?

9 vues (au cours des 30 derniers jours)
I have been working with the Report generator dom.api function moveToNextHole(report) to fill in content controls in a Microsoft Word ".dotx" template with no issues. However, in trying to use a class to fill in the content control holes, anything I try to populate (whether text, pictures, or any other content) just ends up at the beginning of the output document, not where the content control holes are. I found this to be true even in just trying to use the Mathworks example given in the "mlreportgen.dom.Document.fill" documentation.

Réponse acceptée

Paul Kinnucan
Paul Kinnucan le 6 Oct 2016
Modifié(e) : Paul Kinnucan le 6 Oct 2016
To generate a report from a DOM-based document object:
  • Derive your report class from mlreportgen.dom.Document class, for example
% MyReport.m
class MyReport < mlreportgen.dom.Document
method
function rpt = MyReport(name)
rpt@mlreportgen.dom.Document(name, 'docx', 'MyTemplate');
end
end
end
  • Provide a public fill<HOLEID> method for each hole in your report template, where HOLEID is the name of the hole, for example,
class MyReport < mlreportgen.dom.Document
method
function rpt = MyReport(name)
rpt@mlreportgen.dom.Document(name, 'docx', 'MyTemplate');
end
% This method is called by mlreportgen.dom.Document's fill method.
% Do not call it yourself.
function fillReportDate(rpt)
append(rpt, date);
end
end
end
  • Create a report program (i.e., script or function) to run the report.
  • In the report program, create an instance of your report class and call its fill method (inherited from mlreportgen.dom.Document class), for example,
% runMyReport.m
rpt = MyReport('myreport');
fill(rpt);
rptview(rpt.OutputPath);

Plus de réponses (0)

Catégories

En savoir plus sur Reporting and Database Access 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