'TOleContainer does not load Excel on Windows 10, but it works on Windows XP - is the end-of-support for TOleContainer in Delphi?
I am using Delphi TOleContainer components with the variable name SContainer and I am loading the Excel file into it using the code:
function CreateTExcelApp(aOwner: TComponent; AVisible:Boolean=True): TExcelApplication;
var
Res: TExcelApplication;
begin
Res:=TExcelApplication.Create(aOwner);
if Res = nil then
raise Exception.Create(rsNoExcelInstalled);
Res.ConnectKind:=ckNewInstance;
Res.Connect;
if AVisible then begin
if Res.WindowState[LCID] = TOLEEnum(xlMinimized) then
Res.WindowState[LCID] := TOLEEnum(xlNormal);
Res.ScreenUpdating[LCID] := true;
end;
Res.Visible[LCID] := AVisible;
Result:=Res;
end;
procedure SDM.CreateExcelApplication;
begin
try
if not Assigned(FExcel)then
begin
FExcel := CreateTExcelApp(self,False);
end;
FExcel.Workbooks.Open(ExcelFilePath,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,0);
FillExcelWithData;
FExcel.OnSheetChange:=OnExcelSheetChanged;
FExcelChanged:=false;
finally
FExcel.ActiveWorkbook.Save(0);
FExcel.Workbooks.Close(0);
FExcel.Quit;
end;
end;
var SContainer: TOleContainer;
SDM.CreateExcelApplication;
SContainer.CreteObjectFromFile(ExcelFilePath)
This code works (whole Excel container and file within it is loaded in the Delphi application instance) on Windows XP and has always worked on later Windows versions. But Windows 10 opens Excel file in the separate Excel instance (instead loading all the Excel container in the TOleContainer component in the Delphi application) and then Windows 10 loads some parts of the Excel file in the TOleContainer but no Excel menus, ribbon and toolbars are loaded in the TOleContainer. That is different from the behavior on Windows XP machine, in which Windows XP loads entire Excel application in the TOleContainer with all the menus, ribbon and toolbars.
Are the some incompatibilies between OLE technologies, Excel and Windows 10?
I am using Delphi 6, but I guess that problem can be for later Delphi editions as well.
The question made more accurate: The fact, that Windows 10 does not load menus/ribbon/toolbars is not so bad, the worst thing is that Windows 10 loads the visual preview of the first sheet only and no other sheets are loaded by Windows 10. That means that any futher programmatical access of the cells from other sheets gives OLE error and other error message. So, menus/ribbon/toolbars can stay unloaded, but sheets should be present.
Options - Trust Center - Trust Center Settings... - Macro Settings - Macro Settings - Enable all macros (not recommened; potentially dangerous code can run) select prevents the load of additional instance of Excel application and no warning about macros is displayed, the sheet is immediately loaded in the container, but this settings does not solve the problem, that only first sheet (or its visual preview) is loaded in the TOleContainer and no other sheets are loaded.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
