更改chart数据源指向
import openpyxl
import copy
from openpyxl.chart import Reference
wb = openpyxl.load_workbook("")
last_sheet = wb[wb.sheetnames[-1]]
new_sheet = copy.deepcopy(last_sheet)
chart = new_sheet ._charts[0]
chart.ser = []
data = Reference(worksheet=new_sheet , min_row=2, max_row=8, min_col=2, max_col=3)
cat = Reference(worksheet=new_sheet , min_row=3, max_row=8, min_col=1, max_col=1)
chart.add_data(data, titles_from_data=True)
chart.set_categories(cat)
chart.ser.marker = openpyxl.chart.marker.Marker(symbol='triangle', size=7)
chart.ser.graphicalProperties.line.width = 30000
chart.ser.graphicalProperties.line.solidFill = "FF0000"
chart.ser.marker.graphicalProperties.solidFill = "FF0000"
chart.ser.marker.graphicalProperties.line.solidFill = "FF0000"
chart.dLbls.showVal = True
excel._sheets.append(new_sheet)
excel.save('')