Automate it! by Chetan Giridhar

Automate it! by Chetan Giridhar

Author:Chetan Giridhar
Language: eng
Format: mobi, epub
Publisher: Packt Publishing
Published: 2018-04-17T09:59:41+00:00


How it works...

In this recipe, we used the blank template to add a two-content layout slide. Let's see what else we did on top of it:

In the code, we used prs.slide_layouts[3] to convey the presentation object, prs, to add a slide with the two content layout. The two-content layout also has a title text, which was updated to Adding a Two Content Slide by using the shapes.title attribute.

Next, we looked at the placeholders. A placeholder is a preformatted container to which content can be added. Placeholders are categories of shape, which means multiple shapes can have placeholders. For instance, an autoshape (circle, as seen in the first recipe) is a placeholder; a picture or graphic frame can be a placeholder. We have two placeholders, one on the left and one on the right, in a two-content slide. We targeted the left one with shapes.placeholders[1] and added a first line This is line 1. to the text frame referenced by shapes.placeholders[1].text_frame.

We then added bulleted lines by adding a paragraph to text_frame with the add_paragraph() method and added the text Again a line 2... at level one and And this is line 3... at level two.

Basically, not all shapes contain text, but finding if a shape supports text can be done using the shape.has_text_frame attribute. In this recipe, we know our shape contains a placeholder that can handle text content. So, we used the text_frame attribute to add the first line of text. Similarly, we used the add_paragraph() method to add the subsequent lines in bulleted fashion using the level attribute.

In the end, we saved the new presentation under the name, two_content.pptx. If you look at the screenshot, we see the bulleted look on the text added to the left text frame on the slide.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.