可以拿我上传的文件 帮我看一下嘛,删除范围直接的数据和换行
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 这是您上面分享的相同代码。正如我所提到的,它不会产生您在屏幕截图上分享的问题输出。因此,请创建一个可运行的简单代码并提供输入、输出和预期输出文档,这将使我们能够重现该问题。如果您不回答问题,我们很难帮助您。
@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()