Einzelnen Beitrag anzeigen

Benutzerbild von BrunoT
BrunoT

Registriert seit: 23. Jan 2003
Ort: Sandbeiendorf
360 Beiträge
 
Delphi 8 Professional
 
#3

Re: Excel Datei importieren

  Alt 25. Apr 2005, 09:25
Hallo HartiMcFly,

folgender Code funktioniert bei mir:

Delphi-Quellcode:
uses ExcelXP, OleServer;

Var
  s:string;
  excel: TExcelApplication;
  wb: _WorkBook;
  ws: _WorkSheet;
  lcid: INTEGER;

....

PROCEDURE TForm.Button1Click(Sender: TObject);
begin
  lcid := GetUserDefaultLCID;
  excel := TExcelApplication.Create(Form);
  excel.Connect;
  opendialog1.Filter:= 'Exceldateien (*.xls)|*.XLS';
  IF not opendialog1.Execute THEN exit;
   s:= opendialog1.FileName;
  // Exceldatei laden (test.xls)
  wb := excel.Workbooks.Open(s, emptyParam, emptyParam, emptyParam, emptyParam,
  emptyParam, emptyParam, emptyParam, emptyParam, emptyParam, emptyParam,
  emptyParam, emptyParam,emptyParam, emptyParam,lcid);

  // erstes Worksheet auswählen
  ws := wb.Sheets[1] as _WorkSheet;
  // Feld A1 ausgeben
  ShowMessage(ws.Cells.Item[1,1].TEXT);
  // Hier in dein Grid übergeben
...
  wb.Close(FALSE, emptyParam, emptyParam, lcid);
  excel.Quit;
end;
viel Erfolg!

BrunoT
Holger

EDV- Ende der Vernunft
Meine Calcedit-Kompo
  Mit Zitat antworten Zitat