怎么调用WORD控件呀?会用SERVES的高手来解答呀!急~~~~~~~~~~~ 我需要通过调用word控件,在里面写一些东西,然后保存到数据库中,请问我该怎么做保存的内容应该以什么形式存入数据库中,保存的可能包括一些图形哦。请高手指点!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 image,blob类型这些都行的,用TStream存到数据库就行了,试试应该可以的 吐血奉献了,我这个研究很久了!可是我还是不能很好的控制word!存如数据库我是解决了!这是我自己做的一个软件里的代码,你研究一下了!其中内容字段就是用来记录日记的! with DataMdl.RijiADOQry do begin Append;Edit; if DateTimePicker1.DateTime>0 then DateTimePicker1.DateTime:=Int(DateTimePicker1.DateTime)+Time else DateTimePicker1.DateTime:=-(Abs(Trunc(DateTimePicker1.DateTime))+Time); FieldByName('编号').AsInteger:=DataMdl.UserADOQry.FieldByName('记录数').asInteger+1; FieldByName('用户名').AsString:=MainFrm.UserNameSTxt.Caption; FieldByName('日期').AsDateTime:=DateTimePicker1.DateTime; FieldByName('心情').AsString:=XinQingCBB.Text; FieldByName('天气').AsString:=TianQiCBB.Text; FieldByName('主题').AsString:=TitleEdt.Text; FieldByName('备注').AsString:=Memo1.Lines.Text; FieldByName('加锁').AsBoolean:=LockedCkB.Checked; try MemoryStream:=TMemoryStream.Create; try if WordRBtn.Checked then begin if DataMdl.HasWord2000 then try OleContainer1.SaveToStream(MemoryStream); FieldByName('日记格式').AsString:='.doc'; except MessageBox(0,'请安装Word2000,才能保存Word2000格式的日记!现在只保存Rtf格式的空日记!','对不起',MB_OK+MB_IconError); RichEdit1.Lines.Clear; RichEdit1.Lines.SaveToStream(MemoryStream); FieldByName('日记格式').AsString:='.rtf'; end end else begin RichEdit1.Lines.SaveToStream(MemoryStream); FieldByName('日记格式').AsString:='.rtf'; end; try MemoryStream.Position:=0; TBlobField(FieldByName('内容')).LoadFromStream(MemoryStream); except end; post; DataMdl.IncRecoreNumer; MainFrm.TianQiCBBExit(TianQiCBB);//检测添加新天气种类 MainFrm.XinQingCBBExit(XinQingCBB);//检测添加新心情种类 StatusBar1.Panels[0].Text:='日记数:'+FieldByName('编号').AsString; StatusBar1.Panels[2].Text:=''; DataMdl.OutputData(LockedCkB.Checked); except DataMdl.RijiADOQry.Cancel; MessageBox(handle,'请写好日记在添加!','错误',MB_OK+MB_ICONERROR); end; finally MemoryStream.Free; end; end;except DataMdl.RijiADOQry.Cancel; MessageBox(handle,'未可预料的错误,添加失败!','错误',MB_OK+MB_ICONERROR);end; unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Word97, OleServer, OleCtnrs, ActnList, DdeMan,ComObj;type TForm1 = class(TForm) WordApplication: TWordApplication; WordDocument1: TWordDocument; OpenDialog1: TOpenDialog; Button1: TButton; Button3: TButton; OleContainer1: TOleContainer; DdeClient: TDdeClientConv; Button4: TButton; Label1: TLabel; Button5: TButton; Button6: TButton; Label2: TLabel; Button2: TButton; Button7: TButton; Label3: TLabel; Label4: TLabel; Button8: TButton; ComboBox1: TComboBox; Label5: TLabel; Button9: TButton; Button10: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure ComboBox1Change(Sender: TObject); procedure Button9Click(Sender: TObject); procedure Button10Click(Sender: TObject); private { Private declarations } public { Public declarations } procedure RunMacro(Macro:pChar); end;var Form1: TForm1;implementation{$R *.DFM}//放入system里的DdeClientCov并把name:=DDEClientprocedure TForm1.RunMacro(Macro:pChar);//实行宏的函数 var pMacro:array[0..80] of Char; beginDDEClient.SetLink('Winword','System');{设置连接} DDEClient.OpenLink;{按设置打开连接}StrPCopy(pMacro,Macro); if Not DDEClient.ExecuteMacro(pMacro,false) then{执行宏命令} ShowMessage('实行宏命令失败!'); DDEClient.CloseLink;{断开连接} end;procedure TForm1.FormCreate(Sender: TObject);begintry wordapplication.Connect;except showmessage('你没装word!'); Application.Terminate;end; end;procedure TForm1.Button1Click(Sender: TObject);var itemindex :olevariant; filename, confirmconversions, readonly, addtorecentfiles, passworddocument, passwordtemplate, revert, writepassworddocument, writepasswordtemplate, format: olevariant;begin opendialog1.Title:='请选择一个要打开的word文件'; opendialog1.Filter:='word文档|*.doc|rtf文件|*.rtf|文本文件|*.txt|所有文件|*.*'; if not opendialog1.Execute then exit;{open document} filename :=openDialog1.filename; confirmconversions := false; readonly := false;//只读 addtorecentfiles := false;//是否覆盖原文件 passworddocument := ''; passwordtemplate := ''; revert := true; writepassworddocument := ''; writepasswordtemplate := ''; format := wdopenformatdocument; wordapplication.documents.open( filename, confirmconversions,readonly, addtorecentfiles, passworddocument, passwordtemplate,revert, writepassworddocument, writepasswordtemplate, format );{assign worddocument component} itemindex :=wordapplication.Documents.Count; worddocument1.connectto(wordapplication.documents.item(itemindex));{turn spell checking of because it takes a long time if enabled and slows down winword} wordapplication.options.checkspellingasyoutype := false; wordapplication.options.checkgrammarasyoutype := false; Wordapplication.Visible:=true;end;procedure TForm1.FormDestroy(Sender: TObject);begin try worddocument1.Close; worddocument1.Disconnect; except end; try wordapplication.Disconnect; wordapplication.Quit; except end;end;procedure TForm1.Button3Click(Sender: TObject);begin button1.click; opendialog1.Title:='请选择一个要差到当前文件末尾的word文件'; opendialog1.InitialDir:=ExtractFilePath(application.ExeName); if not opendialog1.Execute then exit ; worddocument1.Paragraphs.Last.Range.InsertFile(Opendialog1.fileName,EmptyParam,EmptyParam, EmptyParam,EmptyParam);end;procedure TForm1.Button4Click(Sender: TObject);var v_doc,v_range:Variant;itemindex:OleVariant; filename, confirmconversions, readonly, addtorecentfiles, passworddocument, passwordtemplate, revert, writepassworddocument, writepasswordtemplate, format: olevariant;begin try wordapplication.Connect; except showmessage('你没装word!'); Application.Terminate; end; opendialog1.Title:='请选择要打开的文件'; opendialog1.InitialDir:=ExtractFilePath(application.ExeName); if not opendialog1.Execute then exit; filename :=openDialog1.filename; confirmconversions := false; readonly := false; addtorecentfiles := false; passworddocument := ''; passwordtemplate := ''; revert := true; writepassworddocument := ''; writepasswordtemplate := ''; format := wdopenformatdocument; wordapplication.documents.open(filename, confirmconversions, readonly, addtorecentfiles, passworddocument, passwordtemplate, revert, writepassworddocument, writepasswordtemplate, format);//打开一个word文档 wordapplication.Visible:=true; itemindex:=wordapplication.documents.count;//获得刚打开的文件的编号 v_doc:=wordapplication.documents.Item(itemindex); v_doc.range.insertafter('1.');//插入编号 v_range:=v_doc.Range((v_doc.Paragraphs.Item(v_doc.Paragraphs.Count)).Range.End-1); {v_doc.paragraphs是整篇文章的段落对象,这个是一个段落对象数组,用item获得具体的一个段落, count就是数组中段落的个数。然后就用这个v_doc.Paragraphs.Item(v_doc.Paragraphs.Count))对 象取得它的定位range对象,range表示的这一整个字串,用end-1定位到结尾。 } opendialog1.title:='请选择一个要插入的word文档'; opendialog1.InitialDir:=ExtractFilePath(application.ExeName); if not opendialog1.execute then exit; v_range.insertfile(opendialog1.filename);end;procedure TForm1.Button5Click(Sender: TObject);begin wordapplication.Connect; wordapplication.Visible:=true;end;procedure TForm1.Button6Click(Sender: TObject);var v_app:Variant;begin //注意加unit ComObj v_app:=CreateOleObject('word.appliction'); v_app.visible:=true;end; 感谢 catfather46(猫爸)提供的信息,希望各位继续努力!因为我做的是一个考试系统,要求录入试题(有的试题可能很长哦,有的可能还有图形),但是我还不太熟悉DEPHI,所以在此向各位大哥,大姐们请教,希望各位能给予我有用的帮助!!千万不要吝啬笔墨哦~~~~~~~~~~~~~~~~~~~,我觉得好的有高分相送! 关于验证码图片的保存 急救,在QReport报表中怎样在符合条件的项目后打上“*”号 怎样用Delphi开发网站 请教高手:有关对象和组件对象生命期管理的问题?顶~~~~ 关于数组 如何让LISTVIEW中的ITEM能够显示 hint? Delphi新手问题? win2003为什么SQL Server无法连接 如何把Delphi写的程序封包? 父窗口调用子窗口,子窗口又如何调用父窗口里的一个特殊的函数(方法)? 使用fastreport如何打印Tlist中存的數據. 异型窗体。。。。。。。。。。。。。。。。。。。。。。。。。。。。。急急急。。。。。。。。。。。。。。。。。。。
用TStream存到数据库就行了,试试应该可以的
存如数据库我是解决了!
这是我自己做的一个软件里的代码,你研究一下了!
其中内容字段就是用来记录日记的!
with DataMdl.RijiADOQry do
begin
Append;Edit;
if DateTimePicker1.DateTime>0 then
DateTimePicker1.DateTime:=Int(DateTimePicker1.DateTime)+Time
else DateTimePicker1.DateTime:=-(Abs(Trunc(DateTimePicker1.DateTime))+Time);
FieldByName('编号').AsInteger:=DataMdl.UserADOQry.FieldByName('记录数').asInteger+1;
FieldByName('用户名').AsString:=MainFrm.UserNameSTxt.Caption;
FieldByName('日期').AsDateTime:=DateTimePicker1.DateTime;
FieldByName('心情').AsString:=XinQingCBB.Text;
FieldByName('天气').AsString:=TianQiCBB.Text;
FieldByName('主题').AsString:=TitleEdt.Text;
FieldByName('备注').AsString:=Memo1.Lines.Text;
FieldByName('加锁').AsBoolean:=LockedCkB.Checked;
try
MemoryStream:=TMemoryStream.Create;
try
if WordRBtn.Checked then
begin
if DataMdl.HasWord2000 then
try
OleContainer1.SaveToStream(MemoryStream);
FieldByName('日记格式').AsString:='.doc';
except
MessageBox(0,'请安装Word2000,才能保存Word2000格式的日记!现在只保存Rtf格式的空日记!','对不起',MB_OK+MB_IconError);
RichEdit1.Lines.Clear;
RichEdit1.Lines.SaveToStream(MemoryStream);
FieldByName('日记格式').AsString:='.rtf';
end
end
else begin
RichEdit1.Lines.SaveToStream(MemoryStream);
FieldByName('日记格式').AsString:='.rtf';
end;
try
MemoryStream.Position:=0;
TBlobField(FieldByName('内容')).LoadFromStream(MemoryStream);
except
end;
post;
DataMdl.IncRecoreNumer;
MainFrm.TianQiCBBExit(TianQiCBB);//检测添加新天气种类
MainFrm.XinQingCBBExit(XinQingCBB);//检测添加新心情种类
StatusBar1.Panels[0].Text:='日记数:'+FieldByName('编号').AsString;
StatusBar1.Panels[2].Text:='';
DataMdl.OutputData(LockedCkB.Checked);
except
DataMdl.RijiADOQry.Cancel;
MessageBox(handle,'请写好日记在添加!','错误',MB_OK+MB_ICONERROR);
end;
finally
MemoryStream.Free;
end;
end;
except
DataMdl.RijiADOQry.Cancel;
MessageBox(handle,'未可预料的错误,添加失败!','错误',MB_OK+MB_ICONERROR);
end;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Word97, OleServer, OleCtnrs, ActnList, DdeMan,ComObj;type
TForm1 = class(TForm)
WordApplication: TWordApplication;
WordDocument1: TWordDocument;
OpenDialog1: TOpenDialog;
Button1: TButton;
Button3: TButton;
OleContainer1: TOleContainer;
DdeClient: TDdeClientConv;
Button4: TButton;
Label1: TLabel;
Button5: TButton;
Button6: TButton;
Label2: TLabel;
Button2: TButton;
Button7: TButton;
Label3: TLabel;
Label4: TLabel;
Button8: TButton;
ComboBox1: TComboBox;
Label5: TLabel;
Button9: TButton;
Button10: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure RunMacro(Macro:pChar);
end;var
Form1: TForm1;implementation{$R *.DFM}
//放入system里的DdeClientCov并把name:=DDEClient
procedure TForm1.RunMacro(Macro:pChar);//实行宏的函数
var pMacro:array[0..80] of Char;
begin
DDEClient.SetLink('Winword','System');{设置连接}
DDEClient.OpenLink;{按设置打开连接}
StrPCopy(pMacro,Macro);
if Not DDEClient.ExecuteMacro(pMacro,false) then{执行宏命令}
ShowMessage('实行宏命令失败!');
DDEClient.CloseLink;{断开连接}
end;procedure TForm1.FormCreate(Sender: TObject);
begin
try
wordapplication.Connect;
except
showmessage('你没装word!');
Application.Terminate;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
itemindex :olevariant;
filename, confirmconversions, readonly, addtorecentfiles,
passworddocument, passwordtemplate, revert,
writepassworddocument, writepasswordtemplate, format: olevariant;
begin
opendialog1.Title:='请选择一个要打开的word文件';
opendialog1.Filter:='word文档|*.doc|rtf文件|*.rtf|文本文件|*.txt|所有文件|*.*';
if not opendialog1.Execute then exit;
{open document}
filename :=openDialog1.filename;
confirmconversions := false;
readonly := false;//只读
addtorecentfiles := false;//是否覆盖原文件
passworddocument := '';
passwordtemplate := '';
revert := true;
writepassworddocument := '';
writepasswordtemplate := '';
format := wdopenformatdocument; wordapplication.documents.open( filename, confirmconversions,
readonly, addtorecentfiles, passworddocument, passwordtemplate,
revert, writepassworddocument, writepasswordtemplate, format );{assign worddocument component}
itemindex :=wordapplication.Documents.Count;
worddocument1.connectto(wordapplication.documents.item(itemindex));
{turn spell checking of because it takes a long time if enabled and slows down winword}
wordapplication.options.checkspellingasyoutype := false;
wordapplication.options.checkgrammarasyoutype := false;
Wordapplication.Visible:=true;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
try
worddocument1.Close;
worddocument1.Disconnect;
except
end;
try
wordapplication.Disconnect;
wordapplication.Quit;
except
end;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
button1.click;
opendialog1.Title:='请选择一个要差到当前文件末尾的word文件';
opendialog1.InitialDir:=ExtractFilePath(application.ExeName);
if not opendialog1.Execute then exit ;
worddocument1.Paragraphs.Last.Range.InsertFile(Opendialog1.fileName,EmptyParam,EmptyParam,
EmptyParam,EmptyParam);
end;procedure TForm1.Button4Click(Sender: TObject);
var v_doc,v_range:Variant;itemindex:OleVariant;
filename, confirmconversions, readonly, addtorecentfiles,
passworddocument, passwordtemplate, revert,
writepassworddocument, writepasswordtemplate, format: olevariant;
begin
try
wordapplication.Connect;
except
showmessage('你没装word!');
Application.Terminate;
end;
opendialog1.Title:='请选择要打开的文件';
opendialog1.InitialDir:=ExtractFilePath(application.ExeName);
if not opendialog1.Execute then exit;
filename :=openDialog1.filename;
confirmconversions := false;
readonly := false;
addtorecentfiles := false;
passworddocument := '';
passwordtemplate := '';
revert := true;
writepassworddocument := '';
writepasswordtemplate := '';
format := wdopenformatdocument;
wordapplication.documents.open(filename, confirmconversions,
readonly, addtorecentfiles, passworddocument, passwordtemplate,
revert, writepassworddocument, writepasswordtemplate, format);//打开一个word文档
wordapplication.Visible:=true;
itemindex:=wordapplication.documents.count;//获得刚打开的文件的编号
v_doc:=wordapplication.documents.Item(itemindex);
v_doc.range.insertafter('1.');//插入编号
v_range:=v_doc.Range((v_doc.Paragraphs.Item(v_doc.Paragraphs.Count)).Range.End-1);
{v_doc.paragraphs是整篇文章的段落对象,这个是一个段落对象数组,用item获得具体的一个段落,
count就是数组中段落的个数。然后就用这个v_doc.Paragraphs.Item(v_doc.Paragraphs.Count))对
象取得它的定位range对象,range表示的这一整个字串,用end-1定位到结尾。 }
opendialog1.title:='请选择一个要插入的word文档';
opendialog1.InitialDir:=ExtractFilePath(application.ExeName);
if not opendialog1.execute then exit;
v_range.insertfile(opendialog1.filename);
end;procedure TForm1.Button5Click(Sender: TObject);
begin
wordapplication.Connect;
wordapplication.Visible:=true;
end;procedure TForm1.Button6Click(Sender: TObject);
var v_app:Variant;
begin
//注意加unit ComObj
v_app:=CreateOleObject('word.appliction');
v_app.visible:=true;
end;
因为我做的是一个考试系统,要求录入试题(有的试题可能很长哦,有的可能还有图形),但是我还不太熟悉DEPHI,所以在此向各位大哥,大姐们请教,希望各位能给予我有用的帮助!!千万不要吝啬笔墨哦~~~~~~~~~~~~~~~~~~~,我觉得好的有高分相送!