|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
想利用python创建一个excel表格,在表格中输入汉字,但是会报错,应该怎么修改呢?请指教
# _*_coding:utf-8_*_
import os
import xlwt
import xlrd
def name_list():
print "请输入学生的名字:"
name=str(raw_input())
return name
def score_list():
print "请输入学生的成绩:"
score=str(raw_input())
return score
def age_list():
print "请输入学生的年龄:"
age=str(raw_input())
return age
Path="D:/Onebox/Python/Study"#信息文件存放路径
def student_information_write(num): #建立学生信息
row=0 #行数
col=0 #列数
num=int(num)
#if os.path.isfile(Path+"/information.xls"):
# information_excel=xlrd.open_workbook(Path+"/information.xls")#如果文件存在打开表格
# information_sheet=information_excel.sheet_by_name(u"information")
# row=informatiom_sheet.get_highest_row()
#else:
information_excel=xlwt.Workbook(Path+"/information.xls")#如果文件,不存在新建表格
information_sheet=information_excel.add_sheet(u"information")#建立信息sheet
information_sheet.write(0,0,u"student name")# 存放学生姓名信息
information_sheet.write(0,1,u"student age")# 存放学生成绩信息
information_sheet.write(0,2,u"student score")#存放学生年龄信息
while(num!=0):
name=name_list.decode()执行到这里的时候输入汉字就会报错,应该怎么解决呢?
age=age_list().decode()
score=score_list().decode()
information_sheet.write(row+1,col,name)# 写入名字
information_sheet.write(row+1,col+1,age)#写入年龄
information_sheet.write(row+1,col+2,score)#写入成绩
row+=1
num-=1
information_excel.save("information.xls")
|
|