Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create PPT Files in Python Automation Office

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article Xiaobian for you to introduce in detail "Python automation office how to create PPT files", the content is detailed, the steps are clear, the details are handled properly, I hope this "Python automation office how to create PPT files" article can help you solve your doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge.

Installation of python-pptx

Installation:

Pip install xlsxwriter

If the installation is not available or the installation speed is too slow, you can change the domestic image source address: pip install-I https://pypi.tuna.tsinghua.edu.cn/simple python-pptx

Import:

Import python=pptx generates an empty PPT

Create an empty PPT object

Ppt = Presentation () instantiates a ppt object through Presentation () (Presentation can be used directly through python-pptx)

Set the layout of PPT

Layout = ppt.slide_layout [1] sets a layout for the current ppt object through slide_layout [1], and you can select a total of 9 layouts from 0 to 8 in square brackets.

Generate one page of PPT

Slide = ppt.slides.add_slide (layout) passes in layout through the slides.add_slide (layput) function, and a page of PPT is generated.

Save PPT

Ppt.save (pptx) passes in the saved address through the save () function, and a PPT file is created.

The code example is as follows:

# coding:utf-8import pptx # pip install-I https://pypi.tuna.tsinghua.edu.cn/simple python-pptxppt = pptx.Presentation () # generate ppt object layout = ppt.slide_layouts [1] # Select layout 0,1,7 three most commonly used slide = ppt.slides.add_slide (layout) ppt.save ('test1.ppt')

The running results are as follows:

Nine layouts of python-pptx

The code example is as follows:

# coding:utf-8import pptx # pip install-I https://pypi.tuna.tsinghua.edu.cn/simple python-pptxppt = pptx.Presentation () # generate ppt object layout = ppt.slide_layouts [0] # Select layout 0, 1, 7 three most commonly used # styles [0] is just a title# style [1] display title and text # style [7] display left and right two areas, title on the left. Slide = ppt.slides.add_slide (layout) ppt.save ('test1.ppt')

Take a look at several commonly used styles:

Read here, this "Python automation office how to create PPT file" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, welcome to pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report