输出Python到Word Documen

2024-09-27 07:31:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在跟踪那些无聊的事情。你知道吗

这个问题跟在我之前的两个问题之后:

Iterate a Nested Dictionary in Python

Iterate Dictionary in Python and Sum Totals by Category

我一直在使用ATBS中使用的方法将python代码中的一些数据打印到word文档中。以下是如何设置的片段:

dataFile = open('stocks.py', 'w') wordFile = open('stocks.doc', 'w') dataFile.write('allData = ' + pprint.pformat(stockData)) wordFile.write(pprint.pformat(sectors))
我的问题是双重的。首先,我有一个名为'sectors'的字典,其中包含一个带有'percentage'值的键'sector'。我想把它输出到word中的一个表中,如下所示:

技术30% 医疗保健20% 财务30%

但我发现通过pprint方法并不容易。有什么好办法吗?你知道吗

我的第二个问题是,有没有更好的方法?我知道ATBS是一种使用python的新手方式,但我愿意尝试一种更好的方式,使用python在excel中分析数据,然后在Word中生成自动报告。你知道吗


Tags: 数据方法indictionaryopenwordwritepprint

热门问题