2012-04-05 17 views
0

Ich habe das Diagramm mit PYCHART erstellt, aber die Ausgabe kommt in Form von Pdf/Png/PS etc .. aber ich brauche diese Tabelle sollte in die Excel kommen Blatt. Wie kann dieses Diagramm in ein Arbeitsblatt extrahiert werden?wie man das Diagramm/Diagramm zu Arbeitsblatt/excelsheet mit Python

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

Antwort

2

Versuchen zu verwenden win32com Paket

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

Ändern Sie dann das Diagramm, wie Sie

+0

Danke für die Informationen wünschen, habe ich versucht, win32 zu installieren und den Code gestartet, aber seine schenkt Fehler> >> Import win32com.client >>> xl = win32com.client.Dispatch ("Excel.Application") Traceback (jüngste Aufforderung zuletzt): File "" Linie 1 in Datei "c: \ Python27 \ DLLs \ win32com \ client \ __ init__.py", Zeile 95, in Dispatch hAndUserName return (_GetGoodDispatch (IDispatch, clsctx), Benutzername) Datei "c: \ Python27 \ DLLs \ win32com \ client \ dynamic.py ", Zeile 72, in _GetGoodDispat was ist das Problem hier bitte hilf mir –

+0

Danke Maksym, Es funktioniert, Danke für die Unterstützung –

+0

@Shashi Also akzeptiere die Antwort bitte :-) –

Verwandte Themen