Report Generator - Prevent Table from Breaking onto Multiple Pages
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
1 vote
Is there a way to automatically detect with the report generator when a table will not fit on page and insert a page break so that the table can start on the next page?
Accepted Answer
Sean de Wolski
on 17 Mar 2015
0 votes
Since this only applies to docx reports, this can be done by defining a table style and then applying it when necessary.
Attached in the *.zip file is a word document with this custom table style.
6 Comments
Madeline Oglesby
on 17 Mar 2015
Is there documentation where I can read how to define a table style and apply and use it?
Thanks.
Juande Manjon
on 17 Mar 2015
This code example reproduces the table style formats in the attached Word document.
import mlreportgen.dom.*
document = Document('MyDoc','docx');
for i = 1:11
append(document, Text(i));
end
table = Table(magic(16));
table.RowSep = 'solid';
table.ColSep = 'solid';
table.Border = 'double';
table.TableEntriesStyle = { KeepWithNext, KeepLinesTogether };
append(document, table);
close(document);
rptview(document.OutputPath);
Madeline Oglesby
on 18 Mar 2015
I'm finding that even after including this line, the tables still split from one page to the next:
table.TableEntriesStyle = { KeepWithNext, KeepLinesTogether };
The top rows of my tables are getting split from the rest of the tables.
Sean de Wolski
on 19 Mar 2015
Madeline, do you have a minimal working example?
Madeline Oglesby
on 19 Mar 2015
I suspect that it may have something to do with the fact that the top left cell in my tables are 'empty'. I've recreated something similar below:
import mlreportgen.dom.*;
d = Document('Test','docx');
table_sample = {[],'Sample Table';
'1','10%';
'2','20%';
'3','15%';
'4','15%';
'5','30%';
'6','5%';
'7','5%'};
for lx = 1:10
text_sample = Text('Sample Title');
append(d,text_sample);
tableObj = Table(table_sample);
tableObj.RowSep = 'solid';
tableObj.ColSep = 'solid';
tableObj.Border = 'double';
tableObj.TableEntriesStyle = { KeepWithNext, KeepLinesTogether };
append(d,tableObj);
end
close(d);
rptview(d.OutputPath);
Sean de Wolski
on 20 Mar 2015
The reason it's splitting isn't so much because it's empty as it is because [] creates an empty double array and the input should be a string.
Use '' instead.
table_sample = {'','Sample Table';
'1','10%';
'2','20%';
'3','15%';
'4','15%';
'5','30%';
'6','5%';
'7','5%'};
More Answers (0)
Categories
Find more on Tables in Help Center and File Exchange
See Also
on 17 Mar 2015
on 20 Mar 2015
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)