简体   繁体   中英

Openpyxl: Save Chart As Sheet

Wondering if there is a way or workaround to save a chart as a sheet using Openpyxl?

I've been able to create the charts and place them within a sheet at a specific location:

from openpyxl import Workbook, load_workbook
from openpyxl.chart import LineChart, Reference

def create_chart(worksheet):
    chart = LineChart()
    chart.title = "My Line Chart"
    data = Reference(workbook['Data'], min_col=8, min_row=3, max_row=10, max_col=11)
    categories = Reference(workbook['Data'], min_col=7, min_row=3, max_row=10, max_col=7)
    chart.add_data(data)
    chart.set_categories(categories)
    worksheet.add_chart(chart, 'A1')

Is there a way I could change that last line to send it to a full sheet? Or increase the size?

What you want is called a "chartsheet". This will be possible in the 2.3 release. If you need the functionality now you will need to use a checkout of the 2.3 branch and build the docs yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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