0

我正在将数据框插入到 docx 上,但 docx 似乎在行之间有多个间隔。我希望我的最终报告的 docx 具有 0 pt 单行间距。下面是我的代码中似乎不起作用的部分。

doc = docx.Document()
t = doc.add_table(MyDataFrame.shape[0] + 1, MyDataFrame.shape[1])
for i in range(MyDataFrame.shape[0]):
    for j in range(MyDataFrame.shape[-1]):
        t.cell(i + 1, j).text = str(MyDataFrame.values[i, j])

t = doc.tables[0]
t.style.paragraph_format.line_spacing_rule = WD_LINE_SPACING.EXACTLY #Maybe here
t.style.paragraph_format.line_spacing = (0) #The number does not seem to change anything

doc.save('test.docx')
4

0 回答 0