简体   繁体   English

如何使用Python从Excel文件复制范围并将其粘贴到Powerpoint幻灯片中?

[英]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.

相关问题 如何使用python从excel复制图表并将其作为图表粘贴到powerpoint(不是图像)中 - How to copy chart from excel and paste it as chart into powerpoint (not image) using python 如何使用python将数据从excel复制并粘贴到另一个excel - How to copy and paste data from excel to another excel using python 使用 Python 将指定范围的单元格从 Excel 复制到文本 - Copy specified range of cells from Excel to text using Python 如何使用 Python 将文本文件复制并粘贴到指定的 Excel TAB 中? - How to copy and paste text file into a specified Excel TAB using Python? 从 Microsoft excel csv 文件复制范围 - Copy range from Microsoft excel csv file 如何使用Python从Excel复制并粘贴为Word中的图像? - How to copy from Excel and paste as image in Word using Python? 使用 python xlwings 将范围复制并粘贴为值 - Copy and Paste range as values with python xlwings Python Openpyxl,复制并粘贴单元格范围 - Python Openpyxl, copy and paste cell range 如何复制一张ppt的幻灯片并将其粘贴到另一个ppt的特定位置,并使用pptx在python中创建一个新的ppt? - How to copy 1 slide of a ppt and paste it to specific location of another ppt and create a new ppt from it in python using pptx? 使用Python从Excel文件将当前范围的单元格导入MySql - Import from excel file a current range of cells to MySql using Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM