抖音自动生成文字_审计自动化8向word模板批量填入文字数据并生成多个word文件...

代码如下:

类似于邮件合并

from docx import Documentfrom docx.shared import Cmfrom docx.enum.text import WD_ALIGN_PARAGRAPHimport reimport pandas as pdimport osfrom docx.enum.style import WD_STYLE_TYPEfrom docx import Documentfrom docx.shared import Cm,Pt,RGBColorfrom docx.enum.table import WD_TABLE_ALIGNMENTfrom docx.enum.table import WD_ALIGN_VERTICALfrom docx.enum.text import WD_ALIGN_PARAGRAPHdocument=Document(r"./供应商访谈提纲-sent.docx")# 首先对段落格式进行修改,docx默认标题也属于段落paragraphs=document.paragraphs# paragraphs[2].paragraph_format.first_line_indent=Cm(0.74)# paragraphs[3].paragraph_format.left_indent=Cm(0.74)# paragraphs[4].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT# paragraphs[4].paragraph_format.right_indent=Cm(2)# paragraphs[5].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT# paragraphs[5].paragraph_format.right_indent=Cm(2)# 对文本进行修改# 修改第二段# paragraphs[1].text="小Z同学:"# 将第三段陆亦可替换为大Z,她替换为他。通过python的正则表达式,可以很简单地实现文本的替换和查找。# text=re.sub('陆亦可','大Z',paragraphs[2].text)# text=re.sub('受访公司名称填写处','受访公司名称填写处chu',text)# paragraphs[2].text=text# 在第四段后面加上# paragraphs[3].add_run("向小z同学学习!")# 修改表格里面的内容excel_path = r"供应商走访数据.xlsx"f1=pd.read_excel(excel_path,converters = {'供应商':str})# f2=pd.read_excel(excel_path,converters = {'2018年金额':str})# f3=pd.read_excel(excel_path,converters = {'2019年金额':str})# f4=pd.read_excel(excel_path,converters = {'2018年不含税采购额':str})# f5=pd.read_excel(excel_path,converters = {'2019年不含税采购额':str})# f6=pd.read_excel(excel_path,converters = {'2018/12/31应付余额-已开票':str})# f7=pd.read_excel(excel_path,converters = {'2018/12/31应付余额-未开票':str})# f8=pd.read_excel(excel_path,converters = {'2018/12/31应付余额-总':str})# f9=pd.read_excel(excel_path,converters = {'2018/12/31预付余额':str})# f10=pd.read_excel(excel_path,converters = {'2019/12/31应付余额-已开票':str})# f11=pd.read_excel(excel_path,converters = {'2019/12/31应付余额-未开票':str})# f12=pd.read_excel(excel_path,converters = {'2019/12/31应付余额-总':str})# f13=pd.read_excel(excel_path,converters = {'2019/12/31预付余额':str})tables=document.tables# print(tables)# print(f1.iloc[0,0])for i in range(len(f1)):  tables[0].cell(0,1).text=str(f1.iloc[i,0])#填写公司名称  tables[3].cell(1,1).text=str(f1.iloc[i,1])#以下为填写数据  tables[3].cell(1,2).text=str(f1.iloc[i,3])  tables[3].cell(2,1).text=str(f1.iloc[i,2])  tables[3].cell(2,2).text=str(f1.iloc[i,4])  tables[4].cell(1,1).text=str(f1.iloc[i,5])  tables[4].cell(2,1).text=str(f1.iloc[i,6])  tables[4].cell(3,1).text=str(f1.iloc[i,7])  tables[4].cell(4,1).text=str(f1.iloc[i,8])  tables[4].cell(1,2).text=str(f1.iloc[i,9])  tables[4].cell(2,2).text=str(f1.iloc[i,10])  tables[4].cell(3,2).text=str(f1.iloc[i,11])  tables[4].cell(4,2).text=str(f1.iloc[i,12])      #以下是调整表格中指定单元格的数字格式为靠右垂直居中  tables[3].cell(1,1).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[3].cell(1,2).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[3].cell(2,1).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[3].cell(2,2).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[3].cell(1,1).vertical_alignment = WD_ALIGN_VERTICAL.CENTER  tables[3].cell(1,2).vertical_alignment = WD_ALIGN_VERTICAL.CENTER  tables[3].cell(2,1).vertical_alignment = WD_ALIGN_VERTICAL.CENTER  tables[3].cell(2,2).vertical_alignment = WD_ALIGN_VERTICAL.CENTER  tables[4].cell(1,1).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[4].cell(2,1).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[4].cell(3,1).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[4].cell(4,1).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[4].cell(1,2).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[4].cell(2,2).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[4].cell(3,2).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[4].cell(4,2).paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.RIGHT  tables[4].cell(1,1).vertical_alignment = WD_ALIGN_VERTICAL.CENTER  tables[4].cell(2,1).vertical_alignment = WD_ALIGN_VERTICAL.CENTER  tables[4].cell(3,1).vertical_alignment = WD_ALIGN_VERTICAL.CENTER  tables[4].cell(4,1).vertical_alignment = WD_ALIGN_VERTICAL.CENTER  tables[4].cell(1,2).vertical_alignment = WD_ALIGN_VERTICAL.CENTER  tables[4].cell(2,2).vertical_alignment = WD_ALIGN_VERTICAL.CENTER  tables[4].cell(3,2).vertical_alignment = WD_ALIGN_VERTICAL.CENTER  tables[4].cell(4,2).vertical_alignment = WD_ALIGN_VERTICAL.CENTER# tables[0].cell(2,0).text="猫粮"# tables[0].cell(3,0).text="猫粮"# 插入一张图片,图片宽度设置为11.8cm  document.save(str(i+1)+str(f1.iloc[i,0])+".doc")#以公司名称保存为doc  

最终数据要呈现出千分位的会计格式可以参考以下指南df2c9a78b7e292aa192a79520358391b.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值