2015-03-13 18 views
0

如何在使用catdoc將.doc文件轉換爲.txt文件時接受曲目變更?使用CATDOC接受曲目變更並將.doc轉換爲.txt

假設有兩個文件'original.doc'和'modified.doc'。

「original.doc」具有以下句子:this a test sentence 「modified.doc」具有以下句子:this is a test statement

當我modified.doc轉換爲.txt文件,而不是越來越this is a test statement我的變得this is a test sentence statement

我使用下面的代碼。

def doc_to_text_catdoc(filename): 
(fi, fo, fe) = os.popen3('catdoc -w "%s"' % filename) 
fi.close() 
retval = fo.read() 
erroroutput = fe.read() 
fo.close() 
fe.close() 
if not erroroutput: 
    return retval 
else: 
    raise OSError("Executing the command caused an error: %s" % erroroutput) 

回答

0

使用Antiword解決了該問題。

(fi, fo, fe) = os.popen3('antiword -f "%s"' % filename)