WSL doc2docx 并进行替换
import os import subprocess import tempfile import shutil from docx import Document from doc2docx import convert # 定义替换对照表 REPLACEMENT_DICT = { '陕西省' : '甘肃省' , '西安' : '兰州' , '咸阳' : '天水' , 'SXCDCSOP' : 'GSCDCSOP' , } def convert_doc_to_docx ( doc_path ): """使用 Windows PowerShell 调用 Word 来转换文件,并在转换成功后删除原doc文件""" try : # 将 Linux 路径转换为 Windows 路径 win_path = subprocess.check_output([ 'wslpath' , '-w' , doc_path]).decode().strip() docx_path = os.path.splitext(doc_path)[ 0 ] + ".docx" win_docx_path = subprocess.check_output([ 'wslpath' , '-w' , docx_path]).decode().strip() # 检查目标文件是否已存在 if os.path.exists(docx_path): print ( f "目标文件已存在: { docx_path } " ) ...