乱占耕地图斑举证

"""
表格对比
"""
# import xlrd
# import xlwt
# from xlutils.copy import copy
# meagerPath = r"C:\Users\Administrator\Desktop\汇总表格.xls"
# fenPath = r"C:\Users\Administrator\Desktop\调查表格.xls"
#
# wbMeager = xlrd.open_workbook(meagerPath) #汇总表格
# oldWs = wbMeager.sheet_by_index(0)
#
# newWb = copy(wbMeager)
# ws = newWb.get_sheet(0)
#
# #
#
# wbFen = xlrd.open_workbook(fenPath) #调查表格
# wsf = wbFen.sheet_by_index(0)
#
# for row in range(1,oldWs.nrows):
#     listRow = oldWs.row_values(row)
#     pici = listRow[4]
#     count = len(listRow)-4
#
#     for rof in range(1,wsf.nrows):
#         listFRow = wsf.row_values(rof)
#         fpici = listFRow[1]
#
#         if pici == fpici:
#             n =5
#             for r in listFRow[6:]:
#                 ws.write(row,n,r)
#                 n+=1
#             # print(listFRow)
#             # ws2.write()
# newWb.save(r"C:\Users\Administrator\Desktop\汇总表格2.xls")

"""
举证
"""
import tkinter
from tkinter import filedialog,messagebox
import xlrd
from docx import Document
from docx.enum.table import WD_TABLE_ALIGNMENT
from docx.shared import Pt
from docx.oxml.ns import qn
from  docx import shared
jpgPath = filedialog.askopenfilenames( title="选择照片文件")
import win32com.client
# docxPath = filedialog.askopenfilename(filetypes=[("docx", "docx")], title="选择docx文件")
# xlsPath = filedialog.askopenfilename(filetypes=[("xls", "xls")], title="选择xls文件")
docxPath = r"C:\Users\Administrator\Desktop\模板.docx"
xlsPath = r"C:\Users\Administrator\Desktop\瓶窑图斑表格.xls"

wb = xlrd.open_workbook(xlsPath)
ws = wb.sheet_by_index(0)

print(ws.nrows)
n= 0
for row in range(1,ws.nrows):

    val = ws.row_values(row) #行数据

    num = val[3] #编号
    villageName = val[1] #村名
    townName = val[0] #镇名
    pici = val[4]
    whether = val[5] # 是否上报
    reason = val[8] # 不上报原因
    jpgName = [x for x in val[9:] if x != ''] # 举证照片名称

    w = win32com.client.Dispatch("Word.Application")
    document = Document(docxPath)  # 打开文档
    tabs = document.tables  # 表
    table = tabs[0]  # 表0

    table.cell(2, 0).text = ""  # 表格1行0列
    run2 = table.cell(2, 0).paragraphs[0].add_run(num)
    run2.font.name = "仿宋_GB2312"
    run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
    run2.font.size = Pt(11)  # 设置字体和大小
    table.cell(2, 0).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER


    table.cell(2, 1).text = ""

    run2 = table.cell(2, 1).paragraphs[0].add_run(pici[0:3])
    run2.font.name = "仿宋_GB2312"
    run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
    run2.font.size = Pt(11)  # 设置字体和大小
    table.cell(2, 1).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER


    table.cell(2, 3).text = ""
    run2 = table.cell(2, 3).paragraphs[0].add_run(villageName)
    run2.font.name = "仿宋_GB2312"
    run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
    run2.font.size = Pt(11)  # 设置字体和大小
    table.cell(2, 3).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER

    table.cell(3, 2).text = ""
    run2 = table.cell(3, 2).paragraphs[0].add_run(reason)
    run2.font.name = "仿宋_GB2312"
    run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
    run2.font.size = Pt(11)  # 设置字体和大小
    table.cell(3, 2).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER
    n = 0
    if "2013年1月1日以前" not in reason:
        jpgName.pop(1)
    for name in jpgName:
        bnpath = "F:/调查照片/zp/" + name
        fn = name.split(".")[0]  # xls 内照片名称
        for path in jpgPath:
            bn = path.split("/")[-1].split(".")[0] #路径 照片名称

            if bn == fn:
                run = table.cell(4, 0).paragraphs[0].add_run()
                picture = run.add_picture(bnpath)
                picture.height = shared.Cm(15)
                picture.width = shared.Cm(14)


                if "2013年1月1日以前" in reason:
                    n+=1
                    if n == 1 :
                        run2 = table.cell(4, 0).paragraphs[0].add_run("\n2020年影像")
                        run2.font.name = "仿宋_GB2312"
                        run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
                        run2.font.size = Pt(11)  # 设置字体和大小
                        table.cell(4, 0).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER
                    if n ==2 :
                        run2 = table.cell(4, 0).paragraphs[0].add_run("\n2013年1月1日以前影像")
                        run2.font.name = "仿宋_GB2312"
                        run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
                        run2.font.size = Pt(11)  # 设置字体和大小
                        table.cell(4, 0).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER
                if "2013年1月1日以前" not in reason:
                    n += 1
                    if n == 1:
                        run2 = table.cell(4, 0).paragraphs[0].add_run("\n2020年影像")
                        run2.font.name = "仿宋_GB2312"
                        run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
                        run2.font.size = Pt(11)  # 设置字体和大小
                        table.cell(4, 0).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER

    savePath = r"C:\Users\Administrator\Desktop\举证材料" + "\\" + str(pici) + ".docx"
    if whether == "不上报":
        document.save(savePath)
    else:
        pass



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值