Report Generator: How to change horizontal text alignment for individual columns of the same table?

16 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Rahul Singhal
Rahul Singhal el 27 de Jul. de 2017
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);

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by