求解:
把一個HTM檔案保存為MHT檔案
如
把 C:\1.htm 檔案 保存為 C:\2.mht檔案
注這個1.htm檔案里面有圖片的
最重要的功能是把圖片檔案寫入到 2.mht檔案中 如果用的是一個絕對路徑那就失敗了
把一個HTM檔案保存為MHT檔案 這一功能wizHtmlEditor能做到
下面這段代碼是用DELPHI實作的保存HTM為MHT檔案 但不能實作我這一要求
implementation
uses ADODB_TLB, CDO_TLB,ComObj ;
{$R *.dfm}
procedure WB_SaveAs_MHT(WB: TWebBrowser; FileName: TFileName);
var
Msg: IMessage;
Conf: IConfiguration;
Stream: _Stream;
URL : widestring;
begin
if not Assigned(WB.Document) then Exit;
URL := WB.LocationURL;
Msg := CoMessage.Create;
Conf := CoConfiguration.Create;
try
Msg.Configuration := Conf;
Msg.CreateMHTMLBody(URL, cdoSuppressImages, '', '');//cdoSuppressNone,cdoSuppressImages,cdoSuppressAll
Stream := Msg.GetStream;
Stream.SaveToFile(FileName, adSaveCreateOverWrite);
finally
Msg := nil;
Conf := nil;
Stream := nil;
end;
end; (* WB_SaveAs_MHT *)
procedure TForm1.Button1Click(Sender: TObject);
var
f:string;
begin
f:=ExtractFilePath(Application.ExeName)+'WebDoc.htm';
webbrowser1.Navigate(f);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
f1:string;
begin
f1:=ExtractFilePath(Application.ExeName)+'1.mht';
WB_SaveAs_MHT(webbrowser1,f1);
end;
它保存的圖片仍然是絕對路徑 如圖
這是無意義的經反復測驗 cdoSuppressNone,cdoSuppressImages,cdoSuppressAll修改成這3個的其中一個都不能實作下面的功能
WIZ的是保存成這樣的

這里多了個mhtml 和 cid 把這個BBBBB.mht 檔案復制到別人的電腦上是圖片不會丟失
這是MHT檔案用記事本打開的

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/122358.html
標籤:VCL組件開發及應用
上一篇:delphi 陣列洗掉記錄
下一篇:Delphi輸出字母表
