From 16a4f106351ad0e2db9a60b794fe2496d2689152 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Thu, 27 Jul 2023 20:26:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7v2=E4=B8=AD=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=89=AA=E8=B4=B4=E6=9D=BF=E7=94=9F=E6=88=90=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=B9=B6=E5=8A=A0=E5=85=A5=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/剪贴板生成表格.py | 30 ++++++++++++++++++++++++++++++ 工具v2/工具面板.py | 1 + 2 files changed, 31 insertions(+) create mode 100644 工具v2/剪贴板生成表格.py diff --git a/工具v2/剪贴板生成表格.py b/工具v2/剪贴板生成表格.py new file mode 100644 index 00000000..08f9c12e --- /dev/null +++ b/工具v2/剪贴板生成表格.py @@ -0,0 +1,30 @@ +outputfilepath = "临时文件/tabular.txt" + +from database_tools import * + +data = getCopy().strip().split("\n") + +validflag = False +if "col" in data[0]: + cols = int("".join(re.findall(r"\d",data[0]))) + data = data[1:] + validflag = True +elif "col" in data[-1]: + cols = int("".join(re.findall(r"\d",data[-1]))) + data = data[:-1] + validflag = True +else: + print("未设置列数(在首行或末行, 格式: '数字 cols'), 请重试") #分离列数cols与数据data + +rows = [data[i:i+cols] for i in range(0,len(data),cols)] +for t in range(cols-len(rows[-1])): + rows[-1].append("") + +output = "\\begin{center}\n\\begin{tabular}{%s}\n\\hline\n"%("|c"*cols +"|") +output += "\\\\ \\hline\n".join([" & ".join(row) for row in rows]) +output += "\\\\ \\hline\n" +output += "\\end{tabular}\n\\end{center}" + +setCopy(output) +SaveTextFile(output,outputfilepath) + diff --git a/工具v2/工具面板.py b/工具v2/工具面板.py index 379c01c3..26672fbd 100644 --- a/工具v2/工具面板.py +++ b/工具v2/工具面板.py @@ -155,6 +155,7 @@ OtherMenu = Menu(menubar, tearoff = False) menubar.add_cascade(label = "其他", menu = OtherMenu) OtherMenu.add_command(label = "mathpix识别文本预处理", command = lambda: SetButton("mathpix识别文本预处理",[])) OtherMenu.add_command(label = "修改为带圈数字", command = lambda: SetButton("修改为带圈数字",[])) +OtherMenu.add_command(label = "剪贴板生成表格", command = lambda: SetButton("剪贴板生成表格",[])) # OtherMenu.add_command(label = "剪贴板带圈数字处理", command = lambda: SetButton("带圈数字处理",1,[])) # OtherMenu.add_command(label = "剪贴板表格整理", command = lambda: SetButton("剪贴板表格整理",1,[])) # OtherMenu.add_command(label = "剪贴板单选变多选", command = lambda: SetButton("剪贴板单选变多选",1,[]))