pypiwin32

pypiwin32#

自动化操作 office 软件:

from pathlib import Path
import win32api
from win32com.client import Dispatch # 需要安装的是pypiwin32模块


root = Path("文件目录").resolve()
for file in root.iterdir():
    if file.is_file():
        print(file)
        if file.suffix == ".docx":
            win32api.ShellExecute(0, "open", str(file), '', '', 1)
        elif file.suffix == ".xlsx":
            win32api.ShellExecute(0, "open", str(file), '', '', 1)
        else:
            raise "暂未支持!"