python 写入数据

import sys
reload(sys)
sys.setdefaultencoding('utf8')

import xlrd
import xlwt
book = xlrd.open_workbook('C:/Users/13717/Desktop/sg.xls')
sheet = book.sheet_by_index(0)

book1 = xlwt.Workbook()    #创建文件
sheet1 = book1.add_sheet('test',cell_overwrite_ok=True)#创建工作部对象
print sheet.nrows,sheet.ncols
for i in range(sheet.nrows):
    print sheet.row(i)[1].value
    if sheet.row(i)[1].value == '河北':
        for j in range(0,10):
                sheet1.write(i,j,sheet.row(i)[j].value)    #根据行号写内容

book1.save('test.xls')

 

posted @ 2018-09-10 12:35  破晓e  阅读(287)  评论(0编辑  收藏  举报