基于模板,Python3 生成带图的文档 [英] Generate document with plots based on template, Python3

查看:25
本文介绍了基于模板,Python3 生成带图的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Python3 GUI,用户可以在其中选择某些值进行统计评估和/或绘制(历史).

I have a Python3 GUI, where user selects certain values to be statistically evaluated and/or plotted (hist).

根据用户的要求,我想用这个 GUI 创建一个报告,最好是 DOC 或/和 ODT 或/和 PDF 格式.报告的布局几乎是固定的,将改变的是:所选度量的名称和相应的值(始终显示三个度量 - 用户选择哪个),matplotlib 直方图(将根据所选设置而变化)、用户名、日期等

Out of this GUI on users request I want to create a report, prefferebly in DOC or/and ODT or/and PDF formats. The layout of the report is pretty much fixed, what will change is: the names of the selected measures and the corresponding values (there are always three measures to display - user selects which), matplotlib histogram (will change depending on the selected settings), user name, date etc.

在一些较旧的线程中,我找到了对 pod 包的引用,它看起来非常符合我的需求.但是我没有找到任何关于结果文件的好的说明.最重要的是,我不确定那里是否允许使用图像 - 我想在文档的某个角落为图像保留一个位置,并在用户请求报告时更新它.

In some older thread I found a reference to pod package which looks very close to my needs. But I didn't find any good illustration of the resulting documents. And what is most important, I'm not sure if images are allowed there - I would imagine reserving a place for the image somewhere in the corner of the document and update it when user request the report.

EDIT1:pod 不支持 Python3,在 2to3 转换和几个小修复.有一个使用 LaTeX 的建议,但我不确定我是否理解如何在不进行非常低级编码的情况下实现这个想法.

EDIT1: pod does NOT support Python3, also after 2to3 convertion and couple of small fixes. There was an advice to use LaTeX, but I'm not sure I understand how to implement this idea without going to the very low level of coding.

非常感谢任何建议,因为项目的其余部分几乎完成,这是最后一个未解决的大问题.

Any suggestions are greatly appreciated since the rest of the project is nearly done and this is the last big unsolved problem.

EDIT2:休息一段时间后,我又回到了这个问题.由于我的 GUI 在 PyQt4 中,我最终决定使用 QTextDocument 并将文档打印为 PDF.在这种方法中,我有一些不清楚的地方,比如我是否应该使用 QTextCursor 并以编程方式创建文档或首先创建某种 HTML.另外,我必须弄清楚如何在不显示编辑器窗口的情况下创建文档.欢迎任何带有示例的参考.到目前为止,我在 PyQt4\examples\richtext 中只找到了几个例子,但它们并没有回答我所有的问题.

EDIT2: After some break I return to this problem. Since my GUI is in PyQt4, I finally decided to go with QTextDocument and print document to PDF. There are some unclear moments for me in this approach, like if I should use QTextCursor and programically create the document or create somehow HTML first. Also, I have to figure out how to create the document without displaying editor window. Any references with examples are welcome. So far I found only couple of examples in PyQt4\examples\richtext, but they don't answer all my questions.

推荐答案

终于解决了问题.最后并没有那么困难,我最终使用 QTextDocument 及其 setHtml 方法来生成所需的文档.与代码相关的问题是这里

Finally solved the problem. It was not so difficult at the end, and I ended up using QTextDocument and its setHtml method to produce the desired document. Related question with the code is here

这篇关于基于模板,Python3 生成带图的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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