[英]How to copy a range from an Excel File and paste that range into a Powerpoint slide using Python?
I'd like to copy a range from an excel document into a powerpoint slide. 我想将Excel文档中的范围复制到PowerPoint幻灯片中。
This is my attempt after reading through this documentation : 阅读完本文档后,这是我的尝试:
import win32com.client
powerpoint_object = win32com.client.Dispatch("Powerpoint.Application")
powerpoint_object.visible = True
powerpoint_presentation = powerpoint_object.Presentations.Open("example_powerpoint.pptx")
excel_object = win32com.client.Dispatch("Excel.Application")
excel_object.visible = True
excel_workbook = excel_object.Workbooks.Open(Filename="example_excel.xlsx")
excel_worksheet = excel_workbook.Worksheets("Sheet1")
excel_range = excel_worksheet.Range("A1:L100")
excel_range.Copy()
powerpoint_slide = powerpoint_presentation.Slides.Add(1,12)
powerpoint_slide.Shapes().Paste()
However I get the following error: 但是我收到以下错误:
com_error: (-2147352567, 'Exception occurred.')
Most likely this error is caused by the lack of full file paths. 此错误很可能是由于缺少完整文件路径引起的。 Try replacing "example_powerpoint.pptx"
and "example_excel.xlsx"
with their full paths. 尝试将"example_powerpoint.pptx"
和"example_excel.xlsx"
替换为其完整路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.