|
用python pptx写的,参考- import pandas as pd
- from pptx import Presentation
- from pptx.chart.data import ChartData
- from pptx.enum.chart import XL_CHART_TYPE
- from pptx.util import Inches
- from pptx.enum.chart import XL_LEGEND_POSITION
- df=pd.read_excel('exceltoppt.xlsm')
- prs = Presentation()
- slide = prs.slides.add_slide(prs.slide_layouts[5])
- chart_data = ChartData()
- chart_data.categories = df['支出'].to_list()
- for i,j in zip(df.columns[1:],list(df.columns)[1:]):
- chart_data.add_series(i,tuple(df[j].to_list()))
- x, y, cx, cy = Inches(1), Inches(2), Inches(8.5), Inches(4.5)
- graphic_frame = slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data)
- chart = graphic_frame.chart
- chart.has_legend=True
- chart.legend.position=XL_LEGEND_POSITION.RIGHT
- chart.legend.include_in_layout = False
- prs.save('chart-01.pptx')
复制代码 |
|