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

4 次查看(过去 30 天)
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.

采纳的回答

Paul Kinnucan
Paul Kinnucan 2016-10-6
编辑:Paul Kinnucan 2016-10-6
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Create Report Programs Using the Report API 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by