怎么修改word所有文件的页眉页脚字体大小

可以拿我上传的文件 帮我看一下嘛,删除范围直接的数据和换行

@hhh1111 提供的文档和代码不会产生屏幕截图中所示的输出。因此,请创建一个简化的代码和文档,以演示该问题。

def add_comments_utils(file_path):
    doc = aw.Document(file_path)
    # 修改页面页脚数据
    delete_mode = False
    table = doc.get_child_nodes(aw.NodeType.TABLE, True)
    for i in table:
        for row in i.as_table():

            row = row.as_row()
            row_tex = row.get_text().strip()
            if "研究药物给药" in row_tex:
                delete_mode = True

                # 删除当前单元格
            if delete_mode:
                row.remove()

                # 结束删除范围
            if "严重不良事件" in row_tex:
                delete_mode = False
            for cell in row.as_row():
                cell = cell.as_cell()
                cell.cell_format.vertical_alignment = (
                    aw.tables.CellVerticalAlignment.TOP
                )

@hhh1111 这是您上面分享的相同代码。正如我所提到的,它不会产生您在屏幕截图上分享的问题输出。因此,请创建一个可运行的简单代码并提供输入、输出和预期输出文档,这将使我们能够重现该问题。如果您不回答问题,我们很难帮助您。

您可以用以上代码跑一下
SAE narrative template.docx (29.8 KB)

@hhh1111 您是否尝试过使用您附加的文档运行上述提供的代码?您能否附上您的输出文档?正如我所提到的,我已经使用附加的文档运行了提供的代码,并且输出文档看起来不像您屏幕截图上的问题。

SAE narrative template.docx (26.0 KB)
通过代码输出的文档

原文件
S08003_SAE-TFL.docx (33.1 KB)

通过代码输出文件
S08003_SAE-TFL.docx (22.2 KB)

@hhh1111 请尝试使用以下代码:

for p in doc.get_child_nodes(aw.NodeType.PARAGRAPH, True):
    p = p.as_paragraph()
    if not p.has_child_nodes :
        if p.is_end_of_section:
            p.remove()
            continue

        next_para = p.next_sibling
        if next_para!=None and next_para.node_type == aw.NodeType.PARAGRAPH:
            next_para = next_para.as_paragraph()
            if not next_para.has_child_nodes :
                p.remove()

也不太对 怎么把这里的换行给删除了

@hhh1111 这些是软换行符,因此您可以用空格替换 ControlChar.LINE_BREAK