User`s guide
Create and Format Tables
13-63
Formatting Table Object Property
Align entries horizontally (left, right,
center)
TableEntriesValign
Create space (padding) between entry
boundary and content
TableEntriesInnerMargin
Apply a set of format objects to all table
entries
TableEntriesStyle
Keep a Table and Its Title on the Same Page
Use the KeepLinesTogether and KeepWithNext paragraph formats to keep a table
title and the table together on the same page. This example creates a table title, creates
table content, and makes the table header row bold, using table entry indexing. To keep
the table on the same page, the code specifies KeepLinesTogether and KeepWithNext
for all rows except the last row. The last row has only KeepLinesTogether set and not
KeepWithNext. This prevents the table from being forced to stay with the paragraph
that follows.
import mlreportgen.dom.*
rpt = Document('test','docx');
p = Paragraph('Table 1');
p.Style = {Bold,KeepLinesTogether,KeepWithNext};
append(rpt, p);
ca = {Paragraph('Col 1'),Paragraph('Col 2'); ...
Paragraph('data 11'),Paragraph('Data 12'); ...
Paragraph('data 21'),Paragraph('Data 22')};
ca{1,1}.Children(1).Bold = true;
ca{1,2}.Children(1).Bold = true;
for r = 1:2
for c = 1:2
ca{r, c}.Style = {KeepLinesTogether,KeepWithNext};
end
end
for c = 1:2
ca{3, c}.Style = {KeepLinesTogether};
end