How to insert an image to table entry in this situation in Report Generator ?

10 views (last 30 days)
I saw code like this could change the text content of an entry after building the table:
table.entry(1,1).Children(1).Content = 'Header A';
i tried to use some similar codes like below to insert an image into a certain entry ,
table.entry(1,1).Children(1).Content = Image('number.jpg')
or
table1.entry(1,1).append(Image('number.jpg'));
but they all failed, could anyone please give me some tips?
Thanks in advance

Accepted Answer

Rahul Singhal
Rahul Singhal on 3 Jul 2018
Hi Tong,
For the case where you are updating the Content property to change the text in a table entry, that particular child of the table entry must be a a mlreportgen.dom.Text object. So you are actually accessing the DOM Text object and updating its Content property. As you can see from the documentation of the Content property, it just accepts text specified as character vector, so it works fine when you assign a 'A Header' to it but fails when you assign an Image object to it.
On the other hand, you should be able to use the append method of the table entry to add an Image object. For e.g., the below code will append an image to the first table entry.
t = mlreportgen.dom.Table(magic(2));
i = mlreportgen.dom.Image(which('b747.jpg'));
t.entry(1,1).append(i);
If this doesn't help, can you share the exact code how you are creating the table before appending an image to it's table entry, and also what is the error message you are encountering, so that I will be able to suggest specific to your use case.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!