就是使用Pythondocx库将单元格中的文字变为纵向排列
1条回答 默认 最新
- CSDN专家-HGJ 2021-12-16 13:58关注
可以试试单元格字段用换行符分隔。:table.cell(0, 0).text='\n'.join(list('学生成绩'))
from docx.enum.table import WD_TABLE_ALIGNMENT from docx.shared import RGBColor from docx.enum.text import WD_PARAGRAPH_ALIGNMENT import docx document=docx.Document() table = document.add_table(3, 3,style='Table Grid') table.alignment = WD_TABLE_ALIGNMENT.CENTER table.cell(0, 0).text='\n'.join(list('学生成绩')) for column in table.columns: for cell in column.cells: for paragraph in cell.paragraphs: paragraph.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER # 水平对齐,居中 table.cell(0, 0).paragraphs[0].runs[0].font.color.rgb = RGBColor(255, 55, 55) # 红色 document.save('abcd.docx')
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 3无用