python Excel追加数据

来源:互联网 发布:国外聊天软件 编辑:程序博客网 时间:2024/05/19 03:22
from xlutils.copy import copyimport xlrdimport osdef write_append(file_name):    values = ['张三','男',22]    r_xls = xlrd.open_workbook(file_name) #打开Excel文件读取数据    r_sheet = r_xls.sheet_by_index(0)  #通过索引顺序获取    rows = r_sheet.nrows  #获取行数    w_xls = copy(r_xls)    sheet_write = w_xls.get_sheet(0)    for i in range(0, len(values)):        sheet_write.write(rows, i, values[i])    w_xls.save(file_name)if __name__ == "__main__":    write_append("po.xls")