使用xlrd.book.book.sheet_by_name()时,将“book”替换为笔记本变量名,出现一个属性错误,指出模块“xlrd.book”没有属性“book”。我已经检查过book对象是用xlrd而不是xlwt创建的。
def read_ws(wb, worksheet_name):
'''
Opens a read_only copy of the worksheet.
'''
return xlrd.book.wb.sheet_by_name(worksheet_name)
def existing_start_sheet(path, ws_name, data):
'''
Reads and modifies and existing starter sheet.
'''
workbook = xlwt.Workbook(path)
workbook_r = xlrd.open_workbook(path)
r_ws = read_ws(workbook_r, ws_name)
mod_start_sheet(workbook, r_ws, data)
return
以下是我提到的文档:https://xlrd.readthedocs.io/en/latest/api.html?highlight=sheet_by_name#xlrd.book.book.sheet_by_name
1条答案
按热度按时间2w2cym1i1#
这不应该是回报吗
wb.sheet_by_name(worksheet_name)
?sheet_by_name
是一种方法wb
对象我建议您重新阅读oop教程。