2016-04-06 42 views
0

所以,我得到這個FUNC運行獲取細胞段落不失當前樣式

高清get_bold_lines_from_cell(cellColumn,cellRow):
索引,段落枚舉(table.cell(cellRow,cellColumn)則可對) :
在paragraph.runs運行:
如果run.bold:
#do東西

即使壽段落充滿了大膽的段落,它只是不承認任何。它是否因爲我將docx轉換爲表格而失去它的風格?有無論如何得到段落風格?

謝謝!

回答

0

最好的辦法是查看每個對象的XML以查找線索。

print paragraph._element.xml 
print run._element.xml 

如果有應用了風格,你會看到它在w:pPrw:rPr元素。

1

如果有人曾經有同樣的問題,這是我與

for table in tables: 
    cell = table._cells[cellNumber] 
     for paragraphIndex, paragraph in enumerate(cell.paragraphs): 
      for parentParagraphsIndex, parentParagraphs in enumerate(paragraph._parent.paragraphs): 
       for run in parentParagraphs.runs: 
        tempString = parentParagraphs.text.encode('utf-8') 
        if run.bold: 
         #do stuff 
         break 
        elif run.style.style_id == "Strong": 
         #do stuff 
         break 
        else: 
         #do stuff 
         break 
想出瞭解決方案