Autor Beitrag
Ramon
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 107

WIN7
D6 Prof, D7 Prof, D 2009
BeitragVerfasst: Do 28.07.11 11:55 
Hallo zusammen,

ich habe ein kleines Problem mit einem TOleContainer und Excel Dateien.
XLS Dateien kann ich laden und speichern. XLSX Dateien sind aber nach dem Speichern defekt. Der Weg ist der selbe:

ausblenden Delphi-Quelltext
1:
2:
3:
  ole.CreateObjectFromFile(sFile, False);
  // Ändern der Datei durch den Anwender
  ole.SaveAsDocument(sFile);


Installiert habe ich Office 2010 und Delphi 2009.
Langsam verzweifel ich ziemlich.

Gibt es vielleicht noch einen alternativen Weg aus dem OleContainer eine Excel Datei zu speichern?

Danke und Gruß
Ramon
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 28.07.11 13:06 
Moin!

Musste man nicht beim Speichern eine Dateiformatkonstante mitgeben, sonst bleibt das Format gleich? :gruebel: Einfach nur den Dateinamen ändern interessiert Excel nicht die Bohne. :idea: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Ramon Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 107

WIN7
D6 Prof, D7 Prof, D 2009
BeitragVerfasst: Do 28.07.11 13:15 
Wenn weiß ich nicht wie. Die Datei ist aber auch defekt wenn ich sie in *.xls umbenenne.
Schau ich mir die Datei im Notepad an, finde ich zwischen den ganzen kryptischen Zeichen den Eintrag Excel.Sheet.12. Das müsste ja eigentlich stimmen.

Gibt es eine Möglichkeit das OleObject in eine TExcelApplication umzuwandeln?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 28.07.11 13:18 
Moin!

Schau mal die Beiträge von user profile iconChemiker durch, der machte AFAIR ziemlich viel mit Excel+OLE. :idea: Vielleicht schaut er ja auch beim nächsten Besuch mal hier in deinen Thread rein. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Ramon Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 107

WIN7
D6 Prof, D7 Prof, D 2009
BeitragVerfasst: Do 28.07.11 14:19 
Hallo,

dank dir, aber ich glaube ich hab es jetzt.

XLSX Dateien speicher ich jetzt wie folgt:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  ExcelApplication : variant;
begin
  ole.DoVerb(ovShow);
  ExcelApplication := ole.OLEObject;
  ExcelApplication.SaveAs(sFile);


Have a nice day
Ramon 8)
Chemiker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 194
Erhaltene Danke: 14

XP, Vista 32 Bit, Vista 64 Bit, Win 7 64 Bit
D7, BDS 2006, RAD Studio 2009+C++, Delphi XE2, XE3, VS 2010 Prof.
BeitragVerfasst: Fr 29.07.11 01:08 
Hallo Ramon,

SaveAs ist eine Methode von Workbook und nicht von der Excel-Application. Beim Speichern müsste eigentlich eine Fehlermeldung kommen, dass SaveAs nicht unterstützt wird.
Das bedeutet, dass man das Workbook das gespeichert werden soll spezifizieren muss, dies kann man z. B. mit einem Index erreichen. Der Index entspricht der Position der Mappe1= Index1; Mappe2=Index2 usw.
Soll jetzt die Mappe1 gespeichert werden so muss sie mit dem Index angesprochen werden.
z.B.:
ausblenden Delphi-Quelltext
1:
ExcelApplication.Workbooks[1].SaveAs(FileName:= MyFileName, Fileformat:= xlNormal);					
Damit wird dann Deine Datei als .XLS Datei abgespeichert, soll die Datei als .XLSX abgespeichert werden, einfach das Fileformat weglassen.

Bis bald Chemiker
Ramon Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 107

WIN7
D6 Prof, D7 Prof, D 2009
BeitragVerfasst: Fr 29.07.11 11:18 
Hi,

ist ja keine ExcelApplication, nur ein Variant. Oder meintest du wegen dem Namen des Variants?
Wie komm ich denn an ein Objekt der Klasse TExcelApplication?

Bis jetzt scheint es zu funktionieren.


Danke und Gruß
Ramon 8)