Clear Filters
Clear Filters

Add Superscript to word table header using matlab report generator

11 views (last 30 days)
I'm trying to add a Superscript to word table header using matlab report generator but I'm not getting it. I created this simple example to ilustrate the situation.
In this example, I just create a table in matlab and then I use MATLABTable() to be able to insert it in word. Then I modify the header of the third column using tablex.Header.Children.Entries(1,3).Children.Content()
import mlreportgen.report.*
import mlreportgen.dom.*
import mlreportgen.utils.*
makeDOMCompilable
rpt = Report('mydoc','docx');
Width = [38;43;38;40;49];
Height = [71;69;64;67;64];
Area = Width.*Height;
T = table(Width,Height,Area);
tablex = MATLABTable(T,'List Table 2');
tablex.Header.Children.Entries(1,3).Children.Content = 'ModHeader'; %HTML('<p>Area(m<sup>2</sup>)</p>');
add(rpt,tablex)
close(rpt);
rptview('mydoc','docx');
In a paragraph I can add Superscripts if I do something like this:
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('mydoc_html','docx');
Para = HTML('<p>Area(m<sup>2</sup>)</p>');% ...
append(rpt,Para);
close(rpt);
rptview('mydoc_html','docx');
But when I try to add a superscript in the Header as showed in the first code of this question replacing this line I get the error:
tablex.Header.Children.Entries(1,3).Children.Content = HTML('<p>Area(m<sup>2</sup>)</p>');
Invalid property value: .
Error in Superscript2 (line 14)
tablex.Header.Children.Entries(1,3).Children.Content = HTML('<p>Area(m<sup>2</sup>)</p>');
Thanks in advance for the help.

Answers (1)

Jaswanth
Jaswanth about 13 hours ago
Hi Juan,
To add a superscript to a Word table header using 'MATLAB Report Generator', you can utilize the 'HTML object' to include HTML tags directly in the header content. This approach allows you to format the header with superscripts or other HTML elements effectively.
Please refer to the following revised code that demonstrates how to achieve this:
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('mydoc','docx');
Width = [38;43;38;40;49];
Height = [71;69;64;67;64];
Area = Width.*Height;
T = uitable("Data", [Width,Height,Area]);
columnHeaders = {'Width', 'Height', '<html>Area<sup>2</sup></html>'};
T.ColumnName = columnHeaders;
Please note that this example is a workaround and demonstrates using a ‘uitable’ instead of ‘MATLABTable’.
Kindly refer to the following MATLAB Answer to know more about the 'HTML object' utilization: https://www.mathworks.com/matlabcentral/answers/753024-add-subscript-text-to-header-of-table-in-pdf-by-matlab-report-generator#answer_636406
I hope the information provided above is helpful in resolving the issue.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!