2

重複の可能性:
Python で MS Word ファイルからテキストを抽出する

Python でスクリプトを使用して .doc ファイルを (式で検索を実行するために) 解析したいと考えています。Unix マシンで実行されます。

誰でも助けることができますか?

4

2 に答える 2

3

このプロジェクトを見ることができます: python-docxpython example-extracttext.py docfile.docx textfile.txt | grep some-expressionライブラリをダウンロードしたら、シェルで実行できます。必要に応じて、Python コードでより高度な検索を行うこともできます。

python-docx の欠点は、現在 ms-Word 2007/2008 のみをサポートしていることです。それが気になる場合は、Microsoft Word バージョン 2、6、7、97、2000、2002、および 2003 をサポートするantiwordをお勧めします。実際に私はVIMエディターでms-wordファイルを表示できるように、 vimrcでそれを使用しています。Python スクリプトではありませんが、Python から簡単に呼び出すことができます。

于 2013-01-29T14:04:23.570 に答える
3

使えます、PyUno

サンプル、

# HelloWorld python script for the scripting framework

def HelloWorldPython( ):
    """Prints the string 'Hello World(in Python)' into the current document"""
#get the doc from the scripting context which is made available to all scripts
    model = XSCRIPTCONTEXT.getDocument()
#get the XText interface
    text = model.Text
#create an XTextRange at the end of the document
    tRange = text.End
#and set the string
    tRange.String = "Hello World (in Python)"
    return None

その他、PyUNOサンプル

于 2013-01-29T14:04:44.297 に答える