代码示例:



# -*-encoding: utf-8 -*-

# 打开目标excel
# 获取excel中第一个表单
# 读取出里面写入的行数
# 将xlrd 的 workbook 转为 xlwt的 workbook 对象
# 追加数据
import xlrd3
import xlwt
from xlutils.copy import copy

info = [
['张三疯', 27.0, '打游戏'],
['陈二狗', 25.0, '打自己'],
['程小鸭', 26.0, '打人'],
['贾精忠', 27.0, '被人打']
]
# 打开目标excel
targetExcel = xlrd3.open_workbook('aoe.xlsx')
# 获取excel中表单数
sheetNames = targetExcel.sheet_names()
# 获取excel中第一个表单
first_sheet = targetExcel.sheet_by_name(sheetNames[0])
# 读取出excel 里面的有效行 和 有效列
nrows = first_sheet.nrows
ncols = first_sheet.ncols

# 将xlrd 的 workbook 转为 xlwt的 workbook 对象

workBook = copy(targetExcel)

newSheet = workBook.get_sheet(0)

# 追加数据
i = nrows

for item in info:
for j in range(ncols):
newSheet.write(i,j,item[j])
i = i + 1

# 保存
workBook.save('aoe.xlsx')


图例:

追加前:

Python xlutils excel追加数据_数据

 

 追加后:

Python xlutils excel追加数据_表单_02

 


钟声敲响了日落,柏油路跃过山坡,一直通向北方的是我们想象,长大后也未曾经过~