Python Forum
Openpyxl overwrite Linechart
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Openpyxl overwrite Linechart
#1
Hi All,
Is there any way to overwrite linechart in excel?It get more chart in excel during running *.Py code. Please refer to attachment file.
If have a way to delete exist chart and then run code once get a new chart, thanks in advance!



import openpyxl
from openpyxl.chart import Reference, LineChart, Series

wb = openpyxl.load_workbook('wb2.xlsx')
sheet = wb.active

# Data for plotting
# Choose all the data from Column 2 to 4
values = Reference(sheet,
                   min_col=2,
                   max_col=10,
                   min_row=1,
                   max_row=38)

# Create object of LineChart class
chart = LineChart()
chart.add_data(values, titles_from_data=True)
# set the title of the chart
chart.title = "Analysis Stock prices"
# set the title of the x-axis
chart.x_axis.title = "Date"

# set the title of the y-axis
chart.y_axis.title = "Stock Value"

# the top-left corner of the chart
# is anchored to cell F2 .
sheet.add_chart(chart,"F2")

# save the file
wb.save("wb2.xlsx")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Openpyxl make LineChart SamLiu 0 1,311 Nov-22-2022, 06:54 AM
Last Post: SamLiu
  Overwrite previous live data. Makada 2 2,304 Nov-07-2020, 07:40 PM
Last Post: Makada
  How to overwrite file SriRajesh 3 6,257 Apr-14-2020, 12:57 PM
Last Post: steve_shambles
  Dict overwrite previous list vincentspm 1 2,185 Mar-20-2019, 12:31 PM
Last Post: scidam
  overwrite data using openpyxl BNB 0 10,534 Jun-21-2017, 11:31 AM
Last Post: BNB

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020