doc文件转txt
2015-07-30 17:40
309 查看
doc文件转txt
# -*- coding:utf-8 -*- # 安装pywin32包 http://sourceforge.net/projects/pywin32/files/pywin32/ # windows 7下使用通过 # import os, sys from fnmatch import fnmatch import win32com.client if len(sys.argv)<=2: print "python %s inputdir outputdir" % os.path.basename(sys.argv[1]) sys.exit(1) input = sys.argv[1] output = sys.argv[2] if not os.path.exists(output): os.mkdir(output) i = 1 wordapp = win32com.client.gencache.EnsureDispatch("Word.Application") wordapp.Visible = 0 wordapp.DisplayAlerts = 0 for path, dirs, files in os.walk(input): docs = [os.path.abspath(os.path.join(path, f)) for f in files if fnmatch(f, '*.doc')] for doc in docs: doc2txt = os.path.join(output, os.path.basename(doc.rstrip('doc') + 'txt')) doc2txt = os.path.abspath(doc2txt) if os.path.exists(doc2txt): continue print " processing [%d] %s " % (i, doc) i +=1 wddoc = wordapp.Documents.Open(doc) wddoc.SaveAs(doc2txt, FileFormat=win32com.client.constants.wdFormatTextLineBreaks) wddoc.Close() wordapp.Quit()
相关文章推荐
- 设计模式之 访问者模式
- jQuery的简单应用
- iOS开发中遇到的bug
- NSHashTable 和 NSMapTable学习
- jQuery的简单应用
- PHP的元语言编程
- 使用FAAD库解码AAC实例及 及 faad解码后的通道数不正确的问题
- android acitvity跳转有白色背景 进入软件显示白色
- HTML5账号激活和密码找回模版下载
- 网路总结02-ASI和AFN
- Java byte数据类型详解
- 随笔
- ThinkPHP I方法
- 抽取Zabbix的图形整合到自己后台 推荐
- C#---截取字符串
- maven项目显示红叉的解决方法
- jQuery的简单应用
- ui automation viewer 工具
- Android:手机关闭相机拍照声音
- sql 表连接基本语法