|
首先看B战下载的视频,会介绍整个过程,5分钟视频简短明了
下面开始上代码:
首先会用到三个库,一个标准库csv,两个第三方库docx-mailmerge和lxml
- import csv
- from mailmerge import MailMerge
- with open('F:\邮件合并\\001.csv') as f:
- reader = csv.reader(f)
- next(reader) #跳过首行字段行
- for name,xingbie,tel,anjianname,cname,ctel in reader:
- doc = MailMerge('F:\邮件合并\\模板.docx')
- doc.merge(name=name,xingbie=xingbie,tel=tel,anjianname=anjianname,cname=cname,ctel=ctel)
- doc.write(f'F:\邮件合并\\{name}.docx')
复制代码
|
|