在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Python/ 處理Word文檔
文本翻譯
提取URL地址
處理PDF
塊分類
搜索和匹配
大寫轉(zhuǎn)換
提取電子郵件地址
字符串的不變性
文本處理狀態(tài)機(jī)
雙字母組
閱讀RSS提要
單詞替換
WordNet接口
重新格式化段落
標(biāo)記單詞
向后讀取文件
塊和裂口
美化打印數(shù)字
拼寫檢查
將二進(jìn)制轉(zhuǎn)換為ASCII
文本分類
文字換行
頻率分布
字符串作為文件
約束搜索
詞干算法
符號(hào)化
同義詞和反義詞
過濾重復(fù)的字詞
刪除停用詞
Python文本處理教程
文字摘要
段落計(jì)數(shù)令牌
語料訪問
文字改寫
文本處理簡(jiǎn)介
處理Word文檔
Python文本處理開發(fā)環(huán)境
排序行

處理Word文檔

要讀取word文檔,可使用python中的docx模塊。 首先安裝docx,如下所示。 然后編寫一個(gè)程序,使用docx模塊中的不同函數(shù)按段落讀取整個(gè)文件。

使用以下命令將docx模塊放入程序環(huán)境中。

 pip install docx

在下面的示例中,通過將每個(gè)行附加到段落并最終打印出所有段落文本來讀取word文檔的內(nèi)容。

import docx

def readtxt(filename):
    doc = docx.Document(filename)
    fullText = []
    for para in doc.paragraphs:
        fullText.append(para.text)
    return '\n'.join(fullText)

print (readtxt('path\yiibaispoint.docx'))

當(dāng)運(yùn)行上面的程序時(shí),我們得到以下輸出 -

Yiibai Point originated from the idea that there exists a class of readers who respond 
better to online content and prefer to learn new skills at their own pace from the comforts 
of their drawing rooms. 

The journey commenced with a single tutorial on HTML in 2006 and elated by the response it generated, 
we worked our way to adding fresh tutorials to our repository which now proudly flaunts 
a wealth of tutorials and allied articles on topics ranging from programming languages 
to web designing to academics and much more.

讀取個(gè)別段落

可以使用paragraph屬性從word文檔中讀取特定段落。 在下面的例子中,只讀取word文檔中的第二段。

import docx

doc = docx.Document('path\Yiibaispoint.docx')
print len(doc.paragraphs)

print doc.paragraphs[2].text

當(dāng)運(yùn)行上面的程序時(shí),我們得到以下輸出 -

The journey commenced with a single tutorial on HTML in 2006 and elated by the response 
it generated, we worked our way to adding fresh tutorials to our repository 
which now proudly flaunts a wealth of tutorials and allied articles on topics 
ranging from programming languages to web designing to academics and much more.