2
doc=Document()
table = doc.add_table(rows = 13, cols = 5)
table.style = 'Table Grid'
row = table.rows[0]
row.cells[0].text = ('text').bold
我試圖創建一個表和大膽的文字,但無法獲得語法右表Python中的docx和加粗文字
doc=Document()
table = doc.add_table(rows = 13, cols = 5)
table.style = 'Table Grid'
row = table.rows[0]
row.cells[0].text = ('text').bold
我試圖創建一個表和大膽的文字,但無法獲得語法右表Python中的docx和加粗文字
在電池爲.text方法只是設置在單元格中的內容「純文本」。如果要格式化文本的字體(如使其變爲粗體),則必須在運行級別訪問文本。這樣的事情會工作,但最適合你深入到文檔的詳細一點,明白爲什麼:) http://python-docx.readthedocs.org/en/latest/user/text.html#apply-character-formatting
cell = row.cells[0]
cell.text = "text"
run = cell.paragraphs[0].runs[0]
run.font.bold = True