Excel追加写入

import xlrd
from xlutils.copy import copy


class AddToExcel:

def add_to_excel(self, r, things, filename):

xls = xlrd.open_workbook(filename)
xlc = copy(xls)
shc = xlc.get_sheet(0)
for data in things:
shc.write(r, things.index(data), data)
xlc.save(filename)


if __name__ == '__main__':
file = r'E:\work\a1.xlsx'
row = 4
somethings = [12, 45, 88, 90, 12]
a = AddToExcel()
a.add_to_excel(row, somethings, file)

猜你喜欢

转载自www.cnblogs.com/yzyj/p/10730250.html