0

Based on this question: Table fields in format in PDF report generator - Matlab, I converted the p table to be a DOM MATLAB Table. How can I color the header row, remove the underlining of its entries and apply the tableStyle on the rest of it.

With my code, I get all the table with the LightBlue color and the tableStyle is not applied.

Code:

function ButtonPushed(app, event)
import mlreportgen.dom.*;
import mlreportgen.report.*

ID = [1;2;3;4;5];
Name = {'San';'John';'Lee';'Boo';'Jay'};
Index1 = [1;2;3;4;5];
Index2 = [176.23423;163.123423654;131.45364572;133.5789435;119.63575647];
Index3 = [176.234;16.123423654;31.45364572;33.5789435;11.6647];
p = table(ID,Name,f(Index1),f(Index2),f(Index3));
V = @(x) inputname(1);
p.Properties.VariableNames(3:end) = {V(Index1), V(Index2), V(Index3)};

headerStyle = { BackgroundColor("LightBlue"), ...
    Bold(true) };

tableStyle = { Width("60%"), ...
    Border("single"), ...
    RowSep("solid"), ...
    ColSep("solid") };

p  = MATLABTable(p)

p.Style = headerStyle;
p.TableEntriesHAlign = 'center';

d = Document('myPDF','pdf');
d.OutputPath = ['E:/','temp'];
append(d,'Report for file: ');
append(d,p);
close(d);
rptview(d.OutputPath);
end

function FivDigsStr = f(x)
%formatting to character array with 5 significant digits and then splitting at each tab
FivDigsStr = categorical(split(sprintf('%0.5G\t',x)));
%Removing the last (empty) value (which is included due to \t)
FivDigsStr = FivDigsStr(1:end-1);
end

Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
alirazi
  • 159
  • 8
  • added the problem description. – alirazi May 08 '20 at 13:25
  • btw you have [a DOM MATLAB Table](https://www.mathworks.com/help/rptgen/ug/mlreportgen.dom.matlabtable-class.html), not a [Formal Table](https://www.mathworks.com/help/rptgen/ug/mlreportgen.dom.formaltable-class.html). I have edited your question to fix this – Sardar Usama May 08 '20 at 16:39

1 Answers1

1

You defined the variable tableStyle in which you defined the desired properties but you didn't set them. Also instead of setting the header as bold and light blue background, you are setting all the entries to have that.

The following code fixes that:

set(p, 'Width', '60%', 'Border', 'single',...
    'RowSep', 'solid', 'ColSep', 'solid',...
    'TableEntriesHAlign', 'center');
p.HeaderRule = '';  %To remove the underlining of header entries
p.Header.Style = headerStyle; %Setting the Header Style 

Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
  • OK. Can you please upload all the function? I do not what you removed and where the new code is located – alirazi May 08 '20 at 16:35
  • 1
    Remove these two lines of your code `p.Style = headerStyle; p.TableEntriesHAlign = 'center';` and put my code there – Sardar Usama May 08 '20 at 16:36