{"id":2100,"date":"2019-06-03T09:11:18","date_gmt":"2019-06-03T07:11:18","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=2100"},"modified":"2019-12-07T19:35:59","modified_gmt":"2019-12-07T18:35:59","slug":"create-presentations-with-python-pptx","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/create-presentations-with-python-pptx\/","title":{"rendered":"Create Presentations with Python-pptx"},"content":{"rendered":"<p>Here is the code to make a presentation in powerpoint with Python and the module python-pptx.<\/p>\n<p>We created a class that takes as a argument a list with<\/p>\n<ul>\n<li>title of the slide<\/li>\n<li>subtitle<\/li>\n<li>number of layout (0 is for the first slide, 1 is for the title + bullet points &#8230; ecc.)<\/li>\n<\/ul>\n<p>Creating a list o list with the three arguments, you can easily create a whole presentation (for now with just text).<\/p>\n<pre class=\"lang:default decode:true \">from pptx import Presentation\r\nimport os\r\n\r\n# Create a powerpoint file\r\nprs = Presentation()\r\n\r\nclass Slide:\r\n\r\n\tdef __init__(self, data):\r\n\t\t# data is a list with title, subtitle and layout num\r\n\t\tprint(data)\r\n\t\tself.layout = prs.slide_layouts[data[2]]\r\n\t\tself.slide = prs.slides.add_slide(self.layout)\r\n\t\tself.title = self.slide.shapes.title\r\n\t\tself.title.text = data[0]\r\n\t\tself.subtitle = self.slide.placeholders[1]\r\n\t\tself.subtitle.text = data[1]\r\n\r\ndef save(name):\r\n\tprs.save(name)\r\n\t# Open the file on the operating system\r\n\tos.startfile(name)\r\n\r\n# title \/ subtitle \/ layout num\r\nslides = [\r\n[\"Hello people\", \"We are great\", 1]\r\n]\r\n\r\nfor s in slides:\r\n\tSlide(s)\r\n\r\nsave(\"prova.pptx\")<\/pre>\n<h4>Python and Powerpoint<\/h4>\r\n\r\n\t<script>\r\nvar title = \"Python and powerpoint\";\r\n\t\tvar links = [\r\n\t\t[\"https:\/\/pythonprogramming.altervista.org\/?p=5719&preview=true\",\"Present with SVG files\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-pptx-put-images-in-powerpoint\/\",\"Put images in powerpoint with python-pptx\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/create-a-presentation-with-python-presentations\/\",\"Python-Presentations... without Powerpoint\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-to-create-quickly-powepoint-presentation\/\",\"PyPowerpoint 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-to-powerpoint-2-0\/\",\"PyPowerpoint 2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-and-powerpoint-3-0\/\",\"PyPowerpoint 3\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/powerpoint-pil-png-animated-gif\/\",\"Create a Gif with Powerpoint and Python\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/inserting-an-image-in-powerpoint-with-python\/\",\"Fit Images in Powerpoint with Python\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/a-program-to-use-powerpoint-with-python\/\", \"Use Powerpoint with Python\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/create-presentations-with-python-pptx\/\",\"Create a Powerpoint with Python\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/simple-presentation-in-pure-python-while-you-learn-tkinter\/\", \"Createa Slides without Powerpoint\"]\r\n\t\t\t\r\n];\r\n<\/script>\r\n<script>\r\n\t\r\nif (typeof next2 != \"undefined\"){let next2 = 0;}\r\n\t\r\nnext2 = 0;\r\n\thtml = \"\";\/\/<b style='color:coral;font-size:1.2em'>Other posts about \" + title + \"<\/b><br>\";\r\nfor (address of links) \r\n{\r\n\r\n\tif (next2 == 1){\r\n\t\thtml += \"<div style='background:coral'>\";\r\n\t\thtml += \"Next link => <a href='\" + address[0] + \"'>\" + address[1] + \"<\/a>\";\r\n\t\thtml += \"<\/div><br>\";\r\n\t\tnext2 = 0;\r\n\t}\r\n\tif (address[0] == document.URL) {\r\n\t\tnext2 = 1;\r\n\t}\r\n}\r\n\r\nif (typeof next != \"undefined\") {let next = 0;}\r\nif (typeof addressStart != \"undefined\") {let addressStart = \"\";}\r\nnext = 0;\r\naddressStart = \"<a href='\";\r\nfor (address of links) {\r\n\tif (next == 1){\r\n\t\thtml += \">>>\" + addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t\tnext = 0;\r\n\t}\r\n\telse if (addressStart + address[0] != document.URL)\r\n\t{\r\n\t\thtml += addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t}\r\n\telse\r\n\t{\r\n\t\tnext = 1;\r\n\t\tnext_address = address[0]\r\n\t\tnext_title = address[1]\r\n\t\thtml += \"<span style='color:gray'>\" + address[1] + \"<\/span><br>\";\r\n\t}\r\n\r\n}\r\n\r\n\thtml += `<span style=\"font-size:8px\">Powered by <a href=\"https:\/\/pythonprogramming.altervista.org\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2673\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png\" alt=\"\" width=\"70\" height=\"25\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png 156w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2-150x56.png 150w\" sizes=\"auto, (max-width: 70px) 100vw, 70px\" \/>pythonprogramming.altervista.org<\/a><\/span>`\r\n\thtml = \"<div style='background:yellow'>\" + html + \"<\/div>\";\r\n\tdocument.write(html)\r\n<\/script>\r\n<br>\r\n\t<!----- pubblicit\u00e0-------- vedi h:\\ads\\codice_di_prima.txt per il codice che era qui --------------------->\r\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<!-- Altervista-pythonprogramming-336X280 -->\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block\"\r\n     data-ad-client=\"ca-pub-4189782812829764\"\r\n     data-ad-slot=\"2548661001\"\r\n     data-ad-format=\"auto\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script>\r\n\t<!-- fine ad -->\n","protected":false},"excerpt":{"rendered":"Create a powerpoint presentation with Python.\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/create-presentations-with-python-pptx\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":4271,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[196],"tags":[405,4],"class_list":["post-2100","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powerpoint","tag-powerpoint","tag-python"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":false,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=2100"}],"version-history":[{"count":2,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2100\/revisions"}],"predecessor-version":[{"id":4279,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/2100\/revisions\/4279"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/4271"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=2100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=2100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=2100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}