I work with Excel in Delphi 7 via OLE. How to create a file, change something in it and close it, there are no problems. But I also need to open the Excel file saved in the database (MSSQL) for viewing. I work with Excel like this:
ExlApp: = CreateOleObject ('Excel.Application');
try
ExlApp.Workbooks.Open (XLSFile);
Sheet: = ExlApp.Workbooks [ExtractFileName (XLSFile)]. WorkSheets [1];
...
finally
ExlApp.DisplayAlerts: = false;
ExlApp.ActiveWorkbook.Close (SaveChanges: = False);
ExlApp.Application.Quit;
Sheet: = Unassigned;
ExlApp: = Unassigned;
end;
If we are only going to open an Excel file, then there is a piece of code:
ExlApp.DisplayAlerts: = false;
ExlApp.ActiveWorkbook.Close (SaveChanges: = False);
ExlApp.Application.Quit;
Sheet: = Unassigned;
ExlApp: = Unassigned;
will be absent, then do you need to clear the memory (when the user closes the Excel document) allocated for ExlApp and if so, how?
Answer 1, authority 100%
In fact, it should have been written like this:
try
...
finally
ExlApp.Visible: = True;
Sheet: = Unassigned;
ExlApp: = Unassigned;
end;
We free memory and the program continues to run. And the user will close the Excel document when he sees fit.