亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

大家看看這段代碼為什么會報錯

#?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'


正在回答

3 回答

sheet對象沒有write屬性

0 回復 有任何疑惑可以回復我~
#?encoding:utf-8
import?xlrd,xlwt
def?stary(names,hight,cole):
????staryer=xlwt.XFStyle
????nfone=xlwt.Font
????nfone.name=names
????nfone.height=hight
????nfone.bold=True
????nfone.underline=True
????nfone.colour_index=cole
????nfone.outline=True
????staryer.font=nfone
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)
new_sheet.write(0,0,'實驗',stary(a,b,c))
book.save('d:\新建工作部.xsl')

你看看這樣我依然出錯

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


0 回復 有任何疑惑可以回復我~

sheet 在這里是不能被使用的,你看發出來的最后一行

1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
初識Python
  • 參與學習       758396    人
  • 解答問題       8967    個

學python入門視頻教程,讓你快速入門并能編寫簡單的Python程序

進入課程

大家看看這段代碼為什么會報錯

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號