How can I change the background color of a cell in report generator?

16 次查看(过去 30 天)
I am very new in the report generator toolbox, but hopefully someone can help me here
I am generating a table via report generator, but if i have this table:
T = [1 2 6; 3 4 10; 2 5 10]
is it possible to color the cell so values <10 turns green, >10 & <20 turns yellow, and >20 turns red in the output report?
Thanks a lot in advance

回答(1 个)

Mary Abbott
Mary Abbott 2019-3-13
You can change how a particular number is formatted in a table by setting properties of a Text object that contains the number. For example, the following code creates a Text object for an entry in T and sets the BackgroundColor property to green. It creates a table using the Text object and the remaining numbers in T:
% Make T a cell array so that we can replace a number with a Text object
T = {1 2 6; 3 4 10; 2 5 10};
% Replace the number 6 with a Text object
textObj = mlreportgen.dom.Text(T{1,3});
textObj.BackgroundColor = "green";
T{1,3} = textObj;
% Create a Table from the Text objects and add to a report
tbl = mlreportgen.dom.Table(T);
More information about the mlreportgen.dom.Text class along with other formatting options can be found at the following link:

类别

Help CenterFile Exchange 中查找有关 MATLAB Report Generator 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by