项目计划批量生成


import numpy as np
import pandas as pd
import math

from docxtpl import DocxTemplate
col_order=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ','BA','BB','BC','BD','BE']

df = pd.read_excel(r'C:\Users\caoming\Desktop\20200914数据处理\项目计划.xlsx', sheet_name='市场项目-变更后')
print (df.shape)
lines = df.shape[0]
print ('lines = ' + str(lines))
print(df.iloc[0][0])
for i in range(0,lines):
    doc_dic={}
    doc = DocxTemplate(r'C:\Users\caoming\Desktop\20200914数据处理\项目计划.docx')
    cols=df.iloc[i]
    len_cols = len(df.iloc[i])
    j = 0
    for j in range(0,len_cols):
        if isinstance(cols[j],pd._libs.tslibs.timestamps.Timestamp):
            doc_dic[col_order[j]]=str(cols[j]).split()[0]
        elif isinstance(cols[j], np.int64):
            doc_dic[col_order[j]]=cols[j]
        elif isinstance(cols[j], float) and math.isnan( cols[j]):
            doc_dic[col_order[j]]=""
        elif isinstance(cols[j], np.float64) and np.isnan(cols[j]):
            
            doc_dic[col_order[j]]=""
        else:
            doc_dic[col_order[j]]=cols[j]

    doc_dic['tbl_contents']=[]
    xuhaos= cols[3].split('\n')
    jiaofuwus = cols[4].split('\n')
    chengdanrens=cols[5].split('\n')
    starttimes=cols[6].split('\n')
    endtimes=cols[7].split('\n')
    gongshis=cols[8].split('\n')
    print(jiaofuwus)
    print(chengdanrens)
    print(starttimes)
    print(endtimes)
    print(gongshis)

    for xuhao,jiaofuwu,chengdanren,starttime,endtime,gongshi in zip(xuhaos,jiaofuwus,chengdanrens,starttimes,endtimes,gongshis):
        print(jiaofuwu)
        print(chengdanren)
        print(starttime)
        print(endtime)
        print(gongshi)


        row={}
        row['xuhao'] = str(xuhao)
        row['label']=jiaofuwu
        row['chengdanren']=chengdanren
        row['starttime']=str(starttime)
        row['endtime']=str(endtime)
        row['gongshi']=str(gongshi)
        doc_dic['tbl_contents'].append(row)



    print(doc_dic)
    doc.render(doc_dic)
    doc.save('C:\\Users\\caoming\\Desktop\\20200914数据处理\\新建文件夹\\' + str(cols[9])+ '-变更-项目计划-' + cols[0].replace('\n', '') + '.docx')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值