我使用pychart创建了图表,但输出的格式为pdf / png / ps等。但是我需要这些图表应该进入Excel工作表。将此图表提取到工作表的方法是什么?
from pychart import *
import sys
def to_percents(data):
total = float(sum(v for _, v in data))
data[:] = [(k, v / total) for k, v in data]
return data
data = [("foo", 10),("bar", 20), ("baz", 30), ("ao", 40)]
theme.use_color = True
theme.get_options()
ar = area.T(size=(150,150), legend=legend.T(),
x_grid_style = None, y_grid_style = None)
plot = pie_plot.T(data=data, arc_offsets=[0,0,0,0],
shadow = (0, 0, fill_style.gray50),
label_offset = 25,
arrow_style = arrow.a3)
ar.add_plot(plot)
ar.draw()
答案 0 :(得分:2)
尝试使用win32com软件包
from win32com import client
excel=client.Dispatch("Excel.Application")
excel.Visible=True
book=excel.Workbooks.Open("myfile.csv", False, True)
sheet=book.Worksheets(1)
chart=book.Charts.Add()
然后,根据需要修改图表