mlreportgen add content of word file

조회 수: 9 (최근 30일)
vivek patel
vivek patel 2022년 10월 15일
답변: Akanksha 2025년 6월 17일
In the mlreportgen, how can i add the content of the word file ?
I have tried mlreportgen.dom.DOCXSubDoc, but it would be still a link and need to manually remove the link, or through the matlab command. But i don't want to create many temporary files.
The same problem comes with mlreportgen.dom.EmbeddedObject.
Is there any way to add a full word document or a range of document, as an Paragraph to the mlreportgen ?

답변 (1개)

Akanksha
Akanksha 2025년 6월 17일
Hey vivek patel,
You're absolutely right. Currently, MATLAB Report Generator's DOM API doesn't let you directly insert the full content of a Word document (like paragraphs, tables, etc.) into another Word report.
Since MATLAB doesn’t support this directly, there’s a workaround you can use by processing the Word file outside MATLAB and then recreating its content inside your report. Here's how you can do it:
Step 1: Extract the Word Content
Use an external tool to extract the content of the Word file using
python-docx, pandoc, Word automation via COM, etc.
This will give you the content in a readable format like plain text, HTML, or structured data.
Step 2: Parse the Content
  • If it’s plain text, you can split it into paragraphs or lines.
  • If its HTML, you can use an HTML parser (in MATLAB or Python) to identify headings, tables, etc.
Step 3: Rebuild the Content in MATLAB
Now, use MATLAB’s DOM API to recreate the content in your report like
  • Use mlreportgen.dom.Paragraph to add paragraphs,
  • Use mlreportgen.dom.Table to recreate tables,
  • Use mlreportgen.dom.Text for formatting like bold or italic, etc.
PFA the links to the MathWorks documentation that explain how to use these DOM elements:
Hope this helps!

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by