Report Generator: How to change horizontal text alignment for individual columns of the same table?
6 次查看(过去 30 天)
显示 更早的评论
I would like to have columns with different text alignment within the same FormalTable object. I am using the programmatic approach with the DOM API to create a report and have so far changed Style properties of individual FormalTable columns using TableColSpecGroup objects. There is however no alignment property in TableColSpec objects and I wonder whether it is possible to change this for individual columns. Any ideas on how to solve this?
0 个评论
采纳的回答
Rahul Singhal
2017-7-27
The Style property of TableCopSpec can be used to apply any format to one or more adjacent table columns. The below script will make the text to be left aligned in the first column, centered in the second column, and right aligned in the third column.
import mlreportgen.dom.*
rpt = Document('MyReport','pdf');
table = FormalTable(magic(3));
table.Width = '3in';
table.Border = 'solid';
table.ColSep = 'solid';
table.RowSep = 'solid';
groups(1) = TableColSpecGroup();
specs(1) = TableColSpec();
specs(1).Style = { HAlign('left') };
specs(2) = TableColSpec();
specs(2).Style = { HAlign('center') };
specs(3) = TableColSpec();
specs(3).Style = { HAlign('right') };
groups(1).ColSpecs = specs;
table.ColSpecGroups = groups;
append(rpt, table);
close(rpt);
rptview(rpt.OutputPath);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!