Python - docx-merge -- 需要从access db添加多行到目录参考书目列表词模板

问题描述

对于我正在做的事情,我想知道 docx-merge 是否可以写入目录单词模板。我基本上需要从导入的访问数据库中编写多行列表。我能够将一个测试行写出到单一类型的单词合并模板中。我在 https://pbpython.com/python-word-template.html?fbclid=IwAR2zGuejsyKhYLzXVCPi_kw-udlva_NN2Dbff0UC-UPEy5UmR8Iqx54yI1A

找到了这个

没有关于列表类型文档的内容。现在,我只是将这些写到一个看起来像这样的文本文件中。 ID 和年份以及参考和超链接从新行开始,单独的项目之间有一个空行。非常感谢您对此的任何帮助。我对其他一些应用程序有很多想法,我将分享我的发现。 (每个人也应该尝试一下yerba mate“tea”和康普茶。)

1 2020年 Howard,C. M.、Hu,R. 和 Falconer,J.(2020 年)。分享故事:对教授识字身份和信仰的反思。网络:教师研究在线期刊,22(3)。 #https://doi.org/10.4148/2470-6353.13177#

2 2014年 万豪,C. E. (2014)。只是想知道:调查的开始。知识探索,43(2),74-76。

3 2018年 理查兹-巴斯 (2018)。结合批判性思维:诊断成像教育的教学策略。学位论文 @ northcentral University - ProQuest

`

稍后添加 - 我让它起作用了 - 它并不完美,代码也很古怪,但现在确实可以使用!希望这可以帮助任何正在尝试做类似事情的人。

这是我添加代码

for i in merge_lst:
#print(cnt)

cnt += 1
if len(i) > 0:
   temp_val = i.split("!####!")
   #print(temp_val)
   id_str = temp_val[0]
   year_str = temp_val[1]
   r_str = temp_val[2]
   h_str = temp_val[3]
     
   #additional work on r_str 
   r_str = func_remove_char(r_str,"!#@@@@@#!")

   temp_str = "'ID': '{}','Year': '{}','Reference': '{}','hyperlink': '{}'"
   new_str = temp_str.format(id_str,year_str,r_str,h_str)
   
   temp_str = "row_{} = !xx!{}!xxx!"
   merge_str = temp_str.format(cnt-1,new_str)     
   new_str = merge_str.replace("!xx!","{")
   merge_str = new_str
   new_str = merge_str.replace("!xxx!","}")
   exec(new_str)
   
   print(new_str)
   
   if cnt <= 2:
      template_list = new_str
      tlist = "row_1"
   else:
      template_list = template_list + new_str
      temp_str = "row_{}"
      temp_str = temp_str.format(cnt-1)
      tlist = tlist + "," + temp_str

#print(tlist) # row_1,row_2,row_3

template = ("H:\\new test template.docx")       
document = MailMerge(template)
temp_str = "document.merge_templates([{}],separator='textwrapping_break')"
merge_str = temp_str.format(tlist)

print(merge_str)
exec(merge_str)

filename = "h:\\nt_template.docx"
document.write(filename)

这是它在 word 中的外观 - 有一个“page_break”将它们分成不同的页面,但我只需要一个空行,所以我会尝试查看是否有设置,但现在就可以了.

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)