'''使用xlutils模块在已有Excel文件内追加写功能'''
import xlrd
import xlutils.copy
import os
def write_Excel(r, c, msg):
path_=os.getcwd()
path=os.path.join(path_,"exce.xls")
# file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'test.xls'))
book = xlrd.open_workbook(path, formatting_info=True) # 读取Excel
# 复制表
copy_book = xlutils.copy.copy(book)
copy_sheet = copy_book.get_sheet(0)
# 指定单元格写入信息
copy_sheet.write(r, c, msg)
# 保存文件
copy_book.save(path)
if __name__ == '__main__':
msg = 'test'
# (2,3)为D3单元格
write_Excel(2, 3, msg)
来源:CSDN
作者:灬走走停停丶
链接:https://blog.csdn.net/qq_44667896/article/details/104776216