python doc另存为docx

复制代码
from docx import Document
#from docx.shared import Inches
from win32com import client as wc #导入模块
file = 'C:\\Users\\Administrator\\Desktop\\999999.doc'
word = wc.Dispatch("Word.Application") # 打开word应用程序
doc = word.Documents.Open(file) #打开word文件
doc.SaveAs("{}x".format(file), 12)#另存为后缀为".docx"的文件,其中参数12指docx文件
doc.Close() #关闭原来word文件
word.Quit()
file_new = file+'x'
document = Document(file_new)  #打开文件demo.docx
text = ''
for paragraph in document.paragraphs:
    text += paragraph.text  #打印各段落内容文本
print(text)
复制代码

 

作者:itbaby

出处:https://www.cnblogs.com/itbaby/p/14198037.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   知风阁  阅读(1645)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2018-12-27 json_decode转换数组过程中,结果为null处理办法,百分之百有效
more_horiz
keyboard_arrow_up light_mode palette
选择主题
点击右上角即可分享
微信分享提示