大家看看這段代碼為什么會報錯
#?encoding:utf-8 import?xlrd,xlwt def?stary(names,hight,cole): ????staryer=xlwt.XFStyle ????fone=xlwt.Font ????fone.name=names ????fone.height=hight ????fone.bold=True ????fone.underline=True ????fone.colour_index=cole ????fone.outline=True ????staryer.font=fone a=input('請選擇字體:') b=input('字體大?。?) c=input('字體顏色:') book=xlwt.Workbook() new_sheet=book.add_sheet('新建工作表') new_sheet2=book.add_sheet('新建工作表2') book.save('d:\新建工作部.xsl') wookbook=xlrd.open_workbook('d:\新建工作部.xsl') sheet=wookbook.sheet_by_index(0) sheet2=wookbook.sheet_by_index(1) sheet.write(0,0,'實驗',stary(a,b,c)) book.save('d:\新建工作部.xsl')
這是報錯信息
請選擇字體:'Time New Roman'
字體大?。?00
字體顏色:3
Traceback (most recent call last):
? File "D:/S14/python模塊/xlrd模塊.py", line 23, in <module>
? ? sheet.write(0,0,'實驗',stary(a,b,c))
AttributeError: 'Sheet' object has no attribute 'write'
2019-07-09
sheet對象沒有write屬性
2019-06-16
你看看這樣我依然出錯
C:\Users\25063\Anaconda3\python.exe D:/S14/python模塊/xlrd模塊.py
請選擇字體:Malgun Gothic
字體大?。?00
字體顏色:3
Traceback (most recent call last):
? File "D:/S14/python模塊/xlrd模塊.py", line 23, in <module>
? ? new_sheet.write(0,0,'實驗',stary(a,b,c))
? File "C:\Users\25063\Anaconda3\lib\site-packages\xlwt\Worksheet.py", line 1088, in write
? ? self.row(r).write(c, label, style)
? File "C:\Users\25063\Anaconda3\lib\site-packages\xlwt\Row.py", line 229, in write
? ? self.__adjust_height(style)
? File "C:\Users\25063\Anaconda3\lib\site-packages\xlwt\Row.py", line 59, in __adjust_height
? ? twips = style.font.height
AttributeError: 'NoneType' object has no attribute 'font'
Process finished with exit code 1
2019-06-16
sheet 在這里是不能被使用的,你看發出來的最后一行