"""
刺点
"""
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
jpgPath1 = filedialog.askopenfilenames( title="选择照片文件")
jpgPath2 = filedialog.askopenfilenames( title="选择照片文件")
jpgPath3 = 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) #行数据
dianhao = str(val[0]) #编号
cidianzhe = val[1] #刺点者
jianchazhe = val[2] #检查者
coordX = str(val[3]) # X
coordY = str(val[4]) # Y
coordZ = str(val[5]) # Z
beizhu = [x for x in val[6:] if x != ''] # 备注
w = win32com.client.Dispatch("Word.Application")
document = Document(docxPath) # 打开文档
tabs = document.tables # 表
table = tabs[0] # 表0
table.cell(0, 2).text = "" # 表格1行0列
run2 = table.cell(0, 2).paragraphs[0].add_run(dianhao)
run2.font.name = "仿宋_GB2312"
run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
run2.font.size = Pt(11) # 设置字体和大小
table.cell(0, 2).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER
table.cell(1, 2).text = ""
run2 = table.cell(1, 2).paragraphs[0].add_run(cidianzhe)
run2.font.name = "仿宋_GB2312"
run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
run2.font.size = Pt(11) # 设置字体和大小
table.cell(1,2).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER
table.cell(1, 4).text = ""
run2 = table.cell(1, 4).paragraphs[0].add_run(jianchazhe)
run2.font.name = "仿宋_GB2312"
run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
run2.font.size = Pt(11) # 设置字体和大小
table.cell(1, 4).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER
table.cell(3, 3).text = ""
run2 = table.cell(3, 3).paragraphs[0].add_run(coordX)
run2.font.name = "仿宋_GB2312"
run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
run2.font.size = Pt(11) # 设置字体和大小
table.cell(3, 3).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER
table.cell(3, 4).text = ""
run2 = table.cell(3, 4).paragraphs[0].add_run(coordY)
run2.font.name = "仿宋_GB2312"
run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
run2.font.size = Pt(11) # 设置字体和大小
table.cell(3, 4).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER
table.cell(3, 6).text = ""
run2 = table.cell(3,6).paragraphs[0].add_run(coordZ)
run2.font.name = "仿宋_GB2312"
run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
run2.font.size = Pt(11) # 设置字体和大小
table.cell(3, 6).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER
table.cell(6, 2).text = ""
run2 = table.cell(6, 2).paragraphs[0].add_run(beizhu)
run2.font.name = "仿宋_GB2312"
run2._element.rPr.rFonts.set(qn('w:eastAsia'), u'仿宋_GB2312')
run2.font.size = Pt(11) # 设置字体和大小
table.cell(6, 2).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER
for name in jpgPath1:
gailuedianweitu = name.split("/")[-1][:-6]
if gailuedianweitu == dianhao:
run = table.cell(4, 1).paragraphs[0].add_run()
picture = run.add_picture(name)
picture.height = shared.Cm(12.51)
picture.width = shared.Cm(7.5)
for name2 in jpgPath2:
gailuedianweitu = name2.split("/")[-1][:-6]
if gailuedianweitu == dianhao:
run = table.cell(4, 4).paragraphs[0].add_run()
picture = run.add_picture(name2)
picture.height = shared.Cm(5.99)
picture.width = shared.Cm(6.5)
for name3 in jpgPath3:
gailuedianweitu = name3.split("/")[-1][:-4]
if gailuedianweitu == dianhao:
run = table.cell(5, 4).paragraphs[0].add_run()
picture = run.add_picture(name3)
picture.height = shared.Cm(5.99)
picture.width = shared.Cm(6.5)
savePath = r"C:\Users\Administrator\Desktop\材料" + "\\" + str(dianhao) + ".docx"
document.save(savePath)
数字刺点片批量生成
最新推荐文章于 2024-07-03 14:02:45 发布