请问怎么使用docx结构化读取标题和标题下的内容,如果标题下面有图片怎么判断读取呢

这个呢。打开这个文档进行设置呢 请问怎么把3标题下的内容设置wpsoffice手动目录
把图标目录和表格目录标题下面的内容设置成图表目录

设置成这样
image.png (325.8 KB)

image.jpg (216.8 KB)

image.jpg (246.8 KB)

@hhh1111 在 wpsoffice 中,您可以像这样手动添加内容表:

其他问题在上面的帖子中都有回答。

我需要用代码进行添加 不要手动呀 怎么通过代码设置样式

@hhh1111 请参阅以下帖子,了解如何更改 TOC 样式并从文档中获取它们

好的吗谢谢 我看看 麻烦你啦

那请问我想要读取上传的问题,需要怎么设置呢,我刚刚测试了一下 不太对 能用上面的文件给我一个demo吗

@hhh1111 正如我在另一个主题中所说的,你不能原封不动地复制字段代码并插入它们。你能做的就是原样复制节点。
另一种方法是收集 TOC 字段代码,然后插入结果文档并更新字段。这样,您就可以根据当前文档内容和当前标题获得 TOC。

fields = doc.get_child_nodes(aw.NodeType.FIELD_START, True)
for field in fields:
    field = field.as_field_start()
    if field.field_type == aw.fields.FieldType.FIELD_TOC:
        toc = field.get_field().get_field_code()
        fields_list.append(toc)

builder.move_to_document_end()
for field_list in fields_list:
    builder.insert_field(field_list)
    builder.writeln()

或者,您也可以取消字段链接,将其作为文本收集,然后在结果文档中为标签添加制表符:

doc = aw.Document(file)
doc.unlink_fields()
[
	{
		"type": "text",
		"content": "目录",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&bea3bf57-7148-4e0b-8cd6-42b865a245dc",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "1 标题页\t1",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&3c8d0bc7-25aa-4d87-b623-06e50e0ef5f3",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "2 概要\t5",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&0a7ce8ba-b098-49dc-9ce8-4b49ec04dfd1",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "3 个例临床研究报告目录\t22",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&d583e100-02f6-4dfd-be7b-77f803e65904",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "表格目录\t25",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&0755dd8e-6268-448c-ab70-754af8639dae",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "图表目录\t26",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&26882db7-0ec2-4a04-9945-34146f4bf30e",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "4 缩略语和术语定义表\t28",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&435a9c72-bf15-4810-ba83-81947019aa30",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "5 伦理学\t29",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&b6a21d17-4200-4b0e-b6fa-f39cd75669d2",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "5.1 独立伦理委员会(IEC)\t29",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&bfca61a1-b799-47be-a638-68adac1601bc",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "5.2 研究的伦理行为\t29",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&6ef71dc8-9f4f-414b-80a3-d13e739adf67",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "5.3 受试者知情与同意\t29",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&ebb73cdc-6fc4-45d4-af14-40b6a0ee58c3",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "6 研究者和研究管理机构\t30",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&2fb21742-011e-4435-9674-e3a528d301d7",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "7 简介\t31",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&679dc3d7-adb1-4e82-aab8-7f04d284ca57",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "8 研究目标\t32",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&33d52b14-6f78-460a-8b14-aedb601e6dc0",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "8.1 主要研究目的\t32",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&87d93c87-3806-4729-9703-4070aa528a76",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "8.2 次要研究目的\t32",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&954b3056-bbce-4e0a-8699-5b383cd78aa7",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "8.3 探索性研究目的\t32",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&db4eee5a-a68a-45ac-a922-6b99a377df5d",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9 研究计划\t32",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&2cd1a61e-650e-4d55-8cd2-21c7bdbb257b",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.1 整体研究计划\t32",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&4b6d8c39-dbee-4b77-8264-f2c636476428",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.1.1 研究示意图\t33",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&a23231a2-9b0f-4f9f-a6a0-266e13fd3d07",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.2 研究设计讨论\t33",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&6d79a26d-3fb8-4fe1-969c-5eb590475de4",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.2.1患者群体的选择\t33",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&b7e17716-1222-4591-bad6-23dbda4ac4d5",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.2.2主要终点采用IRC评估的ORR\t34",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&97a6bf77-77f0-41a7-a08a-be1ec3468fe4",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.2.3 疗效评估标准的选择\t34",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&5db98a67-6a74-4f5f-a680-c81e8c62d2c2",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.3 研究人群的选择\t35",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&dfaec5d9-e7a5-41da-afb2-a2b0ce0d514a",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.3.1 入选标准\t35",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&48b8df09-e00d-4f37-846c-b3b5b4553738",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.3.2 排除标准\t36",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&c7d92beb-dadc-4a75-bfc5-62e19133d600",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.3.3 从治疗或评估中移除受试者\t37",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&e2b00cee-09c9-4ce5-a30e-33948be45b75",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.4 治疗\t38",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&7b1b13cb-e13c-4a91-83e4-5ef3fe002dd9",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.4.1 给予的治疗\t38",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&46a2a95b-6512-4077-991f-d0b5c0ff5431",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.4.2 研究药物信息\t39",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&553f59f9-3dcf-4850-9a06-1811d34ede64",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.4.3 受试者的治疗组分配方法\t39",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&09a10fa7-682f-4e83-b95c-d64e3a9f1751",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.4.4 研究中的剂量选择\t39",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&65253004-e5bc-4c59-aae4-192efae400d9",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.4.5 每位受试者的研究剂量和给药时间\t39",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&afbbf1bf-b6b6-41cf-aef7-5d0155a9831d",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.4.6 盲法\t40",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&47885289-78df-4d42-a00e-8d0effad819c",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.4.7 既往和伴随治疗\t40",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&ff4bac88-19b5-455d-b09e-e758b8d683a3",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.4.8 治疗依从性\t41",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&598baca5-d07f-4946-87cc-d4e67210cb44",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.5 疗效、安全性和药代动力学终点\t41",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&f895bfef-5180-4bd2-be3a-38c1d8192d4b",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.5.1 评估疗效、安全性和药代动力学终点指标和流程图\t41",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&c6f902f4-3983-4c99-806f-5c0a1a856fc5",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.5.2 衡量指标的适当性\t45",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&be40857d-f2a4-432d-a6b7-6698f88bc39e",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.5.3 主要疗效终点\t45",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&8e6610dc-0738-48c0-be14-7b406b49058f",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.5.4 药物浓度测定\t45",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&cbac3ade-7435-4dc7-885d-e77ab9ffcc67",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.6 数据质量保证\t45",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&0306e17f-0994-4ef5-ba98-235edd0b7605",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.6.1临床试验过程的质量保证与控制\t46",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&66817d8c-143e-4b3f-a546-592caf59d4b3",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.6.2 启动访视\t47",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&7b61e7f8-6e42-44d4-8134-f0604a5110fd",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.6.3 实验室认可\t47",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&7e97e67b-a584-475b-8481-43218b8fffe7",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.6.4 数据管理\t47",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&689dc981-18c0-46d9-b4e9-a321740d3bfd",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.7 研究方案中计划的统计方法和样本量的确定\t48",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&3b2bb483-8cdc-4454-8e90-9b0b1e89ce26",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.7.1 统计分析计划\t48",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&9acbaa49-4778-44f0-8250-2c6b07914563",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.7.2 样本量的确定\t53",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&138a2915-2469-46a0-b8ec-fa27616d4f0c",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.8 研究过程或分析计划的变更\t53",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&96a99bd2-a5b6-4cb0-bae1-e42c5cc9bc7b",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.8.1 方案变更\t53",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&fc7f5926-c08a-451d-b101-17c6506abec9",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "9.8.2 统计分析计划(SAP)变更\t54",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&40cb74a3-4ff3-45dc-a257-128610b4241b",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "10 研究对象\t55",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&0c125f3f-ff13-42ce-87ca-3b1e16d29221",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "10.1 受试者分布\t55",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&591bdf8b-7874-4c6b-83f2-221f436eed14",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "10.2 研究方案偏离\t56",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&3bad5775-63be-4bcb-9d8e-1a3b488ee2c2",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "10.3 分析数据集\t56",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&21347ada-b39f-4e18-9cf9-9381e1d4be30",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "10.4 人口统计学和其他基线特征\t56",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&bca3d133-d571-4f91-92a4-5deb91c274f5",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "10.4.1 人口统计学和基线特征(mITT集)\t56",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&850912ba-6f6f-4a3f-b0ef-52aa75528f37",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "10.4.2肿瘤基线特征及既往抗肿瘤治疗(mITT集)\t58",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&5f43477f-9bf8-4de8-824d-886b0564d330",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "10.4.3 既往病史\t60",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&39f796dc-6569-4743-b1f2-2e7be7106850",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "10.4.4 既往和合并药物治疗\t61",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&efc3503e-c7d9-42b9-a69c-9a31de9172f9",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "10.5 治疗依从性的测量\t61",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&e3a11541-fc5f-4ed8-b383-28e32921266a",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "11疗效评估和药代动力学评估\t61",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&0340b7ae-93d0-4cb9-96e2-1e4e3cc280a1",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "11.1疗效结果和个体受试者数据列表\t61",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&c97713ad-ed83-4675-b9b6-44e7985fdb6b",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "11.1.1 疗效分析\t62",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&98b6506b-28db-4cbf-a5f9-2a808ab21f14",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "11.1.2 统计/分析内容\t69",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&f52d1654-bdbe-453c-b852-b3d219905eeb",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "11.1.3 个体疗效数据列表\t72",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&7f32bf3a-dde8-49cd-98e4-606f7ded5346",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "11.1.4 药物剂量、药物浓度以及效应之间的关系\t72",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&0359bcee-b771-44bf-9bf6-7eec74397386",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "11.1.5 药物-药物和药物-疾病相互作用\t72",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&ac6c1a29-f0a4-4533-ac4e-4702e1c8a9c6",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "11.1.6 按受试者列出\t72",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&0902548d-308a-403b-bc3d-df1acacfce16",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "11.1.7 疗效结论\t72",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&1e5876ca-eb6d-431d-8b89-0a83c5503146",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12 安全性评价\t73",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&0b07599e-bc44-4cad-96f6-072aa142bbc6",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.1 暴露程度\t73",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&5ca91707-720a-4efb-a1f3-1fc36f5dbf95",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.2 不良事件(AE)\t74",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&46ee079c-2870-4471-b3b9-a7d02eebd239",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.2.1 治疗期间发生的不良事件(TEAE)概要\t74",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&f55697b0-d4c8-4bb5-b134-29465d838df2",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.2.2 不良事件列出\t75",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&b9ef66b7-f590-4ea2-9b9a-3d14643d746a",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.2.3不良事件分析\t76",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&ed323f99-574a-4410-af8f-9c5cd02c0b32",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.2.4 各受试者不良事件列表\t76",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&ed581567-46fe-4dc8-9ac4-31405ca46590",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.3 死亡、其他严重不良事件和其他重要不良事件\t77",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&578dde75-475c-44aa-a94c-886729a123b3",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.3.1 死亡、其他严重不良事件和其他重要不良事件列表\t77",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&bcd05c99-c256-489f-8e19-e2d5cda18664",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.3.2 死亡、其他严重不良事件和其他重要不良事件的叙述\t79",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&7a734bd1-06f1-4084-86d4-64d4579f74e8",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.3.3 死亡、其他严重不良事件和其他重要不良事件的分析和讨论\t79",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&26260c11-eca3-4f51-95c7-77ba8da968f1",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.4 临床实验室评估\t79",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&c0146693-6cec-4b4a-8afd-d54e1c032da5",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.4.1 各受试者的个例实验测量值列表(16.2.8)和各异常实验室值(14.3.4)\t79",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&08f03524-061c-4e7c-8c08-6d2b6e6c73c7",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.4.2 各实验室参数的评价\t79",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&1f826b25-1e81-4ba4-8f68-c77e78be0095",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.5 生命体征、体格检查发现和其他安全性相关观察结果(SS)\t81",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&102c3246-11a4-4c57-9458-3f339a27a3f1",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "12.6 安全性结论\t81",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&9b55f3ec-a371-4742-b26b-a644861d49f7",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "13 讨论和总体结论\t81",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&6996ddd9-f10f-4c1b-aeb5-03aa2e7fa590",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "13.1 讨论\t81",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&1c20ae4d-98ff-4124-9663-f45ccbdd1a9c",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "13.1.1 背景\t81",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&18aeb7ec-6ad4-4cf4-ad3f-5671d9b060d7",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "13.1.2 有效性\t82",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&717212d5-e823-474b-a2ad-95f8ea25983b",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "13.1.3 安全性\t83",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&cebd019e-68d6-461b-a070-803c86b99700",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "13.1.4 药代动力学\t83",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&be9325da-5d8a-4276-9783-b4e2b3a24658",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "13.2 结论\t83",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&54b7453d-bf99-4951-bc70-fa34c8074608",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "14 参考但不纳入文本的表格、图示和图表\t84",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&40a0bdb1-90f9-4953-aaa8-9608470514e4",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "15参考文献列表\t85",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&8921ebc4-d42b-4e0a-9e3a-719c2512a8a4",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	},
	{
		"type": "toc",
		"content": "16 附录\t86",
		"block_id": "90b827cc-b786-49f3-b98c-59ee9329b595&&ad05c740-1d1b-48eb-8fd3-6d396d8cba93",
		"parent_block_id": "90b827cc-b786-49f3-b98c-59ee9329b595"
	}
]
elif section["type"] == 'toc':
    page_setup = doc.first_section.page_setup
    tab_stop_position = page_setup.page_width - page_setup.left_margin - page_setup.right_margin
    builder.paragraph_format.tab_stops.add(tab_stop_position, aw.TabAlignment.RIGHT, aw.TabLeader.DOTS)
    text_content = section.get('content', '')
    builder.writeln(text_content)

output.docx (9.2 KB)

[
{
“type”: “text”,
“content”: “目录”,
“block_id”: “90b827cc-b786-49f3-b98c-59ee9329b595&&bea3bf57-7148-4e0b-8cd6-42b865a245dc”,
“parent_block_id”: “90b827cc-b786-49f3-b98c-59ee9329b595”
},
{
“type”: “toc”,
“content”: “1 标题页\t1”,
“block_id”: “90b827cc-b786-49f3-b98c-59ee9329b595&&3c8d0bc7-25aa-4d87-b623-06e50e0ef5f3”,
“parent_block_id”: “90b827cc-b786-49f3-b98c-59ee9329b595”
},
{
“type”: “toc”,
“content”: “2 概要\t5”,
“block_id”: “90b827cc-b786-49f3-b98c-59ee9329b595&&0a7ce8ba-b098-49dc-9ce8-4b49ec04dfd1”,
“parent_block_id”: “90b827cc-b786-49f3-b98c-59ee9329b595”
},
{
“type”: “toc”,
“content”: “3 个例临床研究报告目录\t22”,
“block_id”: “90b827cc-b786-49f3-b98c-59ee9329b595&&d583e100-02f6-4dfd-be7b-77f803e65904”,
“parent_block_id”: “90b827cc-b786-49f3-b98c-59ee9329b595”
},
{
“type”: “toc”,
“content”: “表格目录\t25”,
“block_id”: “90b827cc-b786-49f3-b98c-59ee9329b595&&0755dd8e-6268-448c-ab70-754af8639dae”,
“parent_block_id”: “90b827cc-b786-49f3-b98c-59ee9329b595”
}, 请问这个数据是从哪里读取出来呢的

image.jpg (212.7 KB)

如果读取我进行修改一下 添加上这个top要怎么修改呢

@hhh1111 这是一个数据示例,可以说明如何做到这一点。

async def aw_extract_headings_and_contents_table_dict_id(file):
doc = aw.Document(file)
current_level = 0
data = []
stack = []
for s in doc.sections:
sect = s.as_section()
for node in sect.body.get_child_nodes(aw.NodeType.ANY, True):
block_id = generate_unique_id()
block_id1 = generate_unique_id()
if node.node_type == aw.NodeType.PARAGRAPH:
node = node.as_paragraph()
if node.paragraph_format.outline_level in [0, 1, 2, 3, 4, 5]:
level = int(node.paragraph_format.outline_level) + 1
if level > current_level:

                    # 如果级别更深,将当前标题添加到堆栈
                    stack.append((current_level, data))
                    data = []
                    current_level = level
                elif level < current_level:
                    # 如果级别更浅,将堆栈中的项添加回数据
                    while stack and stack[-1][0] >= level:
                        old_level, old_data = stack.pop()
                        data = old_data + data
                        current_level = old_level

                data.append(
                    {
                        "Title": node.get_text(),
                        "block_id": str(block_id),
                        "Content": [],
                        "Level": level,
                        "Table": [],
                        "Tbale_name": [],
                    }
                )
            else:

                if data:
                    if node.get_text().strip() and not node.get_ancestor(aw.NodeType.TABLE):
                        data[-1]["Content"].append(
                            {"type": "text",
                             "content": node.get_text().strip().replace("  SEQ 表 \* ARABIC ", '').replace(
                                 'TOC \h \c "表" HYPERLINK \l "_Toc14741"', '').replace(
                                 "\u0013 SEQ 图 \\* ARABIC \u00141\u0015 ", ''),
                             "block_id": data[-1]["block_id"] + '&&' + str(block_id1),
                             "parent_block_id": data[-1]["block_id"]})
        if data:
            if node.node_type == aw.NodeType.SHAPE:
                shape = node.as_shape()
                if shape.has_image:
                    image_id = str(uuid.uuid1())  # 长度是36
                    try:
                        image_extension = aw.FileFormatUtil.image_type_to_extension(shape.image_data.image_type)
                        image_file_name = f"{image_id}{image_extension}"
                        image_path = os.path.join(settings.IMAGES_PATH, image_file_name)
                        shape.image_data.save(image_path)
                        with open(image_path, "rb") as image_file:
                            encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
                        image_string = f'data:image/{image_extension.strip(".")};base64,{encoded_string}'
                        data[-1]["Content"].append(
                            {"type": "image",
                             "content": {"type": "image", "attrs": {
                                 "src": image_string,
                                 "alt": image_file_name, "title": ''}},
                             "block_id": data[-1]["block_id"] + '&&' + str(block_id1),
                             "parent_block_id": data[-1]["block_id"]}
                        )
                    except Exception as e:
                        # 捕获并处理无法转换图像类型的错误
                        print(f"Error saving image: {e}. Skipping this image.")
                        continue

            if node.node_type == aw.NodeType.TABLE:
                parent_node = node.as_table()
                tables = doc.get_child_nodes(aw.NodeType.TABLE, True)
                _able_content = aw_read_table_id(parent_node, data[-1]["block_id"] + '&&' + str(block_id1))
                data[-1]["Content"].append(
                    {"type": "table",
                     "content": _able_content,
                     "block_id": data[-1]["block_id"] + '&&' + str(block_id1),
                     "parent_block_id": data[-1]["block_id"]})
while stack:
    old_level, old_data = stack.pop()
    data = old_data + data
return data

如果我这里添加一个top类型 需要在哪里今天添加呢

@hhh1111 您可以使用类似下面的方法获取字段内容

if node.node_type == aw.NodeType.FIELD_START:
    field = node.as_field_start()
    if field.field_type == aw.fields.FieldType.FIELD_TOC:
        results = field.get_field().display_result.split('\r')
        for result in results:
            if result.strip():
                data[-1]["Content"].append(
                    {"type": "toc",
                     "content": result,
                     "block_id": data[-1]["block_id"] + '&&' + str(block_id1),
                     "parent_block_id": data[-1]["block_id"]}

为什么我写入的样式和你不一样呢 并且以段落的格式也读出来一次
image.jpg (148.4 KB)

下面是读取内容,写入的格式 用的你发的,

async def aw_extract_headings_and_contents_table_dict_id(file):
    doc = aw.Document(file)
    current_level = 0
    data = []
    stack = []
    for s in doc.sections:
        sect = s.as_section()
        for node in sect.body.get_child_nodes(aw.NodeType.ANY, True):
            block_id = generate_unique_id()
            block_id1 = generate_unique_id()
            if node.node_type == aw.NodeType.PARAGRAPH:
                node = node.as_paragraph()
                if node.paragraph_format.outline_level in [0, 1, 2, 3, 4, 5]:
                    level = int(node.paragraph_format.outline_level) + 1
                    if level > current_level:

                        # 如果级别更深,将当前标题添加到堆栈
                        stack.append((current_level, data))
                        data = []
                        current_level = level
                    elif level < current_level:
                        # 如果级别更浅,将堆栈中的项添加回数据
                        while stack and stack[-1][0] >= level:
                            old_level, old_data = stack.pop()
                            data = old_data + data
                            current_level = old_level

                    data.append(
                        {
                            "Title": node.get_text(),
                            "block_id": str(block_id),
                            "Content": [],
                            "Level": level,
                            "Table": [],
                            "Tbale_name": [],
                        }
                    )
                else:

                    if data:
                        if node.get_text().strip() and not node.get_ancestor(aw.NodeType.TABLE) and not node.get_ancestor(aw.NodeType.FIELD_START):
                            data[-1]["Content"].append(
                                {"type": "text",
                                 "content": node.get_text().strip().replace("  SEQ 表 \* ARABIC ", '').replace(
                                     'TOC \h \c "表" HYPERLINK \l "_Toc14741"', '').replace(
                                     "\u0013 SEQ 图 \\* ARABIC \u00141\u0015 ", ''),
                                 "block_id": data[-1]["block_id"] + '&&' + str(block_id1),
                                 "parent_block_id": data[-1]["block_id"]})
            if data:
                if node.node_type == aw.NodeType.SHAPE:
                    shape = node.as_shape()
                    if shape.has_image:
                        image_id = str(uuid.uuid1())  # 长度是36
                        try:
                            image_extension = aw.FileFormatUtil.image_type_to_extension(shape.image_data.image_type)
                            image_file_name = f"{image_id}{image_extension}"
                            image_path = os.path.join(settings.IMAGES_PATH, image_file_name)
                            shape.image_data.save(image_path)
                            with open(image_path, "rb") as image_file:
                                encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
                            image_string = f'data:image/{image_extension.strip(".")};base64,{encoded_string}'
                            data[-1]["Content"].append(
                                {"type": "image",
                                 "content": {"type": "image", "attrs": {
                                     "src": image_string,
                                     "alt": image_file_name, "title": ''}},
                                 "block_id": data[-1]["block_id"] + '&&' + str(block_id1),
                                 "parent_block_id": data[-1]["block_id"]}
                            )
                        except Exception as e:
                            # 捕获并处理无法转换图像类型的错误
                            print(f"Error saving image: {e}. Skipping this image.")
                            continue

                if node.node_type == aw.NodeType.TABLE:
                    parent_node = node.as_table()
                    tables = doc.get_child_nodes(aw.NodeType.TABLE, True)
                    _able_content = aw_read_table_id(parent_node, data[-1]["block_id"] + '&&' + str(block_id1))
                    data[-1]["Content"].append(
                        {"type": "table",
                         "content": _able_content,
                         "block_id": data[-1]["block_id"] + '&&' + str(block_id1),
                         "parent_block_id": data[-1]["block_id"]})
                if node.node_type == aw.NodeType.FIELD_START:
                    field = node.as_field_start()
                    if field.field_type == aw.fields.FieldType.FIELD_TOC:
                        results = field.get_field().display_result.split('\r')
                        for result in results:
                            if result.strip():
                                data[-1]["Content"].append(
                                    {"type": "toc",
                                     "content": result,
                                     "block_id": data[-1]["block_id"] + '&&' + str(block_id1),
                                     "parent_block_id": data[-1]["block_id"]})
    while stack:
        old_level, old_data = stack.pop()
        data = old_data + data
    return data

@hhh1111 我只是用代码来获取数据,然后从生成的数据中创建 json,并将 json 与 for section in sections: 代码一起使用来创建文件。有了数据后,这段代码就能正常工作了。你可以调试代码,尝试找出问题所在。

另外,请更新以下代码以排除所有 TOC 字段:

else:
    if data:
        if node.node_type is not aw.NodeType.TABLE:
            if node.get_text().strip() and "Toc" not in node.get_text()\
                    and "TOC" not in node.get_text():
                data[-1]["Content"].append(
                    {"type": "text",
                     "content": node.get_text().strip().replace("  SEQ 表 \* ARABIC ",
                                                                '').replace(
                         "\u0013 SEQ 图 \\* ARABIC \u00141\u0015 ", ''),
                     "block_id": data[-1]["block_id"] + '&&' + str(block_id1),
                     "parent_block_id": data[-1]["block_id"]})

请问表格样式怎么设置成这种的,没有中间的边框

for row in table.rows:
	row = row.as_row()
	if row.is_first_row:
		for cell in row.cells:
			cell = cell.as_cell()
			cell.cell_format.borders.bottom.line_style = aw.LineStyle.SINGLE
		for cell in row.next_row.cells:
			cell = cell.as_cell()
			cell.cell_format.borders.top.line_style = aw.LineStyle.SINGLE
	
	if row.is_last_row:
		for cell in row.cells:
			cell = cell.as_cell()
			cell.cell_format.borders.top.line_style = aw.LineStyle.SINGLE
		for cell in row.previous_row.cells:
			cell = cell.as_cell()
			cell.cell_format.borders.bottom.line_style = aw.LineStyle.SINGLE

@vyacheslav.deryushev

@hhh1111 您可以使用以下代码清除边框:

table.clear_borders()

for row in table.rows:
    row = row.as_row()
    if row.is_first_row:
        for cell in row.cells:
            cell = cell.as_cell()
            cell.cell_format.borders.top.line_style = aw.LineStyle.SINGLE
            cell.cell_format.borders.bottom.line_style = aw.LineStyle.SINGLE

    if row.is_last_row:
        for cell in row.cells:
            cell = cell.as_cell()
            cell.cell_format.borders.bottom.line_style = aw.LineStyle.SINGLE

或者,如果您在文档中创建了表格样式,也可以使用:

table.style_name = "table style name"

image.png (62.2 KB)

不对呀为什么第一行的下边框没有设置

elif section[“type”] == ‘text’:
# 添加文本内容
new_run = builder.font
# 设置西文和中文字体
new_run.name = “Times New Roman” # 设置西文是新罗马字体
new_run.bold = False
new_run.name_far_east = “MS Gothic”
new_run.size = 10.5
text_content = section.get(‘contents’, ‘’).strip() # 获取文本内容
builder.writeln(text_content) # 写入文本到文档、
如果是日文需要设置成MS Gothic但是没有生效都变成了Times New Roman