又到了一年一度的背题时刻,但是收到的题库是Word版的,页数特别多
利于看,也不利于背,以前都是手动去把Word版转Excle版,但是通常挺费时的,问题还多。这次就想偷懒,祭出Python
# 导入所需库
import csv
import os
import re
from docx import Document
from win32com import client as wc
# 打开word文档
def doc_to_docx(doc_file):
full_path = os.path.abspath(doc_file) # 绝对路径,便于分离文件位置、名和后缀
word = wc.Dispatch("Word.Application")
doc = word.Documents.Open(full_path)
doc.SaveAs(os.path.splitext(full_path)[0] + '.docx', 12) # 保存只改后缀 12 为docx
doc.Close()
word.Quit()
return os.path.splitext(full_path)[0] + '.docx'
def