简体   繁体   English

Openpyxl:将图表另存为工作表

[英]Openpyxl: Save Chart As Sheet

Wondering if there is a way or workaround to save a chart as a sheet using Openpyxl? 想知道是否存在使用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. 这将在2.3版本中实现。 If you need the functionality now you will need to use a checkout of the 2.3 branch and build the docs yourself. 如果您现在需要此功能,则需要使用2.3分支的签出并自己构建文档。

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

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