将使用win32com包进行处理

读取doc文件

# coding=utf-8
import os, fnmatch
from win32com import client as wc
from win32com.client import Dispatchdef word2txt(filePath, savePath = ''):dirs, filename = os.path.split(filePath)print(dirs, '\n', filename)new_name = ''if fnmatch.fnmatch(filename, "*.docx"):new_name = filename[:-5] + '.txt'if fnmatch.fnmatch(filename, "*.doc"):new_name = filename[:-4] + '.txt'if savePath == '':savePath = dirselse:savePath = savePathword2txtPath = os.path.join(savePath, new_name)print(word2txtPath)wordappp = wc.Dispatch('Word.Application')mytxt = wordappp.Documents.Open(filePath)mytxt.SaveAs(word2txtPath, 4) # 4代表抽取结果保存为文本mytxt.Close()if __name__ == '__main__':filePath = os.path.abspath(r'./专业课.docx')word2txt(filePath)

读取pdf

# coding=utf-8
import os, fnmatch
from win32com import client as wc
from win32com.client import Dispatchdef pdf2txt(filePath, savePath=''):dirs, filename = os.path.split(filePath)print(dirs, '\n', filename)new_name = ''if fnmatch.fnmatch(filename, '*.pdf') or fnmatch.fnmatch(filename, '*.PDF'):new_name = filename[:-4] + '.txt'else:print('格式不正确,仅支持pdf格式')returnif savePath == '':savePath = dirselse:savePath = savePathpdf2txtPath = os.path.join(savePath, new_name)print(pdf2txtPath)wordappp = wc.Dispatch('Word.Application')mytxt = wordappp.Documents.Open(filePath)mytxt.SaveAs(pdf2txtPath, 4)  # 4代表抽取文本mytxt.Close()if __name__ == '__main__':filePath = os.path.abspath(r'./论文.pdf')pdf2txt(filePath)

python利用win32com读取doc和pdf内容,并保存到文件相关推荐

  1. python利用win32com实现doc文档转为pdf文档的功能

    1.首先,必须去安装相关的库,使用命令:pip install pypiwin32,接下来是主要代码: import win32com.client import pythoncomclass Wor ...

  2. python 利用jieba读取txt文本进行分词后存入新txt

    python 利用jieba读取txt文本进行分词后存入新txt import jieba txt = open("news.txt",encoding='UTF-8').read ...

  3. python 利用win32com进行数据透视表绘制

    在日常处理中或许会用到数据透视表的功能,但发现对于使用win32com来做数据透视表的介绍有点少. 接下来就是介绍利用win32com进行数据表创建 这也是一个查找的资料的例子,只是稍作了修改,使得可 ...

  4. python编程获取续蜀山剑侠传:目录名称、网址、内容,保存到文件

    昨天已经用Python编程完成了 从<续蜀山剑侠传>连载网站页面上获取目录信息,包括目录名称和网址,进而读取每个网址对应的网页中连载内容,详见: python编程获取续蜀山剑侠传:从目录名 ...

  5. python中 doc_python中doc转pdf

    pip install pywin32 from win32com.client import gencache from win32com.client import constants, genc ...

  6. 解决python利用openpyxl读取excel中公式结果值的问题

    在之前的一段时间里,我一直试图让openpyxl库来读取单元格值.但是每次我运行这个程序时,如果我把它设置为data_only = True,它就会返回None.如果我不添加数据,它只返回我使用的公式 ...

  7. unity 利用iTextSharp 开发doc转换pdf文档

    1:将iTextSharp插件导入到unity->Asset文件夹下面 2:新建一个脚本,取名为ExportPDF,此脚本用于配置pdf文档的前期工作,以及用于接收其他脚本递交过来的数据 < ...

  8. python利用Excel读取和存储测试数据完成接口自动化

     http_request2.py用于发起http请求 #读取多条测试用例 #1.导入requests模块 import requests #从 class_12_19.do_excel1导入read ...

  9. Python利用Opencv读取图片

    首先,要先确认PyCharm里面有没有装opencv-python.如果没有,点右侧+号搜索添加. 确认有opencv之后,便可以使用cv2读取图片了 import cv2image_path = & ...

最新文章

  1. java的自动装箱和拆箱,Java中的自动装箱和拆箱是什么?
  2. 【转】mysql-status和variables区别
  3. linux_redhat_线程后台运行方法
  4. Python解释器工作原理与jit技术
  5. BroadcastReceiver 广播机制详解
  6. 大二下学期学习进度(四)
  7. devops基础扫盲篇_在2020年取得成功的8篇必读的DevOps文章
  8. Python05 梯形公式 Simpson公式 Cotes公式 Romber公式(附代码)
  9. 30岁女子跟程序员相亲,结果见面后秒拒:秃顶工资再多也不要
  10. 此处不允许使用分组函数_查找当前薪水排名第二多的员工信息(不使用order by和窗口函数)...
  11. Linux查看占用mem的进程脚本
  12. oracle dbv验证,【案例】Oracle数据库verify验证块报错4 dbv报错代码:6101解决办法...
  13. Flutter 与 Compose 应该怎么选择?它们冲突吗?
  14. linux免安装mysql_Linux 配置mysql 免安装版。
  15. css 取偶数节点_CSS选择器:奇偶匹配nth-child(even)
  16. 【Minecraft】建立Bukkit/Spigot插件实时调试环境,并避免断点调试时客户端断开连接
  17. 获取当前北京时间API
  18. L1-007 念数字(C语言)
  19. 【python环境下Z3约束求解器学习笔记】And和Or的用法
  20. [原创]酒好喝,好喝酒,喝好酒,酒喝好

热门文章

  1. web计算机导论读书报告,计算机导论 读书报告.doc
  2. android读取外部图片,Android读取本地图库与调用摄像头拍摄
  3. windows下扩展yaf,并生成yaf框架文件(亲测)
  4. 京东三级列表页持续架构优化—前端优化实践
  5. JQUERY获取DOM
  6. JS的parseInt
  7. mysql 存guid类型_从C#在MySQL中存储GUID
  8. eclipse jsp没有提示_JSP+Struts2+JDBC+Mysql实现的校园宿舍管理系统
  9. windows linux 融合,Windows和Linux的设备驱动框架的对比融合研究
  10. mysql实现动态查询_mysql 实现动态查询