需要替换Subject Demographics,Disease Background:,Dosing/Disposition Information:的表格内容
需要在Sequence of Events,Investigator Causality Statement:的表格第二行插入内容
测试2024.docx (12.9 KB)
需要替换Subject Demographics,Disease Background:,Dosing/Disposition Information:的表格内容
需要在Sequence of Events,Investigator Causality Statement:的表格第二行插入内容
测试2024.docx (12.9 KB)
Other Reasons for Narratives:
Subject Demographics:
ffsfsfsfsdfs
Disease Background:
hfhfhfhfghgf
Dosing/Disposition Information:
grgdrgfsgsgsgrs
需要替换Subject Demographics,Disease Background:,Dosing/Disposition Information:的表格内容
@hhh1111 如果我理解正确,你需要从第一张表中找到内容,然后把它放在第二张表中。您可以使用以下代码作为示例来查找和放置内容:
doc = aw.Document("input.docx")
paragraphs = doc.get_child_nodes(aw.NodeType.PARAGRAPH, True)
for paragraph in paragraphs:
paragraph = paragraph.as_paragraph()
if "Subject Demographics:" in paragraph.get_text():
row = paragraph.get_ancestor(aw.NodeType.ROW)
cell = self.get_next_row_cell(row)
content = cell.get_text()
if "Sequence of Events:" in paragraph.get_text():
row = paragraph.get_ancestor(aw.NodeType.ROW)
cell = self.get_next_row_cell(row)
cell.remove_all_children()
cell.ensure_minimum()
cell.first_paragraph.append_child(aw.Run(doc, content))
doc.save("output.docx")
def get_next_row_cell(self, row):
row = row.as_row()
rowIdx = row.parent_table.rows.index_of(row)
cell = row.parent_table.rows[rowIdx + 1].first_cell
cell = cell.as_cell()
return cell
不对我需要替换里面的内容
替换表格里面内容ffsfsfsfsdfs 把它替换成别的内容
比如 Subject Demographics:找到它 然后把它下面的表格数据替换成别的数据
paragraph.get_ancestor(aw.NodeType.TABLE)
进行搜索,然后删除该表。如果需要删除单元格的内容,请使用上面的代码:row = paragraph.get_ancestor(aw.NodeType.ROW)
cell = self.get_next_row_cell(row)
cell.remove_all_children()
cell.ensure_minimum()
doc.range.replace(…(
或doc.range.replace_regex(…)
.if "Subject Demographics:" in paragraph.get_text():
row = paragraph.get_ancestor(aw.NodeType.ROW)
cell = self.get_next_row_cell(row)
cell.remove_all_children()
cell.ensure_minimum()
cell.first_paragraph.append_child(aw.Run(doc, content))