mlreportgen add content of word file

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 ?

Answers (1)

Akanksha
Akanksha on 17 Jun 2025
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!

Categories

Asked:

on 15 Oct 2022

Answered:

on 17 Jun 2025

Community Treasure Hunt

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

Start Hunting!