C
coolmyf
Unregistered / Unconfirmed
GUEST, unregistred user!
请大家看看这段代码有什么问题,其中WordApplication1和WordDocument1使用的是Servers页的控件,程序中想生成5行2 列的表格,但是程序运行后除了生成5行2列的表格外,还在这个表格的第一个单元格内又生成了一个5行2列的小的表格,很奇怪,不知道该怎么解决.我用的是Delphi7 和 Word2003
procedure TMakeTable.Button1Click(Sender: TObject);
var Template,NewTemplate,wdDocumentType,wdVisible,
DefaultTableBehavior,AutoFitBehaviorlevariant;
begin
try
WordApplication1.Connect;//呼叫word服务
except
MessageDlg('Word没有安装,请重试!', mtError, [mbOk], 0);
Abort;
end;
WordApplication1.Visible := True;
WordApplication1.Caption := '文档一';
//新建文档
Template := EmptyParam;
NewTemplate := True;
wdDocumentType := wdNewBlankDocument;
wdVisible := True;
//创建新的word文档
WordDocument1.ConnectTo(WordApplication1.Documents.Add(Template, NewTemplate,wdDocumentType,wdVisible));
WordApplication1.Selection.TypeText('aaaaaaaaaaa');
WordApplication1.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WordApplication1.Selection.TypeParagraph;
DefaultTableBehavior:=wdWord9TableBehavior;
AutoFitBehavior:=wdAutoFitFixed;
WordApplication1.ActiveDocument.Tables.Add(WordApplication1.Selection.Range,
5,2,DefaultTableBehavior,AutoFitBehavior);
end;
代码:
var Template,NewTemplate,wdDocumentType,wdVisible,
DefaultTableBehavior,AutoFitBehaviorlevariant;
begin
try
WordApplication1.Connect;//呼叫word服务
except
MessageDlg('Word没有安装,请重试!', mtError, [mbOk], 0);
Abort;
end;
WordApplication1.Visible := True;
WordApplication1.Caption := '文档一';
//新建文档
Template := EmptyParam;
NewTemplate := True;
wdDocumentType := wdNewBlankDocument;
wdVisible := True;
//创建新的word文档
WordDocument1.ConnectTo(WordApplication1.Documents.Add(Template, NewTemplate,wdDocumentType,wdVisible));
WordApplication1.Selection.TypeText('aaaaaaaaaaa');
WordApplication1.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
WordApplication1.Selection.TypeParagraph;
DefaultTableBehavior:=wdWord9TableBehavior;
AutoFitBehavior:=wdAutoFitFixed;
WordApplication1.ActiveDocument.Tables.Add(WordApplication1.Selection.Range,
5,2,DefaultTableBehavior,AutoFitBehavior);
end;