Change Impress Layout at Runtime Using Basic Macro

1 min


This tutorial will show how to change the Impress Slide Layouts at Run-time.

Prerequisite

This tutorial assumes that you know how to create a basic Impress macro in LibreOffice. You can go through the basic guide using below link.

Impress Macro – Getting Started

In a presentation document, there are various styles of Layout present – Title only, Title with single box, double text box etc. For any automation tasks where it is required to generate the Impress presentation files dynamically with a desired layout, we need to program for the layout changes.

Layout Options

LibreOffice Impress 5.1+ comes with below layouts:

  • Blank Slide
  • Title Slide
  • Title, Content
  • Title and 2 Content
  • Title Only
  • Centered Text
  • Title, 2 Content and Content
  • Title, Content and 2 Content
  • Title, 2 Content over content
  • Title, Content over content
  • Title, 4 Content
  • Title, 6 Content

impress-macro-layouts

 

Macro

To change the Layout at run-time, use the Layout property of a Slide. Layout property takes a number which refers to any above of the layouts.

For example, to change a slide layout to “Title, Content”, follow below code:

oDoc = ThisComponent
' Get a List of all Slides
oSlideList = oDoc.getDrawPages()
' Get the First Slide
oSlide = oSlideList.getByIndex(0)
oSlide.Layout =1 ' Title, Content

Refer below table to get desired Layout numbers for various Layouts.

Layout Value Layout Type
0 Title Slide; one title and a text box
1 Title, Content
3 Title , two content
12 Title content, 2 content
14 Title, content over content
15 Title, 2 content and content
18 Title , 4 content
19 Title Only
34 Title, 6 content

Reference

DrawPage-Layout


Arindam

Creator and author of debugpoint.com. Connect with me via Telegram, Twitter, or send us an email.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments