import docx
import pymysql
from docx.shared import Cm, Inches,Pt
from docx.enum.table import WD_TABLE_ALIGNMENT
conn = pymysql.connect(host='127.0.0.1', user='root', passwd="root", db='fysc')
curCity = conn.cursor()
doc = docx.Document('县级防御图手册模板20200310.docx')
areaCode = '441625%';
# 设置表头
# ptitle = doc.paragraphs[5].text
# doc.paragraphs[5].text = ''
# run = doc.paragraphs[5].add_run(ptitle.replace('{{area_name}}', '河源县'))
# run.bold = True
# run.font.size = Pt(30)
# for j in range(0, len(doc.tables)):
# if doc.tables[j].rows[0].cells.has_key(2):
# print(doc.tables[j].rows[0].cells[2].text)
# - 桥梁 bridge_info 11
# - 水雨情监测站 video_monitor_station monitor_station_info 12
# - 山洪预警设施 warn_equip_info 13
# - 中小河流雨洪危险区 danger_area_info 14
# - 防汛抢险物资仓库 goods_repository 15
# - 防汛抢险队伍 rescue_group_info 16
# - 应急避灾场所 avoide_disaster_point 17
# print(doc.tables[11].rows[0].cells[2].text)
# print(doc.tables[11].rows[0].cells[1].text)
# SELECT BR_NAME,DSVB,RV,BR_LEN,BR_WID,BR_HIGHT,BR_TYPE,LGTD,LTTD FROM `bridge_info` where DSCD like "441625%";
# 桥梁
curCity.execute("SELECT @i:=@i+1,BR_NAME,DSVB,RV,BR_LEN,BR_WID,BR_HIGHT,BR_TYPE,LGTD,LTTD,COMMENTS FROM `bridge_info`,(SELECT @i:=0) as b where DSCD like %s AND delflag is null",(areaCode))
line = 1
for r in curCity:
for x in range(0,9):
if x == 0:
doc.tables[11].rows[line].cells[x].text=str(line)
elif r[x] == None:
doc.tables[11].rows[line].cells[x].text=''
else:
doc.tables[11].rows[line].cells[x].text=r[x]
line = line +1
doc.tables[11].add_row()
# 防汛仓库
curCity.execute("SELECT @i:=@i+1 rownum,`NAME` mc,round(LGTD,6) jd,round(LTTD,6) wd,HEAD lxrxm,TELL lxfs,comments bz,TWN szz FROM goods_repository,(SELECT @i:=0) as b WHERE dscd LIKE %s AND delflag is null",(areaCode))
line = 2
for r in curCity:
for x in range(0,6):
if x==0:
doc.tables[15].rows[line].cells[0].text=str(line-1)
elif r[x] == None:
doc.tables[15].rows[line].cells[x].text=''
else:
doc.tables[15].rows[line].cells[x].text=str(r[x])
line = line+1
#2.防汛抢险队伍
# 名称 人数 所属部门或单位 负责人 为民间抢险队的标注“是” 备注说明
curCity.execute("SELECT @i:=@i+1 rownum, `NAME` mc,PP renshu,AD ssbm,HEAD fzrxm,TELL fzrlxfs,FOLK biaozhu,comments bz,TWN szz,round(LGTD,6) jd,round(LTTD,6) wd FROM rescue_group_info,(SELECT @i:=0) VARS WHERE dscd LIKE %s AND delflag is null",(areaCode))
line = 2
for r in curCity:
for x in range(1,7):
if r[x] == None:
doc.tables[16].rows[line].cells[x].text=''
else:
doc.tables[16].rows[line].cells[x].text=r[x]
line = line +1
doc.tables[16].add_row()
#应急避灾场所 名称 位置 占地面积(m2) 容纳人数 场所等级 备注
curCity.execute("SELECT @i:=@i+1,`NAME`,`ADD`,`AREA`,`ATCP`,`SH_GRD`,`COMMENTS` FROM `avoide_disaster_point`,(SELECT @i:=0) as b where DSCD like %s AND delflag is null",(areaCode))
line = 1
for r in curCity:
for x in range(1,6):
if r[x] == None:
doc.tables[17].rows[line].cells[x].text=''
else:
doc.tables[17].rows[line].cells[x].text=r[x]
line = line +1
doc.tables[17].add_row()
doc.save('demo6.docx')
curCity.close()
conn.close()
网友评论