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

查看:151
本文介绍了如何:使用带有django/python的模板创建.doc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.)

我听说过"pod" python库,但从未使用过.该文档似乎说要使用openoffice模板,但是我的文档是MS Word格式.由于它们通常是由仅使用MS Office的人更新的,因此我很困惑.

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.

任何帮助将不胜感激.

J.

推荐答案

有许多不同的方法可以执行此操作,具体取决于上下文.这里有一些想法,按照难度从小到大的顺序排列.

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使用Python作为宏语言(我相信),并使用 Python-UNO .您可以使OpenOffice将文件转换为其格式,然后使用 pod 来执行邮件合并.

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.

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

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

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

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.

这篇关于如何:使用带有django/python的模板创建.doc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆