image.png (16.78 KB, 下载次数: 0)
下载附件
2023-3-26 19:51 上传
[Asm] 纯文本查看 复制代码import os
import re
import docx
import openpyxl
from tkinter import Tk, Label, Button, filedialog
# 定义表格数据提取函数
def extract_table_data(doc_path, sheet):
doc = docx.Document(doc_path)
for table in doc.tables:
for i, row in enumerate(table.rows):
for j, cell in enumerate(row.cells):
text = re.sub('\s+', ' ', cell.text)
sheet.cell(row=i+1, column=j+1, value=text)
# 创建GUI窗口
root = Tk()
root.title("Word表格批量数据提取到excel by AK黑龙 ")
root.geometry("360x240")
# 创建标签和按钮控件
label = Label(root, text="请选择要处理的Word文件所在文件夹")
label.pack(pady=20)
def select_folder():
folder_path = filedialog.askdirectory()
if folder_path:
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "assion"
for file_name in os.listdir(folder_path):
if file_name.endswith(".docx"):
doc_path = os.path.join(folder_path, file_name)
extract_table_data(doc_path, ws)
wb.save("AK黑龙2495003337.xlsx")
label.config(text="处理完成!")
button = Button(root, text="选择文件夹", command=select_folder)
button.pack(pady=20)
root.mainloop()
不会运行的 直接下载运行 https://download.csdn.net/download/longyifei12345/87614872