python-pptx

How to pass PIL image to Add_Picture in python-pptx

无人久伴 提交于 2019-12-11 06:10:42
问题 I'm trying to get the image from clipboard and I want to add that image in python-pptx . I don't want to save the image in the Disk. I have tried this: from pptx import Presentation from PIL import ImageGrab,Image from pptx.util import Inches im = ImageGrab.grabclipboard() prs = Presentation() title_slide_layout = prs.slide_layouts[0] slide = prs.slides.add_slide(title_slide_layout) left = top = Inches(1) pic = slide.shapes.add_picture(im, left, top) prs.save('PPT.pptx') But Getting this

Adding text / slide title to placeholder on slide with python-pptx

大憨熊 提交于 2019-12-11 03:28:25
问题 I am trying to add a title to my slide . I was looking up the documentation here and it says, "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' " Actually my slide layout does not have

Extracting images from presentation file

↘锁芯ラ 提交于 2019-12-10 23:56:04
问题 I am working on python-pptx package. For my code I need to extract all the images that are present inside the presentation file. Can anybody help me through this ? Thanks in advance for help. my code looks like this: import pptx prs = pptx.Presentation(filename) for slide in prs.slides: for shape in slide.shapes: print(shape.shape_type) while using shape_type it is showing PICTURE(13) present in the ppt. But i want the pictures extracted in the folder where the code is present. 回答1: A Picture

Python-pptx - Text parameters (font, size, position) on Autoshape

假如想象 提交于 2019-12-10 21:54:16
问题 How can I set font, size of text for the shape ? One Object instead two seperate ones (shape and Text, how use run for the shape) Just do not get how to set the parameters on Textframe instance of the Autoshape-object. from pptx import Presentation from pptx.enum.shapes import MSO_SHAPE from pptx.enum.dml import MSO_THEME_COLOR from pptx.enum.text import MSO_ANCHOR, MSO_AUTO_SIZE from pptx.util import Inches, Pt prs = Presentation('Input.pptx') slide_layout = prs.slide_layouts[2] slide = prs

create new pptx using existing pptx Python-Pptx

冷暖自知 提交于 2019-12-10 18:51:26
问题 I am trying to create new.pptx using an old.pptx . old.pptx is having 4 slides in it . I want to create the new.pptx with almost same content with few text modifications in 4 slides . I skipped the modification part from the below code, you can take an example like converting lower cases to upper case..Need to do these things in run time, so that if i just pass the old.pptx it will do the required operation and then write it to new pptx with same no. of slides..I am not sure how to tweak

How to save a presentation to a file-like object in Python 3

陌路散爱 提交于 2019-12-10 17:36:21
问题 Python 3 replaced StringIO.StringIO with io.StringIO . I've been able to successfully save presentations using the former, but it doesn't appear to work for the latter. from pptx import Presentation from io import StringIO presentation = Presentation('presentation.pptx') output = StringIO() presentation.save(output) The above code produces: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site

Why does saving a presentation to a file-like object produce a blank presentation?

ε祈祈猫儿з 提交于 2019-12-10 14:23:05
问题 As a response to this answer to a previous question of mine, I wrote the following short program to try and reproduce the problem. from pptx import Presentation from io import BytesIO p = Presentation() slide = p.slides.add_slide(p.slide_layouts[0]) slide.shapes[0].text = 'asdf' p.save('test.pptx') out = BytesIO() p.save(out) out_file = open('bytes_test.pptx', 'wb', buffering=0) out_file.write(out.read()) out_file.close() This produced two pptx files. The first, test.pptx, contained a single

Python pptx (Power Point) Find and replace text (ctrl + H)

ぐ巨炮叔叔 提交于 2019-12-10 10:32:10
问题 Question in Short: How can I use the find and replace option ( Ctrl + H ) using the Python-pptx module? Example Code: from pptx import Presentation nameOfFile = "NewPowerPoint.pptx" #Replace this with: path name on your computer + name of the new file. def open_PowerPoint_Presentation(oldFileName, newFileName): prs = Presentation(oldFileName) prs.save(newFileName) open_PowerPoint_Presentation('Template.pptx', nameOfFile) I have a Power Point document named "Template.pptx". With my Python

Center-align text with Python-pptx

拈花ヽ惹草 提交于 2019-12-10 10:12:12
问题 Question in short: Is it possible to align text to the center in Python-pptx? Since I'm using Python-pptx, I have been able to automate quite a lot of things and I really enjoy using it! However, I've run into a problem. I'm trying to center my text horizontally on a slide. If you don't understand me: My text is now aligned to the left, similar to the text in the first two paragraphs. However, I'd like them to be aligned to the center, like those last two paragraphs. This is a snippet of my

Python PPTX Internal Hyperlinks workaround function

别来无恙 提交于 2019-12-08 11:44:42
问题 I tried to follow example as discussed in https://groups.google.com/forum/#!topic/python-pptx/nrUkiQQHyZo , however ended up with an error 'Slide' object has no attribute 'rels' . The minimal code I'm experimenting tries to build a hyperlink in first slide to third slide. import pptx import pptx.enum from pptx import Presentation from pptx.enum.action import PP_ACTION from pptx.opc.constants import RELATIONSHIP_TYPE as RT #very minimal Powerpoint template prs = Presentation("tpl.pptx") #