各位大侠新年好,在下遇到了这样的问题:
我想用delphi向WORD文件中添加表格,根据录制的office宏的提示,使用了如下的代码:
with wordapplication1 do
begin
ActiveDocument.Tables.Add(Selection.Range,3,1,wdWord9TableBehavior,wdAutoFitFixed);
end;
可是编译不通过,说是Types of actual and formal var parameters must be identical,我该怎么办呢?请执教!
再次表示感谢
我想用delphi向WORD文件中添加表格,根据录制的office宏的提示,使用了如下的代码:
with wordapplication1 do
begin
ActiveDocument.Tables.Add(Selection.Range,3,1,wdWord9TableBehavior,wdAutoFitFixed);
end;
可是编译不通过,说是Types of actual and formal var parameters must be identical,我该怎么办呢?请执教!
再次表示感谢
msWord: Variant;
doc, sel, tab: Variant;
begin
msWord := CreateOleObject('Word.Application');
msWord.Visible := True; doc := msWord.Documents.Add;
sel := msWord.Selection; sel.TypeText('Some System Parameters:');
sel.HomeKey(5 {wdLine}, 1 {wdExtend});
sel.Font.Bold := True;
sel.EndKey(5 {wdLine}, 0 {wdMove});
sel.Font.Bold := False; tab := doc.Tables.Add(sel.Range, 3, 2); sel.TypeText('Operating System');
sel.MoveRight(12 {wdCell});
sel.TypeText(msWord.System.OperatingSystem);
sel.MoveLeft(12 {wdCell});
sel.MoveDown(5 {wdLine}); sel.TypeText('Processor');
sel.MoveRight(12 {wdCell});
sel.TypeText(msWord.System.ProcessorType);
sel.MoveLeft(12 {wdCell});
sel.MoveDown(5 {wdLine}); sel.TypeText('Word Version');
sel.MoveRight(12 {wdCell});
sel.TypeText(MsWord.Version);
sel.MoveLeft(12 {wdCell});
sel.MoveDown(5 {wdLine});
end;这个是脚本语言的一个代码,对你应该有用,
我想知道你是怎么控制word的工具栏的,它的显示不好处理。
tbl : Table;
i,j:integer;
un_Var,ex_Var,cnt_Var:OleVariant;
row_num,col_num:integer;
st:string;
begin
// 在Word中新建一个文档,并添加文本,然后设置粗体和字体大小
WordApplication1.Connect;
WordApplication1.Visible := True;
WordApplication1.Documents.Add(EmptyParam,EmptyParam);
WordDocument1.Connect;
WordApplication1.ActiveWindow.View.Type_:= wdNormalView;
WordApplication1.Selection.Font.Name :='黑体';
WordApplication1.Selection.Font.Size := 16;
WordApplication1.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter;
WordApplication1.Selection.TypeText('昆明市土地信息系统表格输出');
WordApplication1.Selection.TypeParagraph;
WordApplication1.Selection.TypeParagraph;
WordApplication1.Selection.Font.Name := '宋体';
WordApplication1.Selection.Font.Size :=12;
WordApplication1.Selection.ParagraphFormat.Alignment := wdAlignParagraphRight;
WordApplication1.Selection.TypeText('日期'+formatdatetime('yyyy"年"mm"月"dd"日"',now));
WordApplication1.Selection.TypeParagraph;
WordApplication1.Selection.TypeParagraph;//回车
WordApplication1.Selection.ParagraphFormat.Alignment := wdAlignParagraphLeft;
row_num:=table1.RecordCount;
col_num:=table1.Fields.Count;
tbl := WordApplication1.ActiveDocument.Tables.Add(WordApplication1.Selection.Range,row_num+1,Col_num);
un_Var:=wdCharacter;
cnt_Var:=1;
ex_Var:=wdMove;
table1.First;
for j := 0 to Col_num-1 do //标题
begin
st:=table1.Fields.Fields[j].FieldName;
WordApplication1.Selection.TypeText(st);
WordApplication1.Selection.MoveRight(un_Var,cnt_Var,ex_Var);
end;
for i := 0 to row_num-1 do // 行
begin
for j := 0 to Col_num-1 do // 列
begin
st:=table1.Fields.Fields[j].AsString;
WordApplication1.Selection.TypeText(st);
WordApplication1.Selection.MoveRight(un_Var,cnt_Var,ex_Var);
end;
WordApplication1.Selection.MoveRight(un_Var,cnt_Var,ex_Var);
table1.next;
end;
WordApplication1.Selection.TypeText('制表人:阎磊');
WordApplication1.Selection.TypeParagraph;
end;
word:variant;
begin
word:=createoleobject('word.application');
word.visible:=true;
word.documents.open('e:\abc.doc',false);
word.activedocument.range(0,0);
word.activedocument.tables.add(word.activedocument.range,2,3);
word.activedocument.sellection.insertrowsbelow(1);
end;