我想讀取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