J'essaie de lire la cellule d'un fichier excel en python, changez sa valeur et enregistrez-la. Si je n'ai pas la ligne from xlutils.copy import copy
dans le code, il reconnaît workbook.sheeets()
, mais sinon, il ditlire et écrire dans un fichier excel avec python
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')
Quelle est l'erreur? –
AttributeError: l'objet 'classeur' n'a pas d'attribut 'get_sheet_by_name' – Pegah
Vous pouvez commencer et lire la documentation de 'xlrd' en premier. La méthode pour accéder à une feuille par son nom est '.sheet_by_name' et non' .get_sheet_by_name'. Pour obtenir le nombre de lignes, utilisez également 'sheet.nrows'. – Abdou