How do I set text to left or right side in tables generated in report generator?

조회 수: 8 (최근 30일)
When I create a report I need to set text to left side to get a nice look. How do I do that?
Some part of my code:
T = cell2table(data);
T.Properties.VariableNames{1} = 'Status';
T.Properties.VariableNames{2} = 'Hours';
T.Properties.VariableNames{3} = 'Percent';
table = BaseTable(T)
add(R, table);
Table_setting.JPG
  댓글 수: 2
Rahul Singhal
Rahul Singhal 2019년 8월 16일
Do you want data of all the columns to align to the left or just one column?
Also, what is the output type of your report?
Per Wallentin
Per Wallentin 2019년 8월 19일
When it comes to text I need to left align then and when I have digits/values I would like to right align them.
The output is in PDF format.
Thank you for helping me.

댓글을 달려면 로그인하십시오.

채택된 답변

Rahul Singhal
Rahul Singhal 2019년 8월 19일
Hi Per,
As you want content of some columns to be aligned to the left and content of some columns to be aligned to the right, you can construct a DOM MATLABTable and use its ColSpecGroups property to specify the column formatting.
Below is a sample script:
import mlreportgen.dom.*
import mlreportgen.report.*
% Create sample data
data = {'Initializing', '0.0', '0.2'; 'Cleared', '12.2', '71.1'};
T = cell2table(data);
T.Properties.VariableNames{1} = 'Status';
T.Properties.VariableNames{2} = 'Hours';
T.Properties.VariableNames{3} = 'Percent';
% Create a PDF report
R = Report('myrpt', 'pdf');
open(R);
% Create a DOM MATLABTable
domTable = MATLABTable(T);
domTable.Width = '100%';
% Specify the col specs to left-align the content of the first column and
% right-align the content of the second and third columns
grps(1) = TableColSpecGroup;
specs(1) = TableColSpec;
specs(1).Style = {HAlign('left')};
specs(2) = TableColSpec;
specs(2).Style = {HAlign('right')};
specs(3) = TableColSpec;
specs(3).Style = {HAlign('right')};
grps(1).ColSpecs = specs;
domTable.ColSpecGroups = grps;
% Create a BaseTable reporter from the DOM MATLABTable and add it to the report
baseTable = BaseTable(domTable);
add(R, baseTable);
% Close and view the report
close(R)
rptview(R);
Thanks,
Rahul
  댓글 수: 1
Per Wallentin
Per Wallentin 2019년 8월 20일
Hi Rahul,
that worked very well. Now report content is much easier to read.
Thank you very much!
Kind regards
Per

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by