基于模板、Python3 生成带有绘图的文档

发布于 2025-01-05 06:01:28 字数 869 浏览 1 评论 0原文

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

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

在一些较旧的线程中,我发现了对 pod 包的引用,它看起来非常接近我的需要。但我没有找到生成的文档的任何很好的说明。最重要的是,我不确定那里是否允许使用图像 - 我想在文档的一角为图像保留一个位置,并在用户请求报告时更新它。

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

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

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

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

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神魇的王 2025-01-12 06:01:28

我现在尝试查看 ReportLab - 它不提供 DOC(仅 PDF),但似乎很灵活。据我从常见问题解答中了解到,允许使用图像,但我必须首先将它们从 matplotlib 中保存为 jpeg(PIL 尚不适用于 Python3)。我希望我不会最终以极低级的编程来创建报告......

I try to look at ReportLab now - it doesn't provide DOC (only PDF), but seems to be flexible. As I learned from FAQ, images are allowed, but I will have to save them from matplotlib in jpeg first (PIL is not available for Python3 yet). I hope I will not end up with extreme low level programming for report creation...

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文