md2report icon indicating copy to clipboard operation
md2report copied to clipboard

崩溃了,到底哪里可以找到文档?!

Open teacup418 opened this issue 11 months ago • 0 comments

尝试在修改,python-docx的文档也看了大部分,但是怎么感觉不全啊?

  1. 太多不知道在哪定义的方法,希望得知相关文档。

paragraph._p.addnext(table._tbl)这个addnext到底是哪里来的?还有title._p.addprevious(image_para._p)的addprevious? 文档只给了一个最接近的是insert_paragraph_before(),用vscode去搜,也搜不到定义,为什么这个方法都可以运行呢?我改了一下格式全乱了。 原本希望院校和课程名字作为主标题和副标题的,但是现在缩到文末去了。

  1. ctmd的表格边框。哪里可以找xml的相关标准。
bottom = table._element.xpath("./w:tblPr/w:tblLook")[0]
bottom.set(qn("w:lastColumn"), "1")
bottom.set(qn("w:firstRow"), "0")

这串代码在干什么?为什么第一行要单独设置? 我给deepseek看,要求3行4列,1、3列是院校、姓名等键,2、4列是填上去的值,他直接改成了修改tblBorders的属性

# 遍历表格的每一行
    for row in table.rows:
        # 遍历每一行的单元格
        for idx, cell in enumerate(row.cells):
            # 获取单元格的边框属性
            tc = cell._tc
            tcPr = tc.get_or_add_tcPr()

            # 创建边框元素
            tcBorders = OxmlElement('w:tcBorders')

            # 如果是第2列或第4列,设置下边框
            if idx == 1 or idx == 3:
                bottom = OxmlElement('w:bottom')
                bottom.set(qn('w:val'), 'single')
                bottom.set(qn('w:sz'), '4')
                bottom.set(qn('w:space'), '0')
                bottom.set(qn('w:color'), '000000')
                tcBorders.append(bottom)
            else:
                # 如果是第1列或第3列,移除所有边框
                for border_name in ['top', 'left', 'bottom', 'right']:
                    border = OxmlElement(f'w:{border_name}')
                    border.set(qn('w:val'), 'nil')
                    tcBorders.append(border)

            # 将边框元素添加到单元格属性中
            tcPr.append(tcBorders)
            # 如果是第1列或第3列,设置分散对齐
            if idx == 0 or idx == 2:
                for paragraph in cell.paragraphs:
                    paragraph.alignment = WD_ALIGN_PARAGRAPH.DISTRIBUTE

跑是能跑,但是微软的xml定义在哪?搜索office文件标准啥也没有。整个代码对我而言像魔法一样,要崩溃了QAQ。

teacup418 avatar Feb 10 '25 08:02 teacup418