Problem beim Exportieren mit Ole in Excel...
-
Hallo zusammen,
ich möchte eine Exceldatei öffnen und aus den Werten ein Diagramm machen. Jetzt habe ich gelesen, dass man jede Funktion von Excel auch mit Ole anwenden kann. Das mit dem Öffnen geht, das Makieren der Spalte auch, nur das mit dem Diagramm aufrufen nicht.Ich habe erst im Excel ein Makro erstellt und dann im Microsoft Visual Basic geöffnet. Sieht so aus...
Sub Diagram() ' ' Diagram Makro ' Makro am 06.04.2005 von Magic Man aufgezeichnet ' ' Tastenkombination: Strg+d ' Columns("A:A").Select Charts.Add ActiveChart.ChartType = xlColumnClustered ActiveChart.SetSourceData Source:=Sheets("Tabelle1").Range("A1:A6"), PlotBy _ :=xlColumns ActiveChart.Location Where:=xlLocationAsObject, Name:="Tabelle1" With ActiveChart .HasTitle = False .Axes(xlCategory, xlPrimary).HasTitle = False .Axes(xlValue, xlPrimary).HasTitle = False End With End Sub... nun habe ich versucht, die Funktionen im BCB zu übernehmen und bin beim Chart erstmal gestrandet.

Sieht so aus...
void __fastcall TForm1::Button4Click(TObject *Sender) { Variant Excel; Excel = Variant::CreateObject("Excel.Application"); Excel.OlePropertyGet("ActiveWorkBook"); // Excel-Datei öffnen Excel.OlePropertyGet("WorkBooks").OleFunction("Open",Path.c_str()); // Sichbar machen Excel.OlePropertySet("Visible",1); Variant Sheet; Sheet=Excel.OlePropertyGet("ActiveSheet"); Sheet.OlePropertyGet("Columns",1).OleFunction("Select"); Sheet.OleFunktion("Charts.Add"); /* ; ActiveChart.ChartType = xlColumnClustered ActiveChart.SetSourceData Source:=Sheets("Tabelle1").Range("A1:A6"), PlotBy _ :=xlColumns ActiveChart.Location Where:=xlLocationAsObject, Name:="Tabelle1" With ActiveChart .HasTitle = False .Axes(xlCategory, xlPrimary).HasTitle = False .Axes(xlValue, xlPrimary).HasTitle = False End With */ }...kann mir einer helfen?

-
Ich habe folgenden Teilerfolg:
Ich kann ein Diagramm öffnen habe aber Probleme mit dem übergeben von Werten.
Variant Sheet; Sheet=Excel.OlePropertyGet("ActiveSheet"); Sheet.OlePropertyGet("Columns",1).OleFunction("Select"); Variant Chart; Chart= Variant::CreateObject("Excel.Chart"); Chart.OlePropertyGet("ActiveChart").OleFunction("SetSourceData Source:=Sheets(Tabelle1).Range(A1:A6)");
-
Kann mir den keiner Helfen?????

-
Ist zwar etwas spät, aber da ich das selber mal gesucht und nicht gefunden hab, schreib ich es mal trotzdem noch rein.
Alle Variablen die mit "v" anfangen sind vom Typ Variant und sind teilweise in der .h definiert.
Alle Werte aus dem VB-Code müssen allgemein daraufhin überprüft werden, ob sie Equals sind, z.B. Punktdiagramm == -4169. Die Originalwerte erhält man im VB über rechte Maus->Objektkatalog.//Diagramm einfügen
vWorkBooks = vExcel.OlePropertyGet( "Charts" );
vWorkBooks.OleFunction("Add");
vDiagramm = vExcel.OlePropertyGet("ActiveChart");
vDiagramm.OlePropertySet("Name","Diagramm_BGL");
vDiagramm.OlePropertySet("ChartType",-4169);//
//Daten hinzufügen//ActiveChart.SeriesCollection.NewSeries
series = vDiagramm.OlePropertyGet("SeriesCollection");
series.OleProcedure("NewSeries");
//1.Reihe(X-Werte:A1 bis A10; Y-Werte: B1 bis B10)
vDiagramm.OlePropertyGet("SeriesCollection",1).OlePropertySet("Xvalues",vWorkSheet.OlePropertyGet("Range",
vWorkSheet.OlePropertyGet("Cells",1,1),vWorkSheet.OlePropertyGet("Cells",10,1)));
vDiagramm.OlePropertyGet("SeriesCollection",1).OlePropertySet("Values",vWorkSheet.OlePropertyGet("Range",
vWorkSheet.OlePropertyGet("Cells",1,2),vWorkSheet.OlePropertyGet("Cells",10,2)));//Reihe formatieren
Variant Reihe1 = vDiagramm.OlePropertyGet("SeriesCollection",1) ;
Reihe1.OlePropertySet("MarkerBackgroundColorIndex",3);
Reihe1.OlePropertySet("MarkerForegroundColorIndex",3);
Reihe1.OlePropertySet("MarkerStyle",8);
Reihe1.OlePropertySet("Name","CH_0");//Diagramm gestalten
//Diagramm-Allgemein//Diagrammtitel
vDiagramm.OlePropertySet("HasTitle",(Variant)true);
vDiagramm.OlePropertyGet("ChartTitle").OlePropertySet("Text","Titel des Diagramms");
vDiagramm.OlePropertySet("HasLegend",(Variant)true);
Variant Legende = vDiagramm.OlePropertyGet("Legend");
Legende.OlePropertySet("Position",-4107); //Legende unten
Legende.OlePropertySet("Left",100); //Legenden abstand von links
Legende.OlePropertySet("Width",550); //Legendenbreite
Legende.OlePropertySet("AutoScaleFont",(Variant)false);
Variant Legende_schrift = Legende.OlePropertyGet("Font");
Legende_schrift.OlePropertySet("Name", "Arial");
Legende_schrift.OlePropertySet("FontStyle","Fett");
Legende_schrift.OlePropertySet("Size","10");//X-Achse
axes1=vDiagramm.OlePropertyGet("Axes",1);
axes1.OlePropertySet("MinimumScale",-100);
axes1.OlePropertySet("MaximumScale",100);
axes1.OlePropertySet("MinorUnit",5);
axes1.OlePropertySet("MajorUnit",25);
axes1.OlePropertySet("CrossesAt",0);
axes1.OlePropertySet("HasTitle",(Variant)true);
axes1.OlePropertyGet("AxisTitle").OlePropertySet("Text","X-Achsenbeschriftung");
//Hauptgitternetz
axes1.OlePropertySet("HasMajorGridlines",(Variant)true);
Variant Hauptgitternetz_x = axes1.OlePropertyGet("MajorGridlines").OlePropertyGet("Border");
Hauptgitternetz_x.OlePropertySet("ColorIndex",48);
Hauptgitternetz_x.OlePropertySet("Weight",1);
//Nebengitternetz
axes1.OlePropertySet("HasMinorGridlines",(Variant)true);
Variant Nebengitternetz_x = axes1.OlePropertyGet("MinorGridlines").OlePropertyGet("Border");
Nebengitternetz_x.OlePropertySet("ColorIndex",48);
Nebengitternetz_x.OlePropertySet("Weight",1);
Nebengitternetz_x.OlePropertySet("LineStyle",-4118);
//Achsentitel
Variant Titel_x = axes1.OlePropertyGet("AxisTitle");
Variant Titel_x_schrift = Titel_x.OlePropertyGet("Font");
Titel_x.OlePropertySet("AutoScaleFont",(Variant)false);
Titel_x_schrift.OlePropertySet("Name", "Arial");
Titel_x_schrift.OlePropertySet("FontStyle","Fett");
Titel_x_schrift.OlePropertySet("Size","10");
//Achse
Variant Achse_x = axes1.OlePropertyGet("TickLabels");
Achse_x.OlePropertySet("AutoScaleFont",(Variant)false);
Achse_x.OlePropertySet("NumberFormat","0");Variant Achse_x_schrift = Achse_x.OlePropertyGet("Font");
Achse_x_schrift.OlePropertySet("Name", "Arial");
Achse_x_schrift.OlePropertySet("FontStyle","Fett");
Achse_x_schrift.OlePropertySet("Size","10");//Y-Achse
axes2=vDiagramm.OlePropertyGet("Axes",2); //xlCategory!!!!!!
axes2.OlePropertySet("MinimumScale",-100);
axes2.OlePropertySet("MaximumScale",100);
axes2.OlePropertySet("MinorUnit",5);
axes2.OlePropertySet("MajorUnit",25);
axes2.OlePropertySet("CrossesAt",0);
axes2.OlePropertySet("HasTitle",(Variant)true);
axes2.OlePropertyGet("AxisTitle").OlePropertySet("Text","Y-Achsenbeschriftung");
//Hauptgitternetz
axes2.OlePropertySet("HasMajorGridlines",(Variant)true);
Variant Hauptgitternetz_y = axes2.OlePropertyGet("MajorGridlines").OlePropertyGet("Border");
Hauptgitternetz_y.OlePropertySet("ColorIndex",48);
Hauptgitternetz_y.OlePropertySet("Weight",1);
//Nebengitternetz
axes2.OlePropertySet("HasMinorGridlines",(Variant)true);
Variant Nebengitternetz_y = axes2.OlePropertyGet("MinorGridlines").OlePropertyGet("Border");
Nebengitternetz_y.OlePropertySet("ColorIndex",48);
Nebengitternetz_y.OlePropertySet("Weight",1);
Nebengitternetz_y.OlePropertySet("LineStyle",-4118);
//Achsentitel
Variant Titel_y = axes2.OlePropertyGet("AxisTitle");
Variant Titel_y_schrift = Titel_y.OlePropertyGet("Font");
Titel_y.OlePropertySet("AutoScaleFont",(Variant)false);
Titel_y_schrift.OlePropertySet("Name", "Arial");
Titel_y_schrift.OlePropertySet("FontStyle","Fett");
Titel_y_schrift.OlePropertySet("Size","10");
//Achse
Variant Achse_y = axes2.OlePropertyGet("TickLabels");
Achse_y.OlePropertySet("AutoScaleFont",(Variant)false);
Achse_y.OlePropertySet("NumberFormat","0");Variant Achse_y_schrift = Achse_y.OlePropertyGet("Font");
Achse_y_schrift.OlePropertySet("Name", "Arial");
Achse_y_schrift.OlePropertySet("FontStyle","Fett");
Achse_y_schrift.OlePropertySet("Size","10");Viel Spaß damit
-
Danke für die sehr ausfürliche Antwort!!!!

Währ garantiert auch was für's FAQ