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')
项目计划批量生成
最新推荐文章于 2024-11-02 16:28:26 发布