请问,如何直接从内存流中打开word文档?(30分)

  • 主题发起人 主题发起人 guoxp
  • 开始时间 开始时间
G

guoxp

Unregistered / Unconfirmed
GUEST, unregistred user!
请教诸位一个直接从内存流中打开word文档的问题,内存流中的文件来自数据库<br><br><br>procedure Tf_guoji.SpeedButton_wordClick(Sender: TObject);<br>var<br>blob_word:TBlobStream;<br>M_word:TMemoryStream;<br>begin<br>DataModule_zbgl.Q_MB.Edit;<br><br>blob_word:=TBlobStream.Create(DataModule_zbgl.Q_MB.fieldbyname('招标模板') as TblobField,bmReadWrite);<br>screen.Cursor:=crHourGlass;<br>try<br>&nbsp; m_word:=TmemoryStream.Create;<br>&nbsp; try<br>&nbsp; &nbsp; &nbsp;m_word.CopyFrom(blob_word,blob_word.size);<br>&nbsp; &nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp; &nbsp;ShellExecute(handle,'open',pchar(path),nil,nil,SW_SHOWNORMAL);<br>&nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp;//请注意,这里的pchar(path)本来是通过文件路径来打开文件的,那时候的程序没有问题,现在,我<br>&nbsp; &nbsp; //想直接通过内存流m_word打开word来显示位于M_word中的word文档,那么,这个ShellExecute就不能用了<br>&nbsp; &nbsp; //我该用什么好了?我见过palySound()函数来直接播放内存流中的wav数据的,那么,直接从内存流打开<br>&nbsp; &nbsp; //word文档该怎么做?急盼回答!!<br><br>&nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; &nbsp;application.MessageBox('请确认已经安装word应用程序!','提示信息..',mb_ok);<br>&nbsp; &nbsp; &nbsp; &nbsp;exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;<br><br>&nbsp; finally<br>&nbsp; &nbsp; &nbsp;m_word.Free;<br>&nbsp; end;<br>finally<br>&nbsp; &nbsp;screen.Cursor:=crDefault;<br>&nbsp; &nbsp;blob_word.Free;<br>end;<br><br>end;<br>
 
用Tolecontainer,它可以从内存流中取得数据,不过前提是内存流必须是以前用<br>Tolecontainer生成的内存流<br>Tolecontainer.savetostream<br>olecontainer.loadfromstream<br>
 
type<br>&nbsp; TStHead = record<br>&nbsp; &nbsp; biaozhi : integer; // 标志,$434F4442<br>&nbsp; &nbsp; yangshi : integer; //样式,1<br>&nbsp; &nbsp; Size &nbsp; &nbsp;: integer; //文件大小<br>&nbsp; end;<br>procedure TForm1.Button1Click(Sender: TObject);<br><br>var<br>&nbsp; Fs : TFilestream;<br>&nbsp; Ms1,MS2 : TMemoryStream;<br>&nbsp; SH : &nbsp;TStHead;<br>&nbsp; M<br>begin<br>&nbsp; Ms1 := TMemoryStream.Create;<br>&nbsp; Ms2 := TMemoryStream.Create;<br>&nbsp; try<br>&nbsp; &nbsp; TBlobField(ADOQuery1.FieldByName('content')).SaveToStream(Ms1);<br>&nbsp; &nbsp; with sh do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; biaozhi := $434F4442;<br>&nbsp; &nbsp; &nbsp; yangshi := 1;<br>&nbsp; &nbsp; &nbsp; size &nbsp; &nbsp;:= ms1.Size;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; ms2.WriteBuffer(sh,sizeof(sh));<br>&nbsp; &nbsp; ms2.CopyFrom(ms1,0);<br>&nbsp; &nbsp; ms2.Position := 0;<br>&nbsp; &nbsp; OleContainer1.LoadFromStream(ms2);<br>&nbsp; &nbsp; OleContainer1.DoVerb(ovShow);//编辑文档<br>&nbsp; Finally<br>&nbsp; &nbsp; ms1.Free;<br>&nbsp; &nbsp; ms2.Free;<br>&nbsp; end;<br>end;
 
给你个控件,可以从内存中打开Word文档。<br>http://www.textcontrol.com/tx/downloads/<br>你找找看,有9.0的破解
 
后退
顶部