简体   繁体   English

使用Openpyxl更新Excel模板导致图表不再显示数据表

[英]Using Openpyxl to update an Excel Template results in Chart no longer displaying data table

I am updating the data behind a chart using Openpyxl. 我正在使用Openpyxl更新图表背后的数据。 When I update the data and save the template as a new file, the excel chart that is created from that data seems to lose its formatting, specifically the data table attached. 当我更新数据并将模板另存为新文件时,从该数据创建的Excel图表似乎丢失了其格式,特别是附加的数据表。

I have already tried checking and unchecking "Properties follow chart data point for current / all new workbook(s). 我已经尝试检查和取消选中“针对当前/所有新工作簿的属性遵循图表数据点。

I expect the chart to have the same format as the original excel template. 我希望图表具有与原始excel模板相同的格式。 In this case, the lines on the graph are updated, but the data table underneath the graph disappears. 在这种情况下,图形上的线会更新,但是图形下方的数据表会消失。

Below is my openpyxl snippet, though it probably won't be useful. 下面是我的openpyxl代码段,尽管它可能不会有用。 All I am doing is updating cell values in a loop. 我要做的就是循环更新单元格值。

    for i in range(0, 12):
        ws_S_EPE['D{}'.format(i+36)] = pr['Energy'][i] / 1000
        ws_S_EPE['E{}'.format(i+36)] = pr['pr'][i]
        ws_S_EPE['F{}'.format(i+36)] = pr_tc['pr_tc'][i]

Here are picture of the graph in the template and the file created from the template. 这是模板中的图形图片以及从模板创建的文件。

在模板中 Openpyxl之后的模板

I have similiar issues with openpyxl. 我对openpyxl有类似的问题。 After saving a file the chart format is changed, and text boxes are deleted (see link). 保存文件后,将更改图表格式,并删除文本框(请参见链接)。

truncate, copy from one xlsx and paste to another with openpyxl: messes up all text boxes, charts etc 截断,从一个xlsx复制并使用openpyxl粘贴到另一个:弄乱所有文本框,图表等

No hints here? 这里没有提示吗?

PS: Ah, I see, preserving charts in existing files hasn't been included yet in openpyxl. PS:嗯,我知道,openpyxl中尚未包含在现有文件中保留图表的功能。 Pity! 可怜!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM