How can I switch between landscape and portrait page orientation when creating a Word report using MATLAB Report Generator R2019a?

5 views (last 30 days)
I like to create a Word report (docx) and for that I need to switch between landscape and portrait multiple times. What is the right way to achieve this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 May 2019
Each time you want to change the page layout in the document, you need to create a new DOCXPageLayout object, set the orientation, and append it to the document object. If you are switching between portrait and landscape pages multiple times in the document, one strategy is to create two page layout objects, one portrait and one landscape, and append clones of the objects to the document whenever you need to switch the orientation. For example:
import mlreportgen.dom.*
d = Document('exampleDoc', 'docx');
open(d);
% default page layout is portrait
portraitPLO = DOCXPageLayout;
portraitPageSize = portraitPLO.PageSize;
% define landscape layout
landscapePLO = DOCXPageLayout;
landscapePLO.PageSize.Orientation = "landscape";
landscapePLO.PageSize.Height = portraitPageSize.Width;
landscapePLO.PageSize.Width = portraitPageSize.Height;
table = append(d,magic(15));
table.Border = 'solid';
table.ColSep = 'solid';
table.RowSep = 'solid';
%switch to landscape
append(d, clone(landscapePLO));
table = append(d,magic(11));
table.Border = 'solid';
table.ColSep = 'solid';
table.RowSep = 'solid';
%switch to portrait
append(d, clone(portraitPLO));
table = append(d,magic(5));
table.Border = 'solid';
table.ColSep = 'solid';
table.RowSep = 'solid';
%switch to landscape again
append(d, clone(landscapePLO));
table = append(d,magic(8));
table.Border = 'solid';
table.ColSep = 'solid';
table.RowSep = 'solid';
close(d);
rptview(d);

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!