2016-04-06 45 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 
想出了解决方案