英文:
Embedding an excel file using python-pptx: add_ole_object
问题
我正在尝试将一个包含数据的Excel文件嵌入到PowerPoint文件中,但是当我运行代码时,它添加的是一个空的Excel文件,而不是具有数据的Excel文件(Test.xlsx)。
以下是我运行的代码:
from pptx import Presentation
from pptx.util import Inches
ppt = Presentation()
title_slide = ppt.slides.add_slide(ppt.slide_layouts[0])
title_slide.shapes.add_ole_object('Test.xlsx', 'Excel.Sheet', left=Inches(1), top=Inches(3))
ppt.save('Test.pptx')
这是我参考的文档:
https://python-pptx.readthedocs.io/en/latest/api/shapes.html
我不确定我是否运行得不正确。我会感激任何关于此的建议。
英文:
I am trying to embed an excel file with data to a powerpoint file, but when I run the code, it adds an empty excel file instead of the excel file which has data (Test.xlsx).
Below is the code I ran,
from pptx import Presentation
from pptx.util import Inches
ppt = Presentation()
title_slide = ppt.slides.add_slide(ppt.slide_layouts[0])
title_slide.shapes.add_ole_object('Test.xlsx', 'Excel.Sheet', left = Inches(1), top = Inches(3))
ppt.save('Test.pptx')
This is documentation I referred,
https://python-pptx.readthedocs.io/en/latest/api/shapes.html
I am unsure if I am running it incorrectly. I would appreciate any advice on this.
答案1
得分: 1
我已经解决了这个问题,所以对于 Prog_ID,我不再使用 'Excel.Sheet',而是使用 PROG_ID.XLSX。我使用 'from pptx.enum.shapes import PROG_ID' 导入了 PROG_ID。希望这对遇到这个问题的人有所帮助。
来源:github.com/scanny/python-pptx/issues/752
英文:
I was able to resolve this, so for the Prog_ID, instead of 'Excel.Sheet' I had to use PROG_ID.XLSX. I imported PROG_ID using 'from pptx.enum.shapes import PROG_ID'. In case anyone has this problem, hopefully this helps.
Source: github.com/scanny/python-pptx/issues/752
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论