function Tfrm_main.Openexcel: Boolean;
var
Curexcel: string;
begin
Curexcel := GetRegString(HKEY_CLASSES_ROOT, '/excel.Application/CurVer', '', '');
if Curexcel = '' then
begin
Application.MessageBox('请先安装 excel 97 或 excel 2000!或 excel XP',
PChar(self.Caption), MB_OK + MB_ICONSTOP);
Result := False;
Exit;
end;
if (Curexcel <> 'excel.Application.8') and (Curexcel <> 'excel.Application.9') then
begin
{
Curexcel := GetRegString(HKEY_CLASSES_ROOT, '/excel.Application.8', '', '');
if Curexcel = '' then
begin
Curexcel := GetRegString(HKEY_CLASSES_ROOT, '/excel.Application.9', '', '');
if Curexcel <> '' then Curexcel := 'excel.Application.9';
end
else
begin
Curexcel := 'excel.Application.8';
end;
}
Curexcel := GetRegString(HKEY_CLASSES_ROOT, '/excel.Application.10', '', '');
if Curexcel <> '' then Curexcel := 'excel.Application.10';
if Curexcel = '' then
begin
Application.MessageBox('无法运行 excel 97 或 excel 2000,' + #13#10
+ '请检查 excel 97 或 excel 2000 是否已经正确安装。',
PChar(self.Caption), MB_OK + MB_ICONSTOP);
Result := False;
Exit;
end;
end;
try
Fexcel := CreateOleObject(Curexcel);
if VarIsEmpty(Fexcel) then
begin
Application.MessageBox('无法运行 excel 97 或 excel 2000,' + #13#10
+ '请检查 excel 97 或 excel 2000 是否已经正确安装。',
PChar(self.Caption), MB_OK + MB_ICONSTOP);
Result := False;
Exit;
end;
except
Application.MessageBox('无法运行 excel 97 或 excel 2000,' + #13#10
+ '请检查 excel 97 或 excel 2000 是否已经正确安装。',
PChar(self.Caption), MB_OK + MB_ICONSTOP);
Result := False;
Exit;
end;
try
begin
Fexcel.DisplayAlerts := False;
Fexcel.workbooks.Open(ExtractFilePath(Application.EXEName)+'Chinese Turnover Tax Macro Model (On 1997 Data).xls');
Fexcel.caption:='中国流转税宏观模型';
Fexcel.Visible := True;
Result := True;
end;
except
Application.MessageBox('分析失败,',
PChar(self.Caption), MB_OK + MB_ICONSTOP);
Result := False;
end;
end;
如何!