python - 如何使用 openpyxl 将数据动态添加到现有图表中
问题描述
当新数据使用openpyxl进入excel时,我正在尝试将数据动态添加到现有折线图中。下面是我尝试过的示例代码但是当遇到其他部分时,图表没有变化。谢谢
from openpyxl import load_workbook
from openpyxl.chart import (LineChart, Reference)
wb = load_workbook("Hello.xlsx")
sheet = wb.active
exists = 0
chart = LineChart()
if exists == 1:
values = Reference(sheet, min_col=3, min_row=1, max_row=sheet.max_row)
categories = Reference(sheet, min_col=1, min_row=2, max_row=sheet.max_row,max_col=1)
chart.add_data(values, titles_from_data=True)
chart.set_categories(categories)
chart.title = "sample"
chart.x_axis.title = "date"
chart.y_axis.title = "followers"
sheet.add_chart(chart, "F2")
else:
values_update = Reference(sheet, min_col=3, min_row=1, max_row=sheet.max_row)
chart.add_data(values_update)
wb.save("Hello.xlsx")
解决方案
推荐阅读
- ruby-on-rails - Rails 向其他容器发送请求 [无法打开 TCP 连接]
- javascript - Javascript Web 音频 API - AudioContext 到 base64
- javafx - Java FX - 当节点到达 0 时重置节点的 translateX 和 translateY
- python - 为什么 Python 中的多个复合语句不能在一行中?
- presto - 从 Alluxio 读取超时
- mysql - MYSQL 查找最常见的值
- hugo - 在 hugo 的部分列表中使用无头页面
- apache - 如何在 apache tomcat server 8.0 中配置 proxypass 和 proxyreverse pass?
- c# - 以小数返回 DateTime.Now
- java - 从 Weblogic 10 升级到 Weblogic 12c EJBException NoClassDefFoundError for weblogic/webservice/core/rpc/ServiceImpl