
我有一个由matplotlib生成的图,然后将它保存为.png,然后使用pptx模块将它放在PPT文件中。我想在我的PPT文件中添加图片的边框,谁能帮我写代码..?
from pptx.util import Inches
from pptx import Presentation
prs = Presentation('dashboard.pptx')
left = Inches(0.5)
top = Inches(1)
slide = prs.slides.add_slide(prs.slide_masters[0].slide_layouts[2])
pic = slide.shapes.add_picture('test.png',left, top,width =None ,height =None)
prs.save('dashboard_new.pptx')发布于 2015-09-06 23:41:41
python中的Picture对象具有一个line属性,该属性提供对边框属性的访问:
所以代码会像这样:
from pptx.dml.color import RGBColor
line = pic.line
line.color.rgb = RGBColor(0xFF, 0x00, 0x00)
line.width = Inches(0.1)发布于 2015-09-06 16:30:48
形状(在本例中是pic对象)具有一个.Line属性,该属性控制形状周围的边框。下面是一个如何在VBA中添加行的示例。在您的示例中,您将修改pic对象的相同.Line属性:
Sub AddBorder()
Dim oSh As Shape
' this assumes that the current shape is selected
' in other cases, you'd work with an object reference
' generated when you added the shape
Set oSh = ActiveWindow.Selection.ShapeRange(1)
With oSh
' if you don't set the line to be visible,
' you get odd results
.Line.Visible = msoTrue
.Line.ForeColor.RGB = RGB(255, 0, 0)
.Line.Weight = 6 ' in points
End With
End Subhttps://stackoverflow.com/questions/32421858
复制相似问题