mlreportgen add content of word file

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