给你看一段我的代码吧
// 如果memo是RTF格式,则返回RTF格式的字符串
function MemoRawText(Memo:TRXRichEdit):string;
var
ms:TMemoryStream;
begin
ms:=TMemoryStream.create;
try
Memo.Lines.SaveToStream(ms);
setlength(result,ms.size);
ms.Position:=0;
if length(result)>0 then
ms.Read(result[1],ms.size);
finally
ms.free;
end;
end;
-------------------------------------------------------------
procedure ImportDOC(const LongFileName:string);
var
ext:string;
IsDocFile:boolean; // 文件是word文件
oFileName, // 以下为导入Word文件用到的变量
oReadOnly, //
oAddToRecentFiles, //
oi, //
oint, //
oCount, //
oSaveChanges :OleVariant; //
begin
...
IsDocFile:=Ext='.DOC'; // 准备处理DOC文件
if IsDocFile then
begin
oFileName:=FileName;
oReadOnly:=true;
oAddToRecentFiles:=false;
WordApp.Documents.Open(oFilename,
EmptyParam,
EmptyParam,//oReadOnly,
EmptyParam,//oAddToRecentFiles,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam);
oint:=1;
oi:=0;
oCount:=WordApp.Documents.Item(oint).Characters.Count;
WordApp.selection.SetRange(oi,oCount);
WordApp.Selection.Copy;
TmpRichEdit.Lines.Clear;
SendMessage(TmpRichEdit.Handle,WM_PASTE,0,0);
s:=MemoRawText(TmpRichEdit);
oSaveChanges:=wdDoNotSaveChanges;
WordApp.Documents.Item(oint).Close(oSaveChanges,EmptyParam,EmptyParam);
ShowMessage('文件 '+LongFilename+' 装入成功。');
result:=1;
end;
end;