原文地址:
https://segmentfault.com/a/1190000039060376

import xlrd #读取excel的库
import xlwt #写入excel的库
import xlutils
from xlutils.copy import copy

# 打开文件
xlsx = xlrd.open_workbook('weekshare.xlsx')
sheet1 = xlsx.sheets()[0]    # 获得第1张sheet,索引从0开始
sheet1_nrows = sheet1.nrows  # 获得行数

# 使用xlutils将xlrd读取的对象转为xlwt可操作对象,table即上述xlrd读取的table  
workbook = copy(xlsx)
# 获取一个已存在的sheet
worksheet = workbook.get_sheet('Sheet')

for i in range(sheet1_nrows):  # 逐行打印sheet1数据
    print(sheet1.row(i)[1])
    # 写入一个值,括号内分别为行数、第9列数、内容
    worksheet.write(i, 9,"我是写入内容")

workbook.save('weekshare.xlsx')

原文地址:
https://segmentfault.com/a/1190000039060376


s8fh26h3
18 声望1 粉丝