Borrar filtros
Borrar filtros

In Report Generator DOM how can I make row heights size exactly to the text in the table?

8 visualizaciones (últimos 30 días)
When I create a simple table such as the below very simple code, I find that I get a very sprawling table with lots of padding around the text.
I've spent lots of time experimenting with styles, formats, and properties including Row Height and Table Padding and for some reason I can never reduce the row height below a certain size which includes lots of white space above and below the data or text in the cell. I would have thought this is the most basic requirement of table formatting but for some reason it's incredibly difficult to find out how to do this in the DOM.
I want to create large tables displaying text and numerical data with 10s or even 100s of rows, so need to make each row tiny.
Can anyone advise? Thanks!
import mlreportgen.dom.*;
d = Document('.\Reports\test', 'html');
%d.OutputPath='.\Reports\test.html';
open(d);
t = Table(testArray);
t.Style = {RowHeight('0.1in')};
t.Border = 'solid';
t.BorderWidth = '1px';
t.ColSep = 'solid';
t.ColSepWidth = '1';
t.RowSep = 'solid';
t.RowSepWidth = '1';
% Set this property first to avoid being overwritten.
t.TableEntriesStyle = {FontFamily('Arial'), Width('1in'), Height('0.01in'),Color('red'), Bold};
t.TableEntriesInnerMargin='0.01in';
t.TableEntriesHAlign = 'center';
t.TableEntriesVAlign = 'middle';
append(d, t);
close(d);
rptview('.\Reports\test', 'html');

Respuestas (1)

Sean de Wolski
Sean de Wolski el 23 de Feb. de 2016
Editada: Sean de Wolski el 24 de Feb. de 2016
Try using the RowHeight class to specify the height of each individual row that you then append to the Table.
More
import mlreportgen.dom.*;
d = Document('.\test', 'html');
%d.OutputPath='.\Reports\test.html';
open(d);
t = Table(rand(10,3));
t.Style = {RowHeight('0.1in')};
t.Border = 'solid';
t.BorderWidth = '1px';
t.ColSep = 'solid';
t.ColSepWidth = '1';
t.RowSep = 'solid';
t.RowSepWidth = '1';
% Set this property first to avoid being overwritten.
t.TableEntriesStyle = {FontFamily('Arial'), Width('1in'), Height('0.01in'),Color('red'), Bold, InnerMargin('0') OuterMargin('0') ...
HAlign('center') VAlign('middle')};
t.TableEntriesInnerMargin='0.01in';
t.TableEntriesHAlign = 'center';
t.TableEntriesVAlign = 'middle';
append(d, t);
close(d);
rptview('.\test', 'html');
  3 comentarios
Paul Kinnucan
Paul Kinnucan el 12 de Mayo de 2016
The root of the problem is that constructing a table entry from a string causes the DOM API to wrap the string in a paragraph over whose format you have no control. HTML surrounds a paragraph with lots of white space by default. To control the amount of white space, construct your table entries from paragraphs whose outer margins you specify. The following example shows how.
import mlreportgen.dom.*
rpt = Document('test');
table = Table(2);
table.Style={ResizeToFitContents};
table.TableEntriesInnerMargin='1mm';
table.Border = 'solid';
table.BorderWidth = '1px';
table.RowSep = 'solid';
table.RowSepWidth = '1px';
table.ColSep = 'solid';
table.ColSepWidth = '1px';
row = TableRow();
EntryParaStyle = {OuterMargin('0', '0', '0', '0')};
p = Paragraph('Col 1');
p.Style = EntryParaStyle;
append(row,TableEntry(p));
p = Paragraph('Col 2');
p.Style = EntryParaStyle;
append(row,TableEntry(p));
append(table, row);
row = TableRow();
p = Paragraph('data11');
p.Style = EntryParaStyle;
append(row,TableEntry(p));
p = Paragraph('data12');
p.Style = EntryParaStyle;
append(row,TableEntry(p));
append(table, row);
append(rpt,table);
close(rpt);
rptview(rpt.OutputPath);

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Report Generator Task Examples en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by