惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
U
Unit 42
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
Microsoft Azure Blog
Microsoft Azure Blog
有赞技术团队
有赞技术团队
Stack Overflow Blog
Stack Overflow Blog
爱范儿
爱范儿
博客园 - 司徒正美
Vercel News
Vercel News
I
InfoQ
GbyAI
GbyAI
C
Check Point Blog
B
Blog RSS Feed
Martin Fowler
Martin Fowler
B
Blog
MyScale Blog
MyScale Blog
腾讯CDC
博客园 - Franky
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 三生石上(FineUI控件)

Dr34m's Blog

I Expect You To Die(我希望你死) 1,2,3 完整中文攻略 Linux换国内源 && docker安装 && 换加速镜像 Vue3 + Element-Plus 极简速查 随笔 pyinstaller打包的程序执行报错Failed to extract xxxx decompression resulted in return code -1 taoSync排除项简易教程 apscheduler的cron配置项 如何在绿联NAS中使用TaoSync同步我的文件到各个网盘 GB28181抓包记录 JS计算字节大小,把字节转换为KB/MB/GB/TB等 在Python中使用onvif管理摄像头,包括设备发现,获取RTSP地址,获取设备信息,截图,云台控制与缩放,设置时间 编写bat脚本实现对vue项目构建并压缩 内网穿透工具frp快速使用 CentOS 7.9 安装基础开发环境jdk redis nacos nginx mysql Pyinstaller 逆向 VUE实现复制与粘贴_获取剪切板内容 Electron + xterm.js + node-pty + vue 实现本地终端 child_process exec 中文乱码 Windows&Linux 解决方法 yum 更新 gcc CentOS安装并使用conda 将fluid主题博客的静态资源由第三方改为本地存储 一个上手即用的通用公众号/小程序/h5/app框架 SpringBoot单元测试注入空指针 TensorFlow 预测出现NaN的一种可能以及解决方法 随笔 python归一化数据 windows下python安装sasl遇到的问题及解决 将对象List中的某个字段放到新的List中[转载] Python http.server 本地服务支持跨域 TensorFlow入门
python批量转化doc到docx
Dr3@m · 2022-05-19 · via Dr34m's Blog

目标

通过python批量转换doc文档为docx文档

实现

一、代码

windows下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import os
from win32com import client as wc
word = wc.Dispatch("Word.Application")
path = os.getcwd()
for file in os.listdir(path):
if file.endswith(".doc"):
try:
file_path = path + '\\' + file
doc = word.Documents.Open(file_path)
doc.SaveAs("{}x".format(file_path), 12)
print("成功: " + file + " -> " + file + "x")
except Exception as e:
print("失败: " + file + " -> " + file + "x")
finally:
doc.Close()
word.Quit()
input("输入回车结束...")

Linux下(未经测试,失败烦请告知)

1
2
3
4
5
6
7
8
9
10
11
12
import os
import subprocess
path = os.getcwd()
for file in os.listdir(path):
if file.endswith(".doc"):
try:
file_path = path + '/' + file
subprocess.check_output(["soffice","--headless","--invisible","--convert-to","docx",file_path,"--outdir",path + '/'])
print("成功: " + file + " -> " + file + "x")
except Exception as e:
print("失败: " + file + " -> " + file + "x")
input("输入回车结束...")

二、使用

将以上内容写入main.py移动到需要转换的文档目录,运行python main.py,即可将当前目录下所有doc文件转docx