![]() |
Delphi-OLE, Änderung wird nicht gespeichert
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; |
Re: Delphi-OLE, Änderung wird nicht gespeichert
Hallo,
hat sich erledigt, ich hatte den falschen Dateinamen, statt SaveDialog hatte ich OpenDialog benutzt. Jetzt klappt es. Heiko |
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:43 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz