我正在寻找生成ex中给出的这种类型的情节。使用python pptx。
我无法获得绘图中给出的数据表,也无法获得黑色线条图的样式和组合。
正在寻求帮助。预先感谢
答案 0 :(得分:0)
感谢快速回复。我知道,这不是编写代码的最佳方法。我只是在最初的水平上尝试制作发布的ppt幻灯片。 PPT slide 我无法获得图表中所示的数据表,也无法获得折线图和条形图的样式以及组合(如下图excel图像中所示的保证金列,我想要在折线图中显示datatable横杆,但此处未显示。) Excel image
import openpyxl
from pptx import Presentation
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches
from pptx.enum.chart import XL_LEGEND_POSITION
from pptx.dml.color import RGBColor
# create presentation with 1 slide ------
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[5])
wb = openpyxl.load_workbook('test_ppt.xlsx')
sheet = wb.active
fff = []
for f in range(4,10):
name_l = str(sheet['c'+str(f)].value)
fff.append(name_l)
noo = []
for f in range(4,10):
noo_l = str(sheet['b'+str(f)].value)
noo.append(noo_l)
erp = []
for f in range(4,10):
noo_ll = str(sheet['d'+str(f)].value)
erp.append(noo_ll)
aa = tuple(map(int, fff))
ab = tuple(map(int, erp))
chart_data = CategoryChartData()
chart_data.categories = noo
series1 = str(sheet['c'+str(3)].value);
series2 = str(sheet['d'+str(3)].value);
chart_data.add_series(series1, aa)
chart_data.add_series(series2, ab)
x, y, cx, cy = Inches(2), Inches(2), Inches(6), 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.pptx')
#series = chart.series[0]
## ---series.format is a ChartFormat object, which in turn provides access to
## the LineFormat object for that series---
#line = series.format.line
# ---change the line style, color, etc. the same way as for any other line---
#line.color.rgb = RGBColor(255, 0, 0)