代码前段时间可以使用,无任何报错,最近在pycharm运行后出现Can't find filter element,但是却可以正常运行
python版本:3.8.5
import xlrd
import os
import tkinter as tk
import ttkbootstrap as ttk
from docx import *
from tkinter import filedialog
from docx.shared import Pt, Inches
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from ttkbootstrap import Style
from ttkbootstrap.constants import *
class MainPage:
def __init__(self, master):
self.root = master
self.root.title("批量制作操作卡v1.4")
self.root.minsize(400, 170)
self.root.maxsize(400, 170)
sw = self.root.winfo_screenwidth()
sh = self.root.winfo_screenheight()
ww = 400
wh = 170
x = (sw - ww) / 2
y = (sh - wh) / 2
self.root.geometry("%dx%d+%d+%d" % (ww, wh, x, y))
style = Style(theme='litera')
self.root = style.master
def selectdocument():
global savepath
savepath = filedialog.askdirectory()
savename.set(savepath)
def selectdocx():
global filepath
filepath = filedialog.askopenfilename(filetypes=[('docx', '*.docx')])
filename.set(filepath)
def selectxls():
global filepath1
filepath1 = filedialog.askopenfilename(filetypes=[('xls', '*.xls')])
filename1.set(filepath1)
filename = tk.StringVar()
filename1 = tk.StringVar()
savename = tk.StringVar()
def change_data(文件编号, 货号, 品名, 工段, 正文, 质量标准, 类别, 步骤, 包装规格, 编织袋, 收率):
文件编号 = str(文件编号)
货号 = str(货号)
品名 = str(品名)
工段 = str(工段)
正文 = str(正文)
质量标准 = str(质量标准)
类别 = str(类别)
步骤 = str(步骤)
包装规格 = str(包装规格)
编织袋 = str(编织袋)
收率 = str(收率)
document = Document(filepath)
for i in document.paragraphs:
i.text = i.text.replace('***', 工段)
i.text = i.text.replace('&&&', 正文)
i.text = i.text.replace('¥¥¥', 质量标准)
i.text = i.text.replace('#', 步骤)
i.text = i.text.replace('&-&-&', 包装规格)
i.text = i.text.replace('*-*-*', 编织袋)
i.text = i.text.replace('¥-¥-¥', 收率)
i.paragraph_format.line_spacing = 1.25
i.paragraph_format.left_indent = Inches(0.15)
document.styles['Normal'].font.name = u'宋体'
head = document.sections[0].header
for b in head.paragraphs:
b.text = b.text.replace('@', 品名)
b.text = b.text.replace('=', 货号)
for q in b.runs:
q.font.size = Pt(12)
q.font.bold = True
w = head.paragraphs[0].add_run(' 公 司')
w.font.bold = True
w.font.size = Pt(14)
e = head.paragraphs[1].add_run(' 操 作 卡')
e.font.bold = True
e.font.size = Pt(22)
head.paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
head.paragraphs[1].alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
head.paragraphs[2].alignment = WD_PARAGRAPH_ALIGNMENT.DISTRIBUTE
foot = document.sections[0].footer
k = foot.paragraphs[0].add_run(文件编号)
k.font.size = Pt(8)
foot.paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
rename = 类别 + 品名 + 工段 + '#' + 步骤 + '.docx'
path = os.path.join(savepath, rename)
document.save(path)
def savexls():
excel = xlrd.open_workbook(filepath1)
table = excel.sheet_by_index(0)
nows = table.nrows
for i in range(1, nows):
文件编号 = table.cell(i, 0).value
货号 = table.cell(i, 1).value
品名 = table.cell(i, 2).value
工段 = table.cell(i, 3).value
正文 = table.cell(i, 4).value
质量标准 = table.cell(i, 5).value
类别 = table.cell(i, 6).value
步骤 = table.cell(i, 7).value
包装规格 = table.cell(i, 8).value
编织袋 = table.cell(i, 9).value
收率 = table.cell(i, 10).value
change_data(文件编号, 货号, 品名, 工段, 正文, 质量标准, 类别, 步骤, 包装规格, 编织袋, 收率)
tk.Label(self.root, text='word(.docx)').grid(row=1, column=0, padx=5, pady=5, sticky=W)
tk.Label(self.root, text='excel(.xls)').grid(row=2, column=0, padx=5, pady=5, sticky=W)
tk.Label(self.root, text='select document').grid(row=3, column=0, padx=5, pady=5, sticky=W)
tk.Entry(self.root, textvariable=filename, width=30).grid(row=1, column=1, padx=5, pady=5)
tk.Entry(self.root, textvariable=filename1, width=30).grid(row=2, column=1, padx=5, pady=5)
tk.Entry(self.root, textvariable=savename, width=30).grid(row=3, column=1, padx=5, pady=5)
ttk.Button(self.root, text='打开', bootstyle=(LIGHT), command=selectdocx).grid(
row=1, column=2, padx=5, pady=5)
ttk.Button(self.root, text='打开', bootstyle=(LIGHT), command=selectxls).grid(
row=2, column=2, padx=5, pady=5)
ttk.Button(self.root, text='打开', bootstyle=(LIGHT), command=selectdocument).grid(
row=3, column=2, padx=5, pady=5)
ttk.Button(self.root, text='运行', bootstyle=(PRIMARY), command=savexls).grid(
row=4, column=1, padx=5, pady=5, sticky=E)
ttk.Button(self.root, text='退出', bootstyle=(DANGER), command=self.root.quit).grid(
row=4, column=2, padx=5, pady=5)
if __name__ == '__main__':
root = tk.Tk()
MainPage(master=root)
root.mainloop()
报错:
Can't find filter element
Can't find filter element
进程已结束,退出代码0
能用的方法都排查了,还是找不到原因
我想要达到的结果:不显示Can't find filter element
在cmd下执行正常吗?
先把详细的报错信息贴一下
有没有更新过或者操作过什么,从提示上是找不到filter element,或者将完整提示的报错贴一下