Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 23.01.05 19:09 
Hi, Delpher,

ist wahrscheinlich gaaanz einfach ...
Wie kann ich Excel mit einem existierenden / einem nicht existierenden
Arbeitsblatt (.xls) aufrufen?

Danke für Hilfe,
D.Annies
Radioactive
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 179

Win 98, Win XP Home SP2
D3 Prof, D7 Pers, D2005 Pers
BeitragVerfasst: So 23.01.05 19:20 
was ist den ein extistierendes Arbeitsblatt??? und erst ein nicht existierendes? Meinst du Excel ohne ein Arbeitsblatt und Excel mit einem Arbeitsblatt aus einer Datei?

Excel mit einem Arbeitsblatt us einer Datei rufst du mit
ausblenden Delphi-Quelltext
1:
ShellExecute(Application.Handle,'open','C:\Programme\Microsoft Office\OFFICE11\','C:\Arbeitsblatt.xls','EXCEL.EXE',SW_SHOW);					


Ich binmirnicht sicher, ob der Pfad und der Dateiname zur Excel-Programmdatei stimmt.
Du musst die Unit ShellAPI einbinden.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 23.01.05 19:26 
Hi, radioactivy,

ich dachte an den Aufruf
excel.workbook.open('blatt.xls');
aber diese Datei könnte existieren oder noch nicht.

Was ist dann bei Nichtexistieren genau zu tun (wie lege ich es an?)

bis dann
d.annies
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: So 23.01.05 20:02 
ob die tabelle existiert, kannst du auch mit fileexists ermitteln.

und ein neues Workbook erstellen: zeichne dir einfach ein Makro auf, und gugg dir es in VB an.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 23.01.05 20:10 
Hi, Frank,

fileexists ist ok, aber ein Makro kann ich leider nicht. geht es auch
"traditionell?

bis dann, Detlef A.
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: So 23.01.05 20:27 
klar gehts auch traditionell. Das makro sollst du nur aufzeichenen, damit du gleich die Befehle und Konstanten und erfroderlichen Parameter hast. so gehts viel schneller als erst die einzelnen Befehle nachschlagen.

Menu: extras->aufzeichen, namen vergeben, dann die aktionen duchführen und die Aufzeichnung beenden. wieder extras->Makros und bearbeiten klicken, dir das makro anschauen und die sache in Delphi umsetzen. Ich mach das immer so, erspart viel denkarbeit.

Probiers erstaml allein, sonst frag wieder :)

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 23.01.05 20:37 
Hi,

ich versuchs mal ...

Aber jetzt: Bis morgen!

Detlef Annies
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 25.01.05 18:39 
Hi, Frank (et aliter)

ich bekomme den Aufruf leider nicht alleine hin ...

Kannst du / könnt ihr noch einmal helfen?

Danke, D. Annies
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Di 25.01.05 19:40 
ausblenden volle Höhe 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:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
procedure TForm1.Button1Click(Sender: TObject);
//Server-variante, jeweils eine excel-application, workbook und worksheet-kompo auf die Form
Var flcid:Cardinal;
    Dateiname:string;
begin
  flcid:=GetUserDefaultLCID;
  dateiname:='D:\test2.xls';
  try
    ExcelApplication1.Connect;
    ExcelApplication1.Visible[flcid]:=true;
    ExcelApplication1.UserControl:=true;

    if FileExists(Dateiname) then
      begin
        ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Open(dateiname,EmptyParam, EmptyParam,
                                      EmptyParam, EmptyParam, EmptyParam,
                                      EmptyParam, EmptyParam, EmptyParam,
                                      EmptyParam, EmptyParam, EmptyParam,
                                      EmptyParam, fLCID));
        ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets.Item[1] as ExcelWorkSheet);
        ExcelWorksheet1.Cells.Item[2, 2] :='Test geöffnet';
      end
     else
       begin
        ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(EmptyParam,fLCID));
        ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets.Item[1] as ExcelWorkSheet);
        ExcelWorksheet1.Cells.Item[2, 2] :='Tabelle neu erstellt';
      end;

    ExcelWorksheet1.Disconnect;
    ExcelWorkbook1.Disconnect;
    ExcelApplication1.Disconnect;
  except                                  
  end;
end;

//oder

procedure TForm1.Button2Click(Sender: TObject);
var Excel: Variant;
    dateiname:string;
begin
  try
    Excel:=GetActiveOleObject('Excel.Application');
  except
    Excel:=CreateOleObject('Excel.Application');
  end;
  Excel.Visible := True;
  dateiname:='D:\test2.xls';
  if FileExists(Dateiname) then
    begin
      excel.workbooks.open(dateiname);
    end
   else
    begin
      excel.workbooks.add;
    end;
  Excel := Unassigned;
end;

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 25.01.05 20:53 
Hallo, Frank,

herzlichen Dank für deine zwei CodeVersionen, ich meine, die erste kann ich bei
D3prof und die zweite bei D6Enter einsetzen (siehe mein Profil)

Das hilft!!

Viele Grüße von
Detlef A.
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Di 25.01.05 21:11 
die serverkompos (1. Bsp) sind glaube ab D5 mit dabei, das geht mit D3 bestimmt nich ;), wobei ich die Verwendung der Serverkompos bevorzuge (wegen der möglichen Codevervollständigung)
Variante 2 sollte bei beiden Versionen gehen.

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 25.01.05 21:57 
Hi, Frank, danke für deinen Nachsatz,
Detlef A.