对excel表的操作主要通过xlwt,xlrd模块。
创建excel表
import xlwt
workbook = xlwt.Workbook(encoding='utf-8') worksheet = workbook.add_sheet('worksheet') worksheet.write(0, 0, 'id') workbook.save('name.xls')
对已有的excel表进行追加
import xlrd
from xlutils.copy import copy workbook = xlrd.open_workbook('./new_data.xls') # 打开表 number = int(workbook.sheet_by_index(0).nrows) # 得到表中数据的下一行 new_xls = copy(workbook) # 复制表 worksheet = new_xls.get_sheet(0) # 通过索引得到sheet worksheet.write( 'xxx','xxx','xxx') new_xls.save('new_xls.xls')