郁闷了好几天,究竟是什么问题?(关于打开/读写WORD文档) (30分)

  • 主题发起人 主题发起人 sunsong
  • 开始时间 开始时间
S

sunsong

Unregistered / Unconfirmed
GUEST, unregistred user!
我的机器是word 2000,前两天本程序运行良好,但现在运行后始终不出现WORD窗体,只是在进程中能看到'WINWORD.EXE',把本程序放到另外一个装WORD2002的'机器甲'上,运行良好.然而,同样是word2002的机器乙,跟我的反应一样,还是不出来,郁闷死人了!有没有人遇到过同样的问题?究竟怎么回事?
代码如下(delphi6,用D7也试过,一样):
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleServer, Word2000, DB, ADODB;

type
TForm1 = class(TForm)
TABLE1: TADOTable;
ADOConnection1: TADOConnection;
WordDocument1: TWordDocument;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
Bookmark: TBookmark;
RangeW: Word2000.Range;
v1: Variant;
ov1: OleVariant;
Row1: Word2000.Row;
begin
WordDocument1.Activate;
WordDocument1.Connect ;
// insert title
WordDocument1.Range.Text := 'American Capitals from ' + Table1.TableName;
WordDocument1.Range.Font.Size := 14;
// disable the UI
Table1.DisableControls;
try
// store the current position
Bookmark := Table1.GetBookmark;
try
// scan the database table
Table1.First;
while not Table1.EOF do
begin
// send the two fields
WordDocument1.Range.InsertParagraphAfter;
WordDocument1.Paragraphs.Last.Range.Text :=
Table1.Fields[0].AsString + #9 +
Table1.Fields[1].AsString;
Table1.Next;
end;
finally
// go back to the bookmark and destroy it
Table1.GotoBookmark (Bookmark);
Table1.FreeBookmark (Bookmark);
end;
finally
// re-enable the controls
Table1.EnableControls;
end;
RangeW := WordDocument1.Content;
v1 := RangeW;
v1.ConvertToTable (#9, 19, 2);
Row1 := WordDocument1.Tables.Item(1).Rows.Get_First;
Row1.Range.Bold := 1;
Row1.Range.Font.Size := 30;
Row1.Range.InsertParagraphAfter;
ov1 := ' ';





end;


end.
 
可能跟你的WORD有关,重装下WORD!
 
try
WordApplication1.Connect;
messagedlg('没有安装Word',mterror,[mbok],0);
abort;
end;
这段话,我每次都等的机器死掉,为何???
 
少见,你试试 CreateOleObject 吧,出来的是 variant,可以动态 Dispatch,比用控
件好点,这也类似于 C 和 VB 的调用模型
 
to DragonPC_???:
用你的方式,如何启动/关闭word?我每次使用,我用最上面的代码,word都只在线程列表中,不显式运行.第二次运行还常有问题
 
如你所说,应该用 TWordApplication ,用 Visable := true; 设置显示
用 Documents.Items[1] 进行操作
 

Similar threads

后退
顶部