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()
=====
import pymysql
import os
import docx
conn = pymysql.connect(host='127.0.0.1', user='root', passwd="root", db='fysc')
curCity = conn.cursor()
doc = docx.Document('县级防御图手册模板20200310.docx')
# 445100000000000 广东省潮州市 2 4
# 445122000000000 广东省潮州市饶平县 3 6
# 445122102000000 广东省潮州市饶平县上饶镇 4 9
# ('440500000000000', '汕头市', '汕头市', 2, '440000000000000', '0', '', 0)
# 1、先查找出所有市
curCity.execute("SELECT * FROM sys_dscdnm_c where DSLEVEL=2 and DSNM in ('河源市','梅州市','清远市','韶关市','云浮市')")
for r in curCity:
os.mkdir('%s'%(r[1]))
curTown = conn.cursor()
curTown.execute("SELECT * FROM sys_dscdnm_c where DSLEVEL=3 and DSUPCD = "+r[0])
for t in curTown:
# 创建文件夹
os.mkdir('%s/%s'%(r[1],t[1]))
# 获取当前区域编码 截取长度
areaCode = t[0][0:6] + '%'
# 桥梁信息遍历
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 y in curCity:
for x in range(0, 9):
if x == 0:
doc.tables[11].rows[line].cells[x].text = str(line)
elif y[x] == None:
doc.tables[11].rows[line].cells[x].text = ''
else:
doc.tables[11].rows[line].cells[x].text = y[x]
line = line + 1
doc.tables[11].add_row()
curTown.close()
curCity.close()
doc.save('%s/%s/%s防御手册.docx'%(r[1],t[1],t[2]))
conn.close()
import pymysql
import os
import docx
conn = pymysql.connect(host='127.0.0.1', user='root', passwd="root", db='fysc')
curCity = conn.cursor()
doc = docx.Document('县级防御图手册模板20200310.docx')
# 445100000000000 广东省潮州市 2 4
# 445122000000000 广东省潮州市饶平县 3 6
# 445122102000000 广东省潮州市饶平县上饶镇 4 9
# ('440500000000000', '汕头市', '汕头市', 2, '440000000000000', '0', '', 0)
# 1、先查找出所有市
curCity.execute("SELECT * FROM sys_dscdnm_c where DSLEVEL=2 and DSNM in ('河源市','梅州市','清远市','韶关市','云浮市')")
for r in curCity:
os.mkdir('%s'%(r[1]))
curTown = conn.cursor()
curTown.execute("SELECT * FROM sys_dscdnm_c where DSLEVEL=3 and DSUPCD = "+r[0])
for t in curTown:
os.mkdir('%s/%s' % (r[1], t[1]))
areaCode = t[0][0:6] + '%'
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 y in curCity:
for x in range(0, 9):
if x == 0:
doc.tables[11].rows[line].cells[x].text = str(line)
elif y[x] == None:
doc.tables[11].rows[line].cells[x].text = ''
else:
doc.tables[11].rows[line].cells[x].text = y[x]
line = line + 1
doc.tables[11].add_row()
doc.save('%s/%s/%s防御手册.docx' % (r[1], t[1], t[2]))
curCity.close()
conn.close()