我想读取python中excel文件的单元格,更改它的值并保存。如果我没有行from xlutils.copy import copy
的代码,它承认workbook.sheeets()
,但除此之外,它说用python读写excel文件
AttributeError: 'Workbook' object has no attribute 'sheets'
from xlutils.copy import copy
import xlrd
st = xlwt.easyxf('pattern: pattern solid;')
rb = xlrd.open_workbook('00-17.xlsx')
workbook = copy(rb)
for sheet in workbook.sheets():
for row in range(sheet.nrows):
current_value = sheet.cell(row,3).value
if(current_value == '1') :
st.pattern.pattern_fore_colour = 5
for column in [0,2,3]:
value = sheet.cell(row, column).value
print value
sheet.write(row, column, value,st)
workbook.save('1.xlsx')
什么是错误? –
AttributeError:'工作簿'对象没有属性'get_sheet_by_name' – Pegah
您可能想继续阅读“xlrd”的文档。按名称访问工作表的方法是'.sheet_by_name'而不是'.get_sheet_by_name'。另外,要获得行数,只需使用'sheet.nrows'。 – Abdou