各位大虾小弟求word使用的例子(50分)

  • 主题发起人 主题发起人 yindajun123
  • 开始时间 开始时间
Y

yindajun123

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟是新手,现在正在学习阶段,想实现delphi与word间的基本功能,基本与反已经清楚,但尚组织不起来,希望哪位大哥给我个例子和代码,小弟在此谢过了
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=737517<br>问题:Delphi与Word之间的融合技术 ( 积分:0, 回复:251, 阅读:18726 )<br>分类:OLE/Automation ( 版主:g622, hubdog ) &nbsp;<br>来自:yzhshi, 时间:2001-11-18 17:52:00, ID:737517 <br>
 
这是一个可以存word 文件和读word 文件 代码你可以看看 &nbsp;,保存work文件的字段类型是(image)<br>procedure TF_PFSJCXTJ.N1Click(Sender: TObject);<br>var<br>&nbsp; I : integer;<br>&nbsp; MemoryStream:TMemoryStream;<br>begin<br>&nbsp; MemoryStream:=TMemoryStream.Create;<br>&nbsp; try<br>&nbsp; if opendialog1.Execute then<br>&nbsp; begin<br>&nbsp; &nbsp; opendialog1.Filter:='*.doc';<br>&nbsp; &nbsp; MemoryStream.LoadFromFile(opendialog1.FileName);<br>&nbsp; end<br>&nbsp; else exit;<br>&nbsp; try<br>&nbsp; if DbGrid1.SelectedRows.Count &gt;1 then<br>&nbsp; begin<br>&nbsp; &nbsp; for I := 0 to DbGrid1.SelectedRows.Count -1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; DBGrid1.DataSource.DataSet.GotoBookMark(Pointer(DBGrid1.Selectedrows.Items));<br>&nbsp; &nbsp; &nbsp; QRSDOC.Close;<br>&nbsp; &nbsp; &nbsp; QRSDOC.SQL.Clear;<br>&nbsp; &nbsp; &nbsp; QRSDOC.SQL.Add('update Item_batch set item_doc2=:cs_doc2 where Item_batchno=:cs_batchno');<br>&nbsp; &nbsp; &nbsp; QRSDOC.Parameters.ParamByName('cs_batchno').Value:=dbGrid1.DataSource.DataSet.FieldByName('Item_batchno').AsString;<br>&nbsp; &nbsp; &nbsp; QRSDOC.Parameters.ParamByName('cs_doc2').LoadFromStream(MemoryStream,ftgraphic);<br>&nbsp; &nbsp; &nbsp; QRSDOC.ExecSQL;<br>&nbsp; &nbsp; end;<br>&nbsp; showmessage('保存DOC文件成功!');<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; QRSDOC.Close;<br>&nbsp; &nbsp; QRSDOC.SQL.Clear;<br>&nbsp; &nbsp; QRSDOC.SQL.Add('update Item_batch set item_doc2=:cs_doc2 where Item_batchno=:cs_batchno');<br>&nbsp; &nbsp; QRSDOC.Parameters.ParamByName('cs_batchno').Value:=dbGrid1.DataSource.DataSet.FieldByName('Item_batchno').AsString;<br>&nbsp; &nbsp; QRSDOC.Parameters.ParamByName('cs_doc2').LoadFromStream(MemoryStream,ftgraphic);<br>&nbsp; &nbsp; QRSDOC.ExecSQL;<br>&nbsp; &nbsp; showmessage('保存DOC文件成功!');<br>&nbsp; end;<br>&nbsp; dbGrid1.DataSource.DataSet.Refresh;<br>&nbsp; except<br>&nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; MemoryStream.Free;<br>&nbsp; end;<br>end;<br><br>procedure TF_PFSJCXTJ.DOC2Click(Sender: TObject);<br>var<br>&nbsp; TempMemory:TStream;<br>&nbsp; Memory:TMemoryStream;<br>&nbsp; fname:string;<br>&nbsp; a:OleVariant;<br>begin<br>&nbsp; try<br>&nbsp; &nbsp;QRSDOC.CLOSE;<br>&nbsp; &nbsp;QRSDOC.SQL.CLEAR;<br>&nbsp; &nbsp;QRSDOC.SQL.ADD('select item_doc2 from Item_batch where Item_batchno=:cs_batchno');<br>&nbsp; &nbsp;QRSDOC.Parameters.ParamByName('cs_batchno').Value:=dbGrid1.DataSource.DataSet.FieldByName('Item_batchno').AsString;<br>&nbsp; &nbsp;QRSDOC.OPEN;<br>&nbsp; &nbsp;fname:='c:/3.doc';<br>&nbsp; &nbsp;QRSDOC.Edit;<br>&nbsp; &nbsp;Memory:=TMemoryStream.Create;<br>&nbsp; &nbsp;TempMemory:=QRSDOC.CreateBlobStream(QRSDOC.fieldbyname('item_doc2'),bmReadWrite);<br>&nbsp; &nbsp;Memory.CopyFrom(TempMemory,TempMemory.Size);<br>&nbsp; &nbsp;Memory.SaveToFile(fname);<br>&nbsp; &nbsp;a:=fname;<br>&nbsp; &nbsp;WordApplication1.Connect;<br>&nbsp; &nbsp;WordApplication1.Visible:=true;<br>&nbsp; &nbsp;WordDocument1.Connectto(WordApplication1.Documents.Open(a,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam));<br>&nbsp; &nbsp;WordApplication1.Disconnect;<br>&nbsp; finally<br>&nbsp; &nbsp; Memory.Free;<br>&nbsp; end;<br><br>end;
 
接受答案了.
 
后退
顶部