如何:使用带有django / python的模板创建.doc文件(How to: create .doc files using templates with django/python)

编程入门 行业动态 更新时间:2024-10-26 20:25:22
如何:使用带有django / python的模板创建.doc文件(How to: create .doc files using templates with django/python)

我正在写一个django应用程序,有一些我不知道该怎么做。 假设您有一个包含用户的数据库和几个您可能想要发送给这些用户的.doc文件(邮政信件,而不是电子邮件)。 我想知道是否有办法使用我的用户数据库从模板中自动创建这些字母来填写一些标记? (即姓名,地址等)

我听说过“pod”python库,但我从未使用它。 文档似乎说使用openoffice模板,但我的是MS Word格式。 由于它们经常由仅使用MS Office的人更新,因此我被卡住了。

任何帮助,将不胜感激。

J.

I am writing a django application and there is something I don't know how to do. Say you have a database with users and several .doc files you might want to send to those users (postal letters, not electronicaly). I am wondering if there is a way to automatically create those letters from templates using my user database to fill in some markers? (i.e. name, address, etc.)

I've heard of the "pod" python library but I've never used it. The documentation seems to say to use openoffice templates, but mine are in MS Word format. Since they are often updated by people who only use MS Office, I'm stuck.

Any help would be appreciated.

J.

最满意答案

根据具体情况,有许多不同的方法可以做到这一点。 这里有一些想法,按难度的降序排列。

Microsoft Word包含一个名为Mail Merge的工具 。 您可以使用COM钩子通过安装pywin32从Python控制Word。 这与通过打开Microsoft Word调用邮件合并完全相同。 这必须在安装了Office的Windows计算机上完成,可能不是您的服务器。 请参阅http://bytes.com/topic/python/answers/165364-ms-word-mail-merge-automation或Google“python mail merge”。

OpenOffice使用Python作为宏语言(我相信)并使用Python-UNO公开API。 您可以使OpenOffice将文件转换为其格式,然后使用pod执行邮件合并。

您可以告诉用户以更好的格式为您提供数据,例如OpenOffice模板。

您可以 Django导出用户的数据,将其提供给编写模板的人员,并告诉他们自己进行邮件合并。

无论你选择什么,这都不容易。

There are many different ways to do this, depending on the context. Here are some ideas, ranked in decreasing order of difficulty.

Microsoft Word includes a facility for this, called Mail Merge. You can control Word from Python using COM hooks, by installing pywin32. This would do exactly the same as invoking Mail Merge by opening up Microsoft Word. This would have to be done on a Windows computer with Office installed, probably not your server. See http://bytes.com/topic/python/answers/165364-ms-word-mail-merge-automation, or Google "python mail merge".

OpenOffice uses Python as a macro language (I believe) and exposes an API using Python-UNO. You could make OpenOffice convert the files in to its format, and then use pod to perform the mail merge.

You could tell your users to give you data in a better format, such as OpenOffice templates.

You could export the users' data from Django, give it to the people writing the templates, and tell them to do their own mail merge.

Whatever you choose, this will not be easy.

更多推荐

本文发布于:2023-08-04 07:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1412405.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   文件   django   python   doc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!