PowerPoint应用程序在Python的win32com下设置为虚假时,可见属性不起作用

2024-09-26 22:53:43 发布

您现在位置:Python中文网/ 问答频道 /正文

当设置为“False”时,python下win32com包中Powerpoint应用程序的visible属性不起作用。当visible属性设置为true并且pptx在给定的代码段执行后打开时,它就开始工作了。我不想被打开。你能在给定的代码中提出一些更正建议吗。我在执行下面的代码时遇到了下面的错误。在

ExcelApp = win32com.client.Dispatch("Excel.Application")
ExcelApp.Visible = False
workbook = ExcelApp.Workbooks.open(r'C:\Users\aju.mathew.thomas\Desktop\PBC\Pepsi\PBC\Performance Reports\2019\PPT\PerformanceReportMetrics.xlsx')
worksheet = workbook.Worksheets("Summary")
excelrange = worksheet.Range("A1:R20")


PptApp = win32com.client.Dispatch("Powerpoint.Application")
PptApp.Visible = False
z = excelrange.Copy()

PPtPresentation = PptApp.Presentations.Open(r'C:\Users\aju.mathew.thomas\Desktop\PBC\Pepsi\PBC\Performance Reports\2019\PPT\Performance Reports.pptx')
pptSlide = PPtPresentation.Slides.Add(1,11)
title = pptSlide.Shapes.Title
title.TextFrame.TextRange.Text = 'Metrics Summary'
pptSlide.Shapes.PasteSpecial(z)
PPtPresentation.SaveAs(r'C:\Users\aju.mathew.thomas\Desktop\PBC\Pepsi\PBC\Performance Reports\2019\PPT\Performance2.pptx',1)
workbook.Save()
workbook.Close(True)

错误消息

PptApp.Visible = False, self.oleobj.Invoke(entry.dispid, 0, invoke_type, 0, value) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft PowerPoint', 'Application.Visible : Invalid request. Hiding the application window is not allowed.', '', 0, -2147188160), None)


Tags: falseapplicationperformancethomasuserswin32comworkbookreports

热门问题