【发布时间】:2011-10-20 04:57:12
【问题描述】:
我需要允许用户编辑和打印与客户相关的文档(发票和其他)。
用户填写打印表格(选择客户、月份、他/她需要的 4 种文件中的每一种文件的份数)并点击打印按钮。
接下来我的系统应该做的(算法):
result = create new word-friendly file # because user may manually edit it later
for client in form_clients:
snapshot = select row in snapshots table
where client == client and month == form_month
document1 = generate_from_template(snapshot, tpl1.docx)
for 1 to form_how_much_copies_of_1_type_of_document_he_or_she_needs:
result += document1
document2 = generate_from_template(snapshot, tpl2.docx)
for 1 to form_how_much_copies_of_2_type_of_document_he_or_she_needs:
result += document2
document3 = generate_from_template(snapshot, tpl3.docx)
for 1 to form_how_much_copies_of_3_type_of_document_he_or_she_needs:
result += document3
document4 = generate_from_template(snapshot, tpl4.docx)
for 1 to form_how_much_copies_of_4_type_of_document_he_or_she_needs:
result += document4
print result
要求:
- 能够编辑结果(需要文字格式)
- 分页符(新页面上的每个文档)
- 表格,不是很简单,看invoice tpl例子:
- 字体大小和样式(例如粗体)
- 保存文本位置
我的问题是如何生成这个文件(结果)? 有https://github.com/mikemaccana/python-docx 项目,但不确定它是否可以与模板一起使用(或者至少根据需要生成表)... 或者我可以将我所有的 .docx 模板保存为 html 并将它们用作普通的 django 模板,但不知道如何将它们组合到一个文档中并创建分页符...... 或者我应该看看另一种与单词兼容的文件格式?...
附言更好地使用 python 但它并不重要,我可以使用 java/perl/ruby/php/bash/etc.. 并安装任何新的 Ubuntu 兼容包...
【问题讨论】: