0

I have created the chart using pychart but the output is coming in the form of pdf/png/ps etc .. but i need these chart should come into the excel sheet. what is the way to extract this chart to worksheet.

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()

1 Answers1

2

Try to use win32com package

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()

Then, modify the chart as you wish

Maksym Polshcha
  • 18,030
  • 8
  • 52
  • 77
  • Thanks for the information ,I tried to install win32 and started the code but its is giving error >>> import win32com.client >>> xl= win32com.client.Dispatch("Excel.Application") Traceback (most recent call last): File "", line 1, in File "c:\Python27\DLLs\win32com\client\__init__.py", line 95, in Dispatch hAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "c:\Python27\DLLs\win32com\client\dynamic.py", line 72, in _GetGoodDispat what is the problem here please help me – Shashikant Vasudev Pattar Apr 05 '12 at 09:26