我需要测试我是否可以在我的程序中使用 Excel OLE,因为它可以在没有 Excel 的 PC 上启动。网上的代码示例假设安装了 Excel,但如果没有呢?
XLApp := CreateOleObject('Excel.Application');
try
// Hide Excel
XLApp.Visible := False;
// Open the Workbook
XLApp.Workbooks.Open(aPath);
...snip...
finally
// Quit Excel
if not VarIsEmpty(XLApp) then
begin
XLApp.Quit;
XLAPP := Unassigned;
end;
end;
如果安装了 Excel,那会是正确的代码吗?
//Try to create Excel OLE
try
XLApp := CreateOleObject('Excel.Application');
except
ShowMessage('Error opening Excel');
Exit;
end;