Python 下 win32com 包中 Powerpoint 应用程序的可见属性在设置为“False”时不起作用。当visible属性设置为true并且给定的代码执行后pptx就会打开时,它就可以工作。我不想打开PPT。您能否建议对给定代码进行一些更正。当我执行下面的代码时,出现以下错误。
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)
最佳答案
添加
WithWindow=False
在公开声明中。 像这样:
PPtPresentation = PptApp.Presentations.Open(r'C:\demo.pptx', WithWindow=False)
关于python - python下win32com中Power point应用程序的可见属性设置为false时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56538121/