http://blog.csdn.net/pipisorry/article/details/50368044
def doc2txt(): ''' 将doc文档转换成txt文档 :return: ''' from win32com import client INPUT_DIR = r'C:\Users\pi\Desktop\New folder' OUTPUT_DIR = r'C:\Users\pi\Desktop\txts' word = client.Dispatch('Word.Application') for doc_name in listdir(INPUT_DIR): print(doc_name) doc_full_name = path.join(INPUT_DIR, doc_name) doc = word.Documents.Open(doc_full_name) doc.SaveAs(path.join(OUTPUT_DIR, doc_name.split('.')[0]), 4) doc.Close() word.Quit()
wdFormatDocument = 0 wdFormatDocument97 = 0 wdFormatDocumentDefault = 16 wdFormatDOSText = 4 wdFormatDOSTextLineBreaks = 5 wdFormatEncodedText = 7 wdFormatFilteredHTML = 10 wdFormatFlatXML = 19 wdFormatFlatXMLMacroEnabled = 20 wdFormatFlatXMLTemplate = 21 wdFormatFlatXMLTemplateMacroEnabled = 22 wdFormatHTML = 8 wdFormatPDF = 17 wdFormatRTF = 6 wdFormatTemplate = 1 wdFormatTemplate97 = 1 wdFormatText = 2 wdFormatTextLineBreaks = 3 wdFormatUnicodeText = 7 wdFormatWebArchive = 9 wdFormatXML = 11 wdFormatXMLDocument = 12 wdFormatXMLDocumentMacroEnabled = 13 wdFormatXMLTemplate = 14 wdFormatXMLTemplateMacroEnabled = 15 wdFormatXPS = 18
照着字面意思应该能对应到相应的文件格式,如果你是office2003可能支持不了这么多格式。word文件转html有两种格式可选wdFormatHTML、wdFormatFilteredHTML(对应数字8、10),区别是如果是wdFormatHTML格式的话,word文件里面的公式等ole对象将会存储成wmf格式,而选用wdFormatFilteredHTML的话公式图片将存储为gif格式,而且目测可以看出用wdFormatFilteredHTML生成的HTML明显比wdFormatHTML要干净许多。
当然你也可以用任意一种语言通过com来调用office API,比如PHP.
d = {}
with open(json_file) as in_file:
data = json.load(in_file)
data = json.loads(data)
for paragraph in data:
for sentence in paragraph:
for word in sentence:
pos = word[tag]
d[pos] += 1
ref:数据编码和处理