The first and easiest is to save the document as HTML. If Doc is a
connected TWordDocument:
FileName := 'D:/Docs/Word/TestHTML.htm';
Fmt := wdFormatHTML;
Doc.SaveAs(FileName, Fmt);
You can then use the saved file and delete it when you've finished.
If you really don't want to do that, though, you could use the
clipboard instead - just copy the whole document and then use
Clipboard.GetAsHandle(CF_HTML) to get at the data. Using the
clipboard like that is a bit antisocial, however, so I'll move on to
method three, which is similar but uses the Word document's
IDataObject interface:
var
CF_HTML: Word;
var
Doc: WordDocument;
DataObj: IDataObject;
FormatEtc: TFormatEtc;
SM: TstgMedium;
TextPtr: PChar;
..
Doc := WordApp.ActiveDocument;
DataObj := Doc as IDataObject;
Assert(DataObj <> nil);
FormatEtc.cfFormat := CF_HTML;
FormatEtc.tymed := TYMED_HGLOBAL;
FormatEtc.ptd := nil;
FormatEtc.dwAspect := DVASPECT_CONTENT;
FormatEtc.lindex := -1;
OleCheck(DataObj.GetData(FormatEtc, SM));
TextPtr := GlobalLock(SM.hGlobal);
Memo1.Lines.Text := StrPas(TextPtr);
GlobalUnlock(SM.hGlobal);
ReleaseStgMedium(SM);
initialization
CF_HTML := RegisterClipboardFormat('HTML Format');
---------------------------------------------
以前在国外网站上看到的