使用以下函数表示从本地html文件生成Web归档 function TLessonConstructor2.CreateMHT( const FileName : string):boolean ; var oMSG:IMessage; oConfig: IConfiguration; sFileName: string; Stream: _Stream;begin //CoInitializeEx(nil,
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,”,”)之后;只要基本过程完成,该文件就会被锁定.但是,处理后应删除此文件.
知道问题是什么吗?
CreateMHTMLBody需要URL,因此对于本地文件,请确保以file:///开头CreateMHTMLBody(const URL: WideString; Flags: CdoMHTMLFlags;
const UserName: WideString; const Password: WideString); safecall;
