Python 自动化PPT-修改已有模板中的数据
#import packages
from pptx import Presentation
import os
import pandas as pd
import numpy as np
from pptx.util import Cm,Pt,Inches
from pptx.dml.color import RGBColor
from pptx import chart
from pptx.chart.data import CategoryChartData
from pptx.chart.plot import BarPlot
from pptx.chart import plot
from pptx.enum.chart import XL_LEGEND_POSITION,XL_LABEL_POSITION
from pptx.chart.datalabel import DataLabel
#import data
data=pd.read_excel(‘data.xlsx’,sheet_name=1)
# import presentation model
ppt=Presentation('ppt.pptx')
# alert data of table in page 1
slide_1=ppt.slides[0]
table_1=shapes[0].table
for row in range(4):
for col in range(2):
table_1.cell(2+row,2+col).text=str(data.iloc[row,col])# data position
#alter font format
for cell in table_1.rows[7].cells:#alter row 7 format
for paragraph in cell.text_frame.paragraphs:
paragraph.font.size=Pt(16)#font size
paragraph.font.name='SF Hello Ligh

本文介绍了如何使用Python来自动化处理PPT,特别是针对已有模板进行数据更新的方法。

1万+

被折叠的 条评论
为什么被折叠?



