Python怎么向xls追加信息

def setExcelValue(xlsname, sheetanme, value, line, row):

"""
w = xlwt.Workbook()
sheet = w.add_sheet(sheetanme)
sheet.write(line, row, value.decode('utf8'))
w.save(xlsname)
写了一个方法,但是该方法每次都要创建sheet页,然后在写数据到该sheet中
我想保留原sheet页中的数据,再追加数据

追加你应该用的是xlutils这个包。当然那这个包是依赖xlrd和xlwt包的。

from xlrd import open_workbook
from xlutils.copy import copy
rb = open_workbook(xls_path)
wb = copy(rb)
sheet = wb.get_sheet(0)
然后你再sheet.write就可以了。。最后写完用wb.save(xls_path)就完成了追加和修改。

温馨提示:答案为网友推荐,仅供参考
相似回答