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