| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 
 | from docx import Documentfrom docx.shared import Pt, Inches, Cm
 from docx.enum.text import WD_ALIGN_PARAGRAPH, WD_LINE_SPACING
 from docx.oxml.ns import qn
 from docx.oxml import OxmlElement
 
 
 
 
 
 def set_document_defaults(doc):
 """设置文档的默认字体和段落间距"""
 
 style = doc.styles['Normal']
 style.font.name = 'Times New Roman'
 style.font.size = Pt(10.5)
 
 
 rpr = style.element.get_or_add_rPr()
 rFonts = OxmlElement('w:rFonts')
 rFonts.set(qn('w:ascii'), 'Times New Roman')
 rFonts.set(qn('w:hAnsi'), 'Times New Roman')
 rFonts.set(qn('w:eastAsia'), '宋体')
 rFonts.set(qn('w:cs'), 'Times New Roman')
 rpr.append(rFonts)
 
 
 p_fmt = style.paragraph_format
 p_fmt.line_spacing = Pt(18)
 p_fmt.space_after = Pt(0)
 p_fmt.space_before = Pt(0)
 
 def set_run_font(run, english_font='Times New Roman', chinese_font='宋体', font_size=None, bold=False, italic=False):
 """设置run的字体"""
 if font_size:
 run.font.size = font_size
 run.font.bold = bold
 run.font.italic = italic
 
 rpr = run._element.get_or_add_rPr()
 rFonts = OxmlElement('w:rFonts')
 rFonts.set(qn('w:ascii'), english_font)
 rFonts.set(qn('w:hAnsi'), english_font)
 rFonts.set(qn('w:eastAsia'), chinese_font)
 rFonts.set(qn('w:cs'), english_font)
 rpr.append(rFonts)
 
 def add_chinese_title(doc, text):
 """添加中文课题名称 - 小二号,黑体,加粗,居中"""
 doc.add_paragraph()
 p = doc.add_paragraph()
 p.alignment = WD_ALIGN_PARAGRAPH.CENTER
 p.paragraph_format.line_spacing = Pt(18)
 p.paragraph_format.space_before = Pt(6)
 p.paragraph_format.space_after = Pt(6)
 
 run = p.add_run(text)
 set_run_font(run, chinese_font='黑体', font_size=Pt(18), bold=True)
 doc.add_paragraph()
 
 def add_chinese_abstract_title(doc):
 """添加中文摘要标题 - 四号,黑体,居中"""
 p = doc.add_paragraph()
 p.alignment = WD_ALIGN_PARAGRAPH.CENTER
 p.paragraph_format.line_spacing = Pt(18)
 p.paragraph_format.space_before = Pt(6)
 p.paragraph_format.space_after = Pt(6)
 
 run = p.add_run('摘要')
 set_run_font(run, chinese_font='黑体', font_size=Pt(14))
 
 def add_chinese_abstract_content(doc, abstract_text):
 """添加中文摘要内容 - 五号宋体,首行缩进2个汉字符"""
 p = doc.add_paragraph()
 p.paragraph_format.first_line_indent = Pt(21)
 p.paragraph_format.line_spacing = Pt(18)
 
 run = p.add_run(abstract_text)
 set_run_font(run, chinese_font='宋体', font_size=Pt(10.5))
 
 def add_chinese_keywords(doc, keywords):
 """添加中文关键词 - 标题加粗,内容五号宋体"""
 p = doc.add_paragraph()
 p.paragraph_format.line_spacing = Pt(18)
 
 
 run_title = p.add_run('关键词:')
 set_run_font(run_title, chinese_font='宋体', font_size=Pt(10.5), bold=True)
 
 
 run_content = p.add_run(keywords)
 set_run_font(run_content, chinese_font='宋体', font_size=Pt(10.5))
 
 def add_english_title(doc, text):
 """添加英文课题名称 - 小二号,Times New Roman,加粗,居中"""
 doc.add_page_break()
 doc.add_paragraph()
 
 p = doc.add_paragraph()
 p.alignment = WD_ALIGN_PARAGRAPH.CENTER
 p.paragraph_format.line_spacing = Pt(18)
 p.paragraph_format.space_before = Pt(6)
 p.paragraph_format.space_after = Pt(6)
 
 run = p.add_run(text)
 set_run_font(run, font_size=Pt(18), bold=True)
 doc.add_paragraph()
 
 def add_english_abstract_title(doc):
 """添加英文摘要标题 - 四号Times New Roman,居中"""
 p = doc.add_paragraph()
 p.alignment = WD_ALIGN_PARAGRAPH.CENTER
 p.paragraph_format.line_spacing = Pt(18)
 p.paragraph_format.space_before = Pt(6)
 p.paragraph_format.space_after = Pt(6)
 
 run = p.add_run('Abstract')
 set_run_font(run, font_size=Pt(14))
 
 def add_english_abstract_content(doc, abstract_text):
 """添加英文摘要内容 - 五号Times New Roman,首行缩进2个汉字符"""
 p = doc.add_paragraph()
 p.paragraph_format.first_line_indent = Pt(21)
 p.paragraph_format.line_spacing = Pt(18)
 
 run = p.add_run(abstract_text)
 set_run_font(run, font_size=Pt(10.5))
 
 def add_english_keywords(doc, keywords):
 """添加英文关键词 - 标题加粗,内容五号Times New Roman"""
 p = doc.add_paragraph()
 p.paragraph_format.line_spacing = Pt(18)
 
 
 run_title = p.add_run('Keywords: ')
 set_run_font(run_title, font_size=Pt(10.5), bold=True)
 
 
 run_content = p.add_run(keywords)
 set_run_font(run_content, font_size=Pt(10.5))
 
 def add_heading_1(doc, text, chapter_num=None):
 """添加1级标题 - 四号,黑体,居中"""
 doc.add_page_break()
 doc.add_paragraph()
 
 p = doc.add_paragraph()
 p.alignment = WD_ALIGN_PARAGRAPH.CENTER
 p.paragraph_format.line_spacing = Pt(18)
 p.paragraph_format.space_before = Pt(6)
 p.paragraph_format.space_after = Pt(6)
 
 if chapter_num:
 full_text = f"{chapter_num} {text}"
 else:
 full_text = text
 
 run = p.add_run(full_text)
 set_run_font(run, chinese_font='黑体', font_size=Pt(14))
 
 def add_heading_2(doc, text, section_num):
 """添加2级标题 - 五号,黑体,顶格"""
 p = doc.add_paragraph()
 p.paragraph_format.line_spacing = Pt(18)
 p.paragraph_format.space_before = Pt(6)
 p.paragraph_format.space_after = Pt(6)
 
 run = p.add_run(f"{section_num} {text}")
 set_run_font(run, chinese_font='黑体', font_size=Pt(10.5))
 
 def add_heading_3(doc, text, section_num):
 """添加3级标题 - 五号,黑体,缩进2个汉字符"""
 p = doc.add_paragraph()
 p.paragraph_format.first_line_indent = Pt(21)
 p.paragraph_format.line_spacing = Pt(18)
 p.paragraph_format.space_before = Pt(6)
 p.paragraph_format.space_after = Pt(6)
 
 run = p.add_run(f"{section_num} {text}")
 set_run_font(run, chinese_font='黑体', font_size=Pt(10.5))
 
 def add_paragraph_text(doc, text):
 """添加正文段落 - 五号,宋体,两端对齐,首行缩进2个汉字符"""
 p = doc.add_paragraph()
 p.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
 p.paragraph_format.first_line_indent = Pt(21)
 p.paragraph_format.line_spacing = Pt(18)
 
 run = p.add_run(text)
 set_run_font(run, chinese_font='宋体', font_size=Pt(10.5))
 
 def add_equation(doc, equation_text, chapter_num, eq_num):
 """添加公式 - 居中,五号宋体"""
 p = doc.add_paragraph()
 p.alignment = WD_ALIGN_PARAGRAPH.CENTER
 p.paragraph_format.line_spacing = 1.5
 
 
 run = p.add_run(equation_text)
 set_run_font(run, chinese_font='宋体', font_size=Pt(10.5), italic=True)
 
 
 run_num = p.add_run(f"\t({chapter_num}.{eq_num})")
 set_run_font(run_num, chinese_font='宋体', font_size=Pt(10.5))
 
 def add_table(doc, table_num, chapter_num, caption, data):
 """添加表格 - 采用三线表"""
 doc.add_paragraph()
 
 
 p_caption = doc.add_paragraph()
 p_caption.alignment = WD_ALIGN_PARAGRAPH.CENTER
 p_caption.paragraph_format.line_spacing = Pt(18)
 
 run = p_caption.add_run(f"表{chapter_num}.{table_num} {caption}")
 set_run_font(run, chinese_font='宋体', font_size=Pt(9))
 
 
 rows, cols = len(data), len(data)
 table = doc.add_table(rows=rows, cols=cols)
 table.style = 'Table Grid'
 
 
 for i, row_data in enumerate(data):
 for j, cell_text in enumerate(row_data):
 cell = table.cell(i, j)
 cell.text = str(cell_text)
 p = cell.paragraphs
 p.alignment = WD_ALIGN_PARAGRAPH.CENTER
 p.paragraph_format.line_spacing = Pt(18)
 
 for run in p.runs:
 set_run_font(run, chinese_font='宋体', font_size=Pt(9))
 if i == 0:
 run.bold = True
 
 doc.add_paragraph()
 
 def add_figure(doc, fig_num, chapter_num, caption):
 """添加图片占位符和图题"""
 doc.add_paragraph()
 
 
 p_placeholder = doc.add_paragraph("[--- 在此插入图片 ---]")
 p_placeholder.alignment = WD_ALIGN_PARAGRAPH.CENTER
 
 
 p_caption = doc.add_paragraph()
 p_caption.alignment = WD_ALIGN_PARAGRAPH.CENTER
 p_caption.paragraph_format.line_spacing = Pt(18)
 
 run = p_caption.add_run(f"图{chapter_num}.{fig_num} {caption}")
 set_run_font(run, chinese_font='宋体', font_size=Pt(9))
 
 doc.add_paragraph()
 
 def add_sub_item(doc, text, item_type='number', level=1):
 """添加三级以下标题或段落号
 item_type: 'number' for (1), 'letter_upper' for A., 'letter_lower' for a., 'circle' for ①
 """
 p = doc.add_paragraph()
 p.paragraph_format.first_line_indent = Pt(21)
 p.paragraph_format.line_spacing = Pt(18)
 
 if item_type == 'number':
 prefix = f"({level})"
 elif item_type == 'letter_upper':
 prefix = f"{chr(64 + level)}."
 elif item_type == 'letter_lower':
 prefix = f"{chr(96 + level)}."
 elif item_type == 'circle':
 prefix = f"①②③④⑤⑥⑦⑧⑨⑩"[level-1] if level <= 10 else f"({level})"
 
 run = p.add_run(f"{prefix} {text}")
 set_run_font(run, chinese_font='黑体', font_size=Pt(10.5))
 
 def add_references(doc, references):
 """添加参考文献"""
 add_heading_1(doc, "参考文献")
 
 for i, ref in enumerate(references, 1):
 p = doc.add_paragraph()
 p.paragraph_format.line_spacing = Pt(18)
 
 run = p.add_run(f"[{i}] {ref}")
 set_run_font(run, chinese_font='宋体', font_size=Pt(10.5))
 
 
 
 
 
 if __name__ == "__main__":
 
 doc = Document()
 set_document_defaults(doc)
 
 
 add_chinese_title(doc, "轨道交通设施设备电气参数高精度采集与服役状态智能感知技术")
 
 
 add_chinese_abstract_title(doc)
 add_chinese_abstract_content(doc,
 "本研究针对轨道交通设施设备电气参数采集精度不高、状态监测不够智能的问题,"
 "提出了一种基于宽频段高精度采集技术的智能感知方案。通过集成11种传统采集器功能,"
 "实现了对电气参数的精准监测和服役状态的智能评估。实验结果表明,该技术能够有效"
 "提高采集精度和监测效率,为轨道交通的安全运营提供了可靠保障。本研究的创新点在于"
 "将多种采集功能集成到单一设备中,大大简化了系统结构,降低了维护成本。")
 
 
 add_chinese_keywords(doc, "轨道交通,电气参数,高精度采集,智能感知,状态监测")
 
 
 add_english_title(doc,
 "High-Precision Acquisition and Intelligent Perception Technology for "
 "Electrical Parameters and Service Status of Rail Transit Facilities")
 
 
 add_english_abstract_title(doc)
 add_english_abstract_content(doc,
 "This study addresses the issues of low precision in electrical parameter "
 "acquisition and insufficient intelligence in condition monitoring of rail "
 "transit facilities. A intelligent perception scheme based on wide-band "
 "high-precision acquisition technology is proposed. By integrating 11 "
 "traditional collector functions, accurate monitoring of electrical parameters "
 "and intelligent assessment of service status are achieved.")
 
 
 add_english_keywords(doc, "rail transit, electrical parameters, high-precision acquisition, intelligent perception, condition monitoring")
 
 
 add_heading_1(doc, "绪论", "1")
 
 
 add_heading_2(doc, "研究背景与意义", "1.1")
 add_paragraph_text(doc,
 "随着我国轨道交通事业的快速发展,对设施设备运行状态的实时监测和智能评估"
 "提出了更高的要求。传统的监测方法存在采集精度低、响应速度慢、智能化程度"
 "不高等问题,难以满足现代轨道交通安全运营的需求。")
 
 
 add_heading_3(doc, "国内外研究现状", "1.1.1")
 add_paragraph_text(doc,
 "近年来,国内外学者在轨道交通电气参数监测方面开展了大量研究工作。"
 "专利CN109142844B集成了11种传统采集器功能,通过宽频段高精度采集技术"
 "实现了电气参数的精准监测。")
 
 
 add_equation(doc, "P = U × I × cosφ", 1, 1)
 
 
 add_sub_item(doc, "采集精度提高到0.1%", 'number', 1)
 add_sub_item(doc, "响应时间缩短至10ms", 'number', 2)
 add_sub_item(doc, "支持多通道同步采集", 'number', 3)
 
 
 add_paragraph_text(doc, "系统具有以下特点:")
 add_sub_item(doc, "高精度采集能力", 'circle', 1)
 add_sub_item(doc, "实时数据处理", 'circle', 2)
 
 
 table_data = [
 ["参数名称", "传统方法", "本文方法", "提升幅度"],
 ["采集精度", "1%", "0.1%", "90%"],
 ["响应时间", "100ms", "10ms", "90%"],
 ["通道数量", "4", "16", "300%"]
 ]
 add_table(doc, 1, 1, "技术参数对比", table_data)
 
 
 add_figure(doc, 1, 1, "系统架构示意图")
 
 
 references_list = [
 "张三, 李四. 轨道交通电气参数监测技术研究[J]. 中国铁道科学, 2023, 44(2): 15-22.",
 "Wang X, Liu Y. High-precision data acquisition system for railway applications[J]. "
 "IEEE Transactions on Industrial Electronics, 2022, 69(5): 4521-4530.",
 "王五, 赵六. 基于物联网的轨道交通智能监测系统设计[J]. 铁道学报, 2023, 45(3): 88-95.",
 "Johnson M, Smith K. Intelligent condition monitoring in rail transit systems[J]. "
 "Transportation Research Part C, 2021, 128: 103-115.",
 "陈七. 城市轨道交通供电系统状态监测与故障诊断[M]. 北京: 科学出版社, 2022.",
 "李八, 周九. 轨道交通设备全生命周期管理技术[J]. 城市轨道交通研究, 2023, 26(4): 45-52.",
 "Brown A. Advanced sensor technologies for railway infrastructure monitoring[J]. "
 "Sensors and Actuators A: Physical, 2022, 335: 113-125.",
 "钱十, 孙十一. 基于大数据的轨道交通设备健康评估方法[J]. 交通运输工程学报, 2023, 23(2): 178-186.",
 "Taylor R, Anderson P. Machine learning applications in railway predictive maintenance[J]. "
 "Expert Systems with Applications, 2023, 213: 118-132.",
 "郑十二. 智能轨道交通系统关键技术研究进展[J]. 中国科学: 技术科学, 2023, 53(6): 891-905."
 ]
 add_references(doc, references_list)
 
 
 doc.save("学术论文格式化文档.docx")
 print("文档已保存为: 学术论文格式化文档.docx")
 
 |