破解资源 发布日期:2024/12/30 浏览次数:1
image.png
import osimport reimport docximport openpyxlfrom 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()