Autor Beitrag
BingoBongo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Linux Mint
Lazarus, Pascal
BeitragVerfasst: Mo 25.08.08 11:00 
Hallo allerseits,
ich habe ein Problem, bei dem ich mir Hilfe erhoffe.
Ich habe ein kleines Tool geschrieben, welches mir sehr lästige Routineaufgaben beim Arbeiten mit bestimmten Excel-Tabellen abnimmt. Unter anderem sollen Formeln innerhalb einer solchen Exceltabelle verändert oder überschrieben werden.
Leider klappt genau das nicht so wie es soll.
Hier mal der Code, den ich verwende, vielleicht kann mir da jemand einen Tipp geben.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure gesamtmiete;
//paßt die Formel für die Gesamtmiete so an, dass alle 8 Zellen addiert werden
var
  Excel: Variant;
  kopie, kopie2: string;
  pfad: string;
  i: integer;
begin
  Excel := CreateOleObject('Excel.Application');
  pfad:= form1.Edit2.Text;
  Excel.Workbooks.Open (pfad);
  Excel.Visible := true;

  application.ProcessMessages;
  Excel.Sheets[2].select;
  Excel.Sheets[2].Range['e5'].select;
  Excel.ActiveCell.formula:= '=c5+c6+c7+c8+d5+d6+d7+d8';
  Excel.ActiveCell.NumberFormat:='0,00';

  Excel.ActiveWorkbook.Save; //(pfad);
  Excel.Quit;
  Excel := unassigned;
end;


Mein Problem ist der Eintrag "Excel.ActiveCell.formula:= '=c5+c6+c7+c8+d5+d6+d7+d8';"

Ich hatte eigentlich vor, die Zeile

ausblenden Delphi-Quelltext
1:
Excel.ActiveCell.formula:= '=Summe(c5:d8)';					


in diese Zelle zu schreiben, aber Excel meckert dann rum mit einem #Name - Fehler, was bei dem aktuellen Eintrag nicht der Fall ist.
Da dies nicht die einzige Art Formel ist, die eigentlich angepaßt werden muß, bin ich nun etwas ratlos. Weiß jemand von euch, was ich machen müßte, damit auch die in die Zellen geschriebenen Formeln von Excel als solche akzeptiert werden?

Ach ja, nutzen tu ich D7 unter Win2000, falls es wichtig wäre.

Bingo
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Mo 25.08.08 11:32 
Ich habs mal mit der englischen Bezeichnung für die Funktion versucht und siehe da, es ging.

ausblenden Delphi-Quelltext
1:
Excel.ActiveCell.formula:= '=sum(c5:d8)';					
BingoBongo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Linux Mint
Lazarus, Pascal
BeitragVerfasst: Mo 25.08.08 11:38 
Das hatte ich auch schon versucht, aber bei mir gings leider nicht, keine Ahnung wieso. :(

Bingo
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Mo 25.08.08 11:41 
Mein System:
Windows XP proffesional SP2 englisch, Office XP (2002) mit SP3 deutsch, Delphi 5 Enterprise
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Mo 25.08.08 11:43 
Noch ein Nachtrag:

Es dürfen KEINE Leerzeichen in der Formel sein.
BingoBongo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Linux Mint
Lazarus, Pascal
BeitragVerfasst: Mo 25.08.08 12:11 
Aber es ist doch gar kein Leerzeichen in der Formel.
Ich habe es auf einem System mit jeweils Win2000 mit Office 2000, Office XP und Office 2003 ausprobieren können. Überall kommt der gleiche Fehler in der Exceltabelle.
Das ist doch zum Haare ausraufen. Bei anderen funktioniert das und bei mir nicht, trotz scheinbar gleichem Code.
Gibt es eventuell eine andere Möglichkeit, eine Formel in eine Tabelle zu schreiben? Ich meine, nicht ".Formula" sondern irgend eine andere Bezeichnung oder sowas? Die Dukumentation diesbezüglich ist ja leider mehr als mager oder nur extrem schwer zu finden. :(

Bingo
BingoBongo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Linux Mint
Lazarus, Pascal
BeitragVerfasst: Mo 25.08.08 15:23 
Es ist doch schon seltsam. Aus reiner Verzweiflung habe ich es nun noch einmal mit Sum versucht und auf einmal klappt das. Irritierend ist nur, dass nicht =Sum in den Formelzellen erscheint, sondern =Summe.
Aber scheinbar habe ich nun einen funktionierenden Weg. Danke für die Tipps.

Bingo
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Mo 25.08.08 15:27 
Ich finde das gar nicht irritierend, denn du hast ja ein deutsches Office...
Prima, das es jetzt auch bei dir funktioniert, ich hatte mich doch schon doll gewundert.
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Di 26.08.08 15:34 
Man kann auch in die Value Eigenschaft einfach die (Excel-) Formel schreiben!
BingoBongo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Linux Mint
Lazarus, Pascal
BeitragVerfasst: Mi 27.08.08 11:18 
In diesem Zusammenhang stehe ich nun vor einen neuen Problem. Wie schreibe ich eine sogenannte Array-Formel in eine Excel-Zelle. Das sind diese Formeltypen, die durch Ctrl-Shift-Enter abgeschlossen werden müssen und dann durch geschweifte Klammern dargestellt werden.
Ich habe eine solche Formel mal aus einer meiner Tabellen in eine Variable rauskopiert und in einem Edit-Feld anzeigen lassen, aber da fehlen die geschweiften Klammern. Muß ich die etwa beim schreiben durch Delphi in eine Excel-Zelle erst sozusagen von Hand anfügen und dann direkt als Formel in die gewünschte Zelle schreiben oder macht man das anders?

Bingo