使用以下函数表示从本地html文件生成Web存档
function TLessonConstructor2.CreateMHT( const FileName : string):boolean ;
var
oMSG:IMessage;
oConfig: IConfiguration;
sFileName: string;
Stream: _Stream;
begin
//CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
//CoInitialize(nil);
try
Result := false;
sFileName := ChangeFileExt(FileName, '.mht');
DeleteFile(PAnsiChar(sFileName));
try
oConfig := CoConfiguration.Create();
oMSG := CoMessage.Create();
oMSG.Configuration := oConfig;
oMSG.CreateMHTMLBody(FileName,CdoSuppressNone,'','');
Stream:=oMSG.GetStream;
Stream.SaveToFile(sFileName,adSaveCreateOverWrite);
Stream.Cancel;
Stream.Close;
Result := True;
except
on E: Exception do
begin
Result := false;
MessageDlg(E.Message, mtError, [mbOK], 0);
end;
end;
finally
// CoUnInitialize;
Stream:=nil;
oConfig:=nil;
oMSG:=nil;
end;
end;
FileName - html的完整路径。
执行 oMSG.CreateMHTMLBody(FileName,CdoSuppressNone,'','');只要基本过程完成,该文件就会被锁定。但是,处理后应删除此文件。
知道问题是什么吗?
答案 0 :(得分:3)
CreateMHTMLBody需要网址,因此对于本地文件,请确保先于file:///
CreateMHTMLBody(const URL: WideString; Flags: CdoMHTMLFlags;
const UserName: WideString; const Password: WideString); safecall;