C
csm55
Unregistered / Unconfirmed
GUEST, unregistred user!
wordDocument.Tables.Add(WordDocument.Range,1,6,emptyparam,fitWeidth);
先用这个语句建一个新表格,而后再往插一行,变成二行六列,,
最后再用wordDocument.Tables.Add(WordDocument.Range,1,7,emptyparam,fitWeidth);
建一行七列的,不知怎得把前面建的二行六列的表格给覆盖了,只有后面一行七列的啦
在word中录制的宏:
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
6, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
Selection.TypeText Text:="工商类别"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="子类别"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="广告名称"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="版本"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="总播出次数"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="时长"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.InsertRows 1
Selection.Collapse Direction:=wdCollapseStart
Selection.TypeText Text:="化妆品"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="护肤"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="淋浴"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="9秒"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="1"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="00:00:29"
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="广告个数 24 总播出次数 36 总播出时长 00:15:15"
Selection.TypeParagraph
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
6, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
Selection.TypeText Text:="工商类别"
CommandBars("Stop Recording".Visible = False
==================================================================
转成delphi的代码:
procedure TForm1.Button1Click(Sender: TObject);
var
typename:string;
sub_ad_counts,sub_play_counts,sub_play_sum,ad_counts,play_counts,play_sum:integer;
docs,template,newtemplate,itemindex,savepath,WwdPageBreak1levariant;
wordtable,fitWeidthlevariant;
oleUnit,oleCount,oleCount2,oleExtend,OleDirectionlevariant;
i,colcount,RowCount,col,row:integer;
begin
try
screen.Cursor:=crhourglass;
template:=emptyparam;
newtemplate:=true;
itemindex:=1;
try
wordapplication.Connect;
except
messagedlg('word未安装',mterror,[mbOk],0);
abort;
end;
wordapplication.Visible:=true;
wordapplication.Caption:='媒体广告分类统计清单';
template:=emptyparam;
newtemplate:=false;
docs:=wordapplication.Documents;
docs.add(newtemplate:=true);
worddocument.ConnectTo(wordapplication.Documents.Item(itemindex));
wordapplication.Options.CheckSpellingAsYouType:=false;
wordapplication.Options.CheckGrammarAsYouType:=false;
Wordapplication.Selection.Font.Size:=12;
Wordapplication.Selection.Font.Name := 'gb-2312';
//======================开始导入DBGRIDEH的内容
oleunit:=wdCharacter;
olecount:=1;
oleCount2:=2;
OleDirection:=wdCollapseStart;
fitWeidth:=wdAutoFitContent; //wordtable.cell(1,col).range.text
wordDocument.Tables.Add(WordDocument.Range,1,6,emptyparam,fitWeidth);
wordapplication.Selection.TypeText('工商类别');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('子类别');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('广告名称');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('版本');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('总播出次数');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('时长');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.InsertRows(olecount);
wordapplication.Selection.Collapse(OleDirection);
wordapplication.Selection.TypeText('化妆品');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('洁肤/护肤');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('玉兰油');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('29秒');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('1');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('00:00:13');
wordapplication.Selection.MoveRight(oleunit,olecount2,emptyparam);
wordapplication.Selection.TypeText('广告个数 24 总播出次数 36 总播出时长 00:15:15');
wordapplication.Selection.TypeParagraph;
wordapplication.ActiveDocument.Tables.Add(WordDocument.Range,1,7,emptyparam,fitweidth); //当这句话执行时前面的建的两行六列的表格被它覆盖了,不知是什么原因????
{wordDocument.Tables.Add(WordDocument.Range,1,7,emptyparam,fitWeidth);
wordapplication.Selection.TypeText('工商类别qq');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('子类别qq');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);}
//======================
Wordapplication.Disconnect; //这句不可少,不然会出现RPC服务器找不到的错误;
screen.Cursor:=crdefault;
except
on E:Exception do
begin
showmessage(E.Message+'请查看TemplateIni文件夹下的INI文件配置是否有误!');
wordapplication.Disconnect;
screen.Cursor:=crdefault;
end;
end;
end;
先用这个语句建一个新表格,而后再往插一行,变成二行六列,,
最后再用wordDocument.Tables.Add(WordDocument.Range,1,7,emptyparam,fitWeidth);
建一行七列的,不知怎得把前面建的二行六列的表格给覆盖了,只有后面一行七列的啦
在word中录制的宏:
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
6, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
Selection.TypeText Text:="工商类别"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="子类别"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="广告名称"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="版本"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="总播出次数"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="时长"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.InsertRows 1
Selection.Collapse Direction:=wdCollapseStart
Selection.TypeText Text:="化妆品"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="护肤"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="淋浴"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="9秒"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="1"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="00:00:29"
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="广告个数 24 总播出次数 36 总播出时长 00:15:15"
Selection.TypeParagraph
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
6, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
Selection.TypeText Text:="工商类别"
CommandBars("Stop Recording".Visible = False
==================================================================
转成delphi的代码:
procedure TForm1.Button1Click(Sender: TObject);
var
typename:string;
sub_ad_counts,sub_play_counts,sub_play_sum,ad_counts,play_counts,play_sum:integer;
docs,template,newtemplate,itemindex,savepath,WwdPageBreak1levariant;
wordtable,fitWeidthlevariant;
oleUnit,oleCount,oleCount2,oleExtend,OleDirectionlevariant;
i,colcount,RowCount,col,row:integer;
begin
try
screen.Cursor:=crhourglass;
template:=emptyparam;
newtemplate:=true;
itemindex:=1;
try
wordapplication.Connect;
except
messagedlg('word未安装',mterror,[mbOk],0);
abort;
end;
wordapplication.Visible:=true;
wordapplication.Caption:='媒体广告分类统计清单';
template:=emptyparam;
newtemplate:=false;
docs:=wordapplication.Documents;
docs.add(newtemplate:=true);
worddocument.ConnectTo(wordapplication.Documents.Item(itemindex));
wordapplication.Options.CheckSpellingAsYouType:=false;
wordapplication.Options.CheckGrammarAsYouType:=false;
Wordapplication.Selection.Font.Size:=12;
Wordapplication.Selection.Font.Name := 'gb-2312';
//======================开始导入DBGRIDEH的内容
oleunit:=wdCharacter;
olecount:=1;
oleCount2:=2;
OleDirection:=wdCollapseStart;
fitWeidth:=wdAutoFitContent; //wordtable.cell(1,col).range.text
wordDocument.Tables.Add(WordDocument.Range,1,6,emptyparam,fitWeidth);
wordapplication.Selection.TypeText('工商类别');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('子类别');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('广告名称');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('版本');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('总播出次数');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('时长');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.InsertRows(olecount);
wordapplication.Selection.Collapse(OleDirection);
wordapplication.Selection.TypeText('化妆品');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('洁肤/护肤');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('玉兰油');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('29秒');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('1');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('00:00:13');
wordapplication.Selection.MoveRight(oleunit,olecount2,emptyparam);
wordapplication.Selection.TypeText('广告个数 24 总播出次数 36 总播出时长 00:15:15');
wordapplication.Selection.TypeParagraph;
wordapplication.ActiveDocument.Tables.Add(WordDocument.Range,1,7,emptyparam,fitweidth); //当这句话执行时前面的建的两行六列的表格被它覆盖了,不知是什么原因????
{wordDocument.Tables.Add(WordDocument.Range,1,7,emptyparam,fitWeidth);
wordapplication.Selection.TypeText('工商类别qq');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);
wordapplication.Selection.TypeText('子类别qq');
wordapplication.Selection.MoveRight(oleunit,olecount,emptyparam);}
//======================
Wordapplication.Disconnect; //这句不可少,不然会出现RPC服务器找不到的错误;
screen.Cursor:=crdefault;
except
on E:Exception do
begin
showmessage(E.Message+'请查看TemplateIni文件夹下的INI文件配置是否有误!');
wordapplication.Disconnect;
screen.Cursor:=crdefault;
end;
end;
end;