批量word表格内容提取到excel
批量word表格内容提取到excel

image.png


[Asm] 纯文本查看 复制代码
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()

不会运行的 直接下载运行 https://download.csdn.net/download/longyifei12345/87614872
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!