我在网上搜索了好久都没找到答案,如何将word保存到数据库?(200分)

  • 主题发起人 主题发起人 maozhuxi
  • 开始时间 开始时间
M

maozhuxi

Unregistered / Unconfirmed
GUEST, unregistred user!
1.如何将word保存到数据库?<br>2.保存到access或者oracle都行。<br>3.保存后如何打开。<br>4.我的机子上是安装了office的。<br>5.如果能加上查询保存后word中的内容更好。<br>6.最好有demo.<br>7.回答了第一个问题200分,其他问题都回答后再加300分。
 
搜索以前的贴子,有很多的。。。。<br>///////<br>1.用Blod数据流保存到数据库<br>2.打开也可用同样的方法逆向。。
 
很简单:<br>建议表字段用:image 因为office文件比较大<br>TBlobField(adotable1.FieldByName('doc')).LoadFromFile('FileName')<br>在读时在数据流里把格式变为.doc,方便打开
 
//存入数据库<br>TBlobField(adotable1.FieldByName('doc')).LoadFromFile('FileName');<br>//存出数据库<br>TBlobField(adotable1.FieldByName('doc')).SavetoFile('FileName');
 
能不能具体点,我查找了离线数据库好多帖子,都是实际有用的不行,谁能写点具体的代码或做个用access的demo,谢谢了。
 
给你demo的代码,已经测试完毕。如果还不行的话告诉我E-Mail,我发给你。<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls, Word2000, OleServer;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; WordApplication1: TWordApplication;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; OpenDialog1: TOpenDialog;<br>&nbsp; &nbsp; ADOConnection1: TADOConnection;<br>&nbsp; &nbsp; ADOQuery1: TADOQuery;<br>&nbsp; &nbsp; DataSource1: TDataSource;<br>&nbsp; &nbsp; DBGrid1: TDBGrid;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; m_File:TMemoryStream;<br>begin<br>&nbsp; if OpenDialog1.Execute then<br>&nbsp; begin<br>&nbsp; &nbsp; m_File:=TMemoryStream.Create;<br>&nbsp; &nbsp; m_File.LoadFromFile(OpenDialog1.FileName);<br>&nbsp; &nbsp; ADOQuery1.Append;<br>&nbsp; &nbsp; TBlobField(ADOQuery1.FieldByName('文件')).LoadFromStream(m_File);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; ADOQuery1.Post;<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; m_File.Free;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br>&nbsp; Template : OleVariant;<br>&nbsp; NewTemplate : OleVariant;<br>&nbsp; DocuType : OleVariant;<br>&nbsp; Visible : OleVariant;<br>begin<br>&nbsp; if ADOQuery1.IsEmpty then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('当前数据库为空!');<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; TBlobField(ADOQuery1.FieldByName('文件')).SaveToFile('C:/temp.doc');<br>&nbsp; &nbsp; WordApplication1.Connect;<br>&nbsp; &nbsp; WordApplication1.Visible:=True;<br>&nbsp; &nbsp; Template:='C:/temp.doc';<br>&nbsp; &nbsp; NewTemplate:=False;<br>&nbsp; &nbsp; DocuType:=0;<br>&nbsp; &nbsp; Visible:=True;<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; //WordApp.Documents.Add(Template:='C:/Doc1.dot',NewTemplate:=False,DocuType,Visible);<br>&nbsp; &nbsp; &nbsp; WordApplication1.Documents.Add(Template,NewTemplate,DocuType,Visible);<br>&nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; showmessage('打开文档失败!');<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;
 
308035395@mail.qq.com<br>能对保存了的word中的内容进行查询,我的意思是这样,比如有10个word文件,现在假设这十个word文件都已经保存到了数据库,现在我想查找其中有内容为xxxx的word文件,并显示这个word文件。<br>能否留下你的qq?<br>谢谢!
 
不行啊,我按照你上面的去写的,第一个button就不能通过,到ADOQuery1.Append;<br>就不行了,首先好像说是数据库关闭的,我用adoquery.active又说缺少sql语句,我都不知道怎么改,希望你能再次指教。
 
先去学点基础的东西吧。人家都写的这么详细了还不会,没办法了。
 
发现上面少了一个sql语句,我自己加上去了。<br>现在还有个问题没解决了,就是上面说的对存入数据库字段为ole的word文件的内容进行查询。200分给Ray.D.Chou。还剩300分的家底全部奉上,希望能谁帮忙解决下,谢谢!
 
OLE在数据库没办法查询吧,它是二进制的,只有存出来时在WORD中操作。
 
多人接受答案了。
 
后退
顶部