Placeholders can make adding content a lot easier. If you’ve ever added a new textbox to a slide from scratch and noticed how many adjustments it took to get it the way you wanted you understand why. The placeholder is in the right position with the right font size, paragraph alignment, bullet style, etc., etc. Basically you can just click and type in some text and you’ve got a slide. Show
A placeholder can be also be used to place a rich-content object on a slide. A picture, table, or chart can each be inserted into a placeholder and so take on the position and size of the placeholder, as well as certain of its formatting attributes. Access a placeholder¶Every placeholder is also a shape, and so can be accessed using the
The most reliable way to access a known placeholder is by
its It’s usually easy enough to take a look at the placeholders on a slide and pick out the one you want: >>> prs = Presentation() >>> slide = prs.slides.add_slide(prs.slide_layouts[8]) >>> for shape in slide.placeholders: ... print('%d %s' % (shape.placeholder_format.idx, shape.name)) ... 0 Title 1 1 Picture Placeholder 2 2 Text Placeholder 3 … then, having the known index in hand, to access it directly: >>> slide.placeholders[1] <pptx.parts.slide.PicturePlaceholder object at 0x10d094590> >>> slide.placeholders[2].name 'Text Placeholder 3' Note Item
access on the placeholders collection is like that of a dictionary rather than a list. While the key used above is an integer, the lookup is on idx values, not position in a sequence. If the provided value does not match the idx value of one of the placeholders, In general, the Identify and Characterize a placeholder¶A placeholder behaves differently that other shapes in some ways. In particular, the value of its >>> prs = Presentation() >>> slide = prs.slides.add_slide(prs.slide_layouts[8]) >>> for shape in slide.shapes: ... print('%s' % shape.shape_type) ... PLACEHOLDER (14) PLACEHOLDER (14) PLACEHOLDER (14) To find out more, it’s necessary to inspect the contents of the placeholder’s >>> for shape in slide.shapes: ... if shape.is_placeholder: ... phf = shape.placeholder_format ... print('%d, %s' % (phf.idx, phf.type)) ... 0, TITLE (1) 1, PICTURE (18) 2, BODY (2) Another way a placeholder acts differently is that it inherits its position and size from its layout placeholder. This inheritance is overridden if the position and size of a placeholder are changed. Insert content into a placeholder¶Certain placeholder types have specialized methods for inserting content. In the current release, the picture, table, and chart placeholders have content insertion methods. Text can be inserted into title and body placeholders in the same way text is inserted into an auto shape. PicturePlaceholder.insert_picture()¶The picture placeholder has an
>>> prs = Presentation() >>> slide = prs.slides.add_slide(prs.slide_layouts[8]) >>> placeholder = slide.placeholders[1] # idx key, not position >>> placeholder.name 'Picture Placeholder 2' >>> placeholder.placeholder_format.type PICTURE (18) >>> picture = placeholder.insert_picture('my-image.png') Note A reference to a picture placeholder becomes invalid after its
A picture inserted in this way is stretched proportionately and cropped to fill the entire placeholder. Best results are achieved when the aspect ratio of the source image and placeholder are the same. If the picture is taller in aspect than the placeholder, its top and bottom are cropped
evenly to fit. If it is wider, its left and right sides are cropped evenly. Cropping can be adjusted using the crop properties on the placeholder, such as TablePlaceholder.insert_table()¶The table placeholder has an
>>> prs = Presentation('having-table-placeholder.pptx') >>> slide = prs.slides.add_slide(prs.slide_layouts[1]) >>> placeholder = slide.placeholders[10] # idx key, not position >>> placeholder.name 'Table Placeholder 1' >>> placeholder.placeholder_format.type TABLE (12) >>> graphic_frame = placeholder.insert_table(rows=2, cols=2) >>> table = graphic_frame.table >>> len(table.rows), len(table.columns) (2, 2) A table inserted in this way has the position and width of the original placeholder. Its height is proportional to the number of rows. Like all rich-content insertion methods, a reference to a table placeholder becomes invalid after its Note The return value of the
ChartPlaceholder.insert_chart()¶The chart placeholder has an
>>> from pptx.chart.data import ChartData >>> from pptx.enum.chart import XL_CHART_TYPE >>> prs = Presentation('having-chart-placeholder.pptx') >>> slide = prs.slides.add_slide(prs.slide_layouts[1]) >>> placeholder = slide.placeholders[10] # idx key, not position >>> placeholder.name 'Chart Placeholder 9' >>> placeholder.placeholder_format.type CHART (12) >>> chart_data = ChartData() >>> chart_data.categories = ['Yes', 'No'] >>> chart_data.add_series('Series 1', (42, 24)) >>> graphic_frame = placeholder.insert_chart(XL_CHART_TYPE.PIE, chart_data) >>> chart = graphic_frame.chart >>> chart.chart_type PIE (5) A chart inserted in this way has the position and size of the original placeholder. Note the return value from Like all rich-content insertion methods, a reference to a chart placeholder becomes invalid after its
Setting the slide title¶Almost all slide layouts have a title placeholder, which any slide based on the layout inherits when the layout is applied. Accessing a slide’s title is a common operation and there’s a dedicated attribute on the shape tree for it: title_placeholder = slide.shapes.title title_placeholder.text = 'Air-speed Velocity of Unladen Swallows' Can you change the levels of items in a list in a content placeholder?You cannot change the levels of items in a list in a content placeholder.
Which of these will you click in text pane to add text to a SmartArt?On the Insert tab, in the Illustrations group, click SmartArt. In the menu of types that appears, point at the type you want and then select a layout. Enter your text by doing one of the following: Click [Text] in the Text pane, and then type your text.
Which of the following can help you remember what you need to say in your presentation?Add speaker notes to help you remember what to say when you present. You can see your notes on your computer, but your audience only sees your slides.
When the title slide is the current slide What happens when you click the new slide button?Which of the following views would be the best one to use? Which of the following is text that describes the data illustrated in the chart? When the title slide is the current slide, what happens when you click the New Slide button? A new slide with the Title and Content layout is added after the title slide.
|