Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Fernsteuerung von Excel - Quellcodeproblem (https://www.delphipraxis.net/57697-fernsteuerung-von-excel-quellcodeproblem.html)

Frozen-Death 25. Nov 2005 10:47


Fernsteuerung von Excel - Quellcodeproblem
 
Hallo alle zusammen.
Ich habe folgendes Problem, welches ich einfach nicht gelöst bekomme.
Ich will per Fernsteuerung auf Excel eine csv Datei einlesen und die Spalten gleich formatieren etc.
Ich weiß auch wie ich das machen kann, jedoch habe ich folgenden Quellcode aus Excel, den ich einfach nicht so übersetzt bekomme, dass Delphi ihn versteht:

ActiveSheet.QueryTables.Add("Connection:= "TEXT;C:\Dokumente und Einstellungen\Stefan\Desktop\daten.csv", Destination:= Range("A1")");

nun kann ich ja mit excel. den Code an Excel übergeben:

excel.ActiveSheet.QueryTables.Add("Connection:= "TEXT;C:\Dokumente und Einstellungen\Stefan\Desktop\daten.csv", Destination:= Range("A1")");

Leider weiß er nichts mit dem .add anzufangen.

Kann mir da irgendeiner helfen, ich komm einfach nicht mehr weiter.

Der gesamte Quellcode sieht derzeit so aus, wobei er noch nicht fertig ist:

"
procedure TForm1.Button1Click(Sender: TObject);
var
Excel : Variant;
begin
excel := CreateOleObject('Excel.Application');
excel.visible := true;
excel.Workbooks.Add;
excel.ActiveSheet.QueryTables.Add("Connection:= "TEXT;C:\Dokumente und Einstellungen\Stefan\Desktop\daten.csv", Destination:= Range("A1")");
excel.activesheet.name := 'Daten';
excel.activesheet.fieldnames := false;
excel.rownumbers := false;
excel.filladjacentformulas := false;
excel.PreserveFormatting := True;
excel.RefreshOnFileOpen := False;
excel.RefreshStyle := xlInsertDeleteCells;
excel.SavePassword := False;
excel.SaveData := True;
excel.AdjustColumnWidth := True;
excel.RefreshPeriod := 0;
excel.TextFilePromptOnRefresh := False;
excel.TextFilePlatform := 1252;
excel.TextFileStartRow := 1;
excel.TextFileParseType := xlDelimited;
excel.TextFileTextQualifier := xlTextQualifierNone;
excel.TextFileConsecutiveDelimiter := False;
excel.TextFileTabDelimiter := False;
excel.TextFileSemicolonDelimiter := True;
excel.TextFileCommaDelimiter := False;
excel.TextFileSpaceDelimiter := False;
excel.TextFileColumnDataTypes := 'Array(.....)';
excel.TextFileTrailingMinusNumbers := True;
excel.Refresh;
excel.BackgroundQuery := False
end;
"

Wäre für jede Hilfe echt dankbar.

Gruß Stefan

HendrikM 25. Nov 2005 11:38

Re: Fernsteuerung von Excel - Quellcodeproblem
 
1. Welche Excel - Version benutzt Du? Mein Excel (2002) kennt kein
Zitat:

ActiveSheet.QueryTables.Add
2. Wenn Du Excel als Variant deklarierst stehen Dir nicht alle Funktionen/Prozeduren zur Verfügung
besser wäre es
Delphi-Quellcode:
uses ..., Excel_TLB,...;
  var
    ExcelAPP: Excel_TLB._Application;
    WB:Excel_TLB.ExcelWorkbook;
    WS:Excel_TLB._Worksheet;
    MyLCID: integer;
begin
      Mylcid := LOCALE_USER_DEFAULT;
      ExcelAPP := CoExcelApplication.Create;
      WB := xlAPP.Workbooks.Open(Filename, EmptyParam, EmptyParam,
                                EmptyParam, EmptyParam, EmptyParam,
                                EmptyParam, EmptyParam, EmptyParam,
                                EmptyParam, EmptyParam, EmptyParam,
                                EmptyParam, EmptyParam, EmptyParam, MyLCID);
      WS:=WB.Worksheets[1] as Excel_TLB._Worksheet;



...
end;
3. Du müsstest Dir dann mal die entsprechenden Parameter bei Workbooks.Open ansehen,
was da für Deine Zwecke reinmuß.
Hendrik


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:57 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz