AttributeError:'Sheet'对象没有属性'Shapes'

时间:2017-07-21 14:29:47

标签: python excel python-2.7

以下是我正在运行的代码。我想要实现的目标很简单。我需要从现有的Excel文件中复制图表。粘贴为图表(NOT图像)到现有的PowerPoint幻灯片中。

但我总是得到错误

  

“AttributeError:'Sheet'对象没有属性'Shapes'”

我应该安装任何软件包吗?

from pptx import Presentation
import xlrd
import math
import xlutils

import win32com.client
from win32com.client import constants

prs = Presentation('D:\Sruti K\Online_Retail\APAC\Office Slides\Office QBU Slides\FY17 Q4 June\Office Slides FY17 Q4 test.pptx')
title_slide_layout = prs.slide_layouts[3]
slide = prs.slides.add_slide(title_slide_layout)

book = xlrd.open_workbook(r'D:\Sruti K\Online_Retail\APAC\Office Slides\Office QBU Slides\FY17 Q4 June\Python Chart Paste.xlsx')
ws = book.sheet_by_index(0)

sheetsinbook=[book.sheet_by_index(0)]


for ws in sheetsinbook:
    for chart in ws.Shapes():
        chart.Activate()
        chart.Copy()
        slide.Shapes.PasteSpecial(constants.ppPasteShape)
        Print("hi")

prs.save(r'D:\Sruti K\Online_Retail\APAC\Office Slides\Office QBU Slides\FY17 Q4 June\Python Trial APAC PPT V1.pptx')

1 个答案:

答案 0 :(得分:0)

问题是你正在利用随机词,这会改变他们的行为/召唤。例如,您键入了Print而不是print这是无效的,除非您有一个名为Print的。如果您使用ws.shapes()代替它,它应该可以工作(并且也可以取消其他一些单词的大写)。