Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.275 Beiträge
Delphi 10.4 Sydney
|
Delphi-OLE, Änderung wird nicht gespeichert
18. Okt 2008, 19:46
Hallo #,
das folgende Stück Code soll eine Excel-Datei öffnen,
was eintragen und die Datei wieder speichern.
Problem
Keine Fehlermeldung, es wird aber nix gespeichert !
Was mache ich falsch ?
Danke
Heiko
Delphi-Quellcode:
procedure TForm_SMS_Import.DoSave;
var
iCol : Integer;
sFilename : String;
ExcelApplication0 : TExcelApplication;
ExcelWorkbook0 : TExcelWorkbook;
ExcelWorksheet0 : TExcelWorksheet;
SaveChanges : OleVariant;
begin
Button_Save.Enabled:= False;
try
SaveDialog2.InitialDir:= ExtractFilePath(OpenDialog1.FileName);
if SaveDialog2.Execute=False then Exit;
ExcelApplication0 := TExcelApplication.Create(NIL);
ExcelWorkbook0 := TExcelWorkbook.Create(NIL);
ExcelWorksheet0 := TExcelWorksheet.Create(NIL);
try
ExcelApplication0.Connect;
ExcelApplication0.Visible[flcid]:=False;
ExcelApplication0.UserControl:=true;
sFilename:= OpenDialog1.FileName;
ExcelWorkbook0.ConnectTo(ExcelApplication0.Workbooks.Open(sFilename,
emptyParam, emptyParam, emptyParam, emptyParam, emptyParam,
emptyParam, emptyParam, emptyParam, emptyParam, emptyParam,
emptyParam, emptyParam, flcid));
ExcelWorksheet0.ConnectTo(ExcelWorkbook0.Sheets.Item[1] as ExcelWorkSheet);
ExcelWorksheet0.Range['A5','A5'].Value:= 'Test';
ExcelWorksheet0.Cells.Item[1,1].Value:= 'Test';
(*
SaveChanges:= True;
ExcelWorkbook0.Close(SaveChanges, EmptyParam, EmptyParam, flcid);
*)
// ExcelApplication0.DisplayAlerts[flcid]:= True;
finally
(*
ExcelWorkbook0.Close(False);
*)
SaveChanges:= True;
ExcelWorkbook0.Save;
ExcelWorksheet0.Disconnect;
FreeAndNIL(ExcelWorksheet0);
// Workbook ohne Speichern schliessen
ExcelWorkbook0.Disconnect;
FreeAndNil(ExcelWorkbook0);
// Excel beenden
ExcelApplication0.Quit;
ExcelApplication0.Disconnect;
FreeAndNil(ExcelApplication0);
end;
Label_TargetFile.Caption:= SaveDialog2.FileName;
finally
Button_Save.Enabled:= False;
end;
end;
Heiko
|
|
Zitat
|