Reputation: 1117
Install
pip install python-pptx==0.6.18
Code
from pptx.util import Inches
from pptx import Presentation
from pptx.enum.chart import XL_CHART_TYPE
from pptx.chart.data import CategoryChartData
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[5])
shapes = slide.shapes
shapes.title.text = ' '
chart_data = CategoryChartData()
chart_data.categories = ['East', 'West', 'Midwest']
chart_data.add_series('Series 1', (19.2, 21.4, 16.7))
x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data)
prs.save('test.pptx')
Actual
Expect
I want to add border for this whole chart, but I can't find any API from python-pptx Documentation.
How to solve it?
Upvotes: 1
Views: 767
Reputation: 21
xml = '<c:roundedCorners val="0"/>'
parser = etree.XMLParser(recover=True)
element = etree.fromstring(xml, parser)
chart._chartSpace.append(element)
Use this code to remove rounded corners.
Upvotes: 2
Reputation: 1117
from pptx.util import Inches
from pptx import Presentation
from pptx.enum.chart import XL_CHART_TYPE
from pptx.chart.data import CategoryChartData
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[5])
shapes = slide.shapes
shapes.title.text = ' '
chart_data = CategoryChartData()
chart_data.categories = ['East', 'West', 'Midwest']
chart_data.add_series('Series 1', (19.2, 21.4, 16.7))
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
from lxml import etree
xml = '<c:spPr><a:ln><a:solidFill><a:schemeClr val="tx1"/></a:solidFill></a:ln></c:spPr>'
parser = etree.XMLParser(recover=True)
element = etree.fromstring(xml, parser)
chart._chartSpace.append(element)
prs.save('test.pptx')
Upvotes: 3