微软最近打破了我们长期(并由他们正式推荐)的代码来读取 Excel 版本及其当前的 omacro 安全级别。
以前的工作:
// Get the program associated with workbooks, e.g. "C:\Program Files\...\Excel.exe"
SHELLAPI.FindExecutable( 'OurWorkbook.xls', ...)
// Get the version of the .exe (from it's Properties...)
WINDOWS.GetFileVersionInfo()
// Use the version number to access the registry to determine the security level
// '...\software\microsoft\Office\' + VersionNumber + '.0\Excel\Security'
(我总是很高兴安全级别在不安全的注册表项中多年......)
在 Office 2010 中,.xls 文件现在与“Microsoft Application Virtualization DDE Launcher”或 sftdde.exe 相关联。这个exe的版本号显然不是Excel的版本。
我的问题:
除了实际启动 Excel 并查询它的版本和安全级别(使用 OLE CreateOLEObject('Excel.Application'))之外,是否有一种更清晰、更快或更可靠的方法来执行此操作,该方法适用于从 Excel 2003 开始的所有版本?
最佳答案
用
function GetExcelPath: string;
begin
result := '';
with TRegistry.Create do
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe', false) then
result := ReadString('Path') + 'excel.exe';
finally
Free;
end;
end;
获取 excel.exe 文件的完整文件名。然后像往常一样使用
GetFileVersionInfo
。据我所知,这种方法总是有效的。
关于delphi - 如何获取 Excel 版本和宏安全级别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3507224/