鱼C论坛

 找回密码
 立即注册
查看: 1945|回复: 1

Python 创建excel表格 输入汉字的问题

[复制链接]
发表于 2017-11-10 23:17:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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")           
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-11-11 06:41:36 From FishC Mobile | 显示全部楼层
…你用的python2吧?编码问题,最好换python3就可以少很多麻烦了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-18 03:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表