while j<6 do begin
doc.Tables.item(1).cell(1,j).Range.Bold:=integer(true);
WordFont1.ConnectTo(doc.Tables.item(1).cell(1,j).Range.Font);
WordFont1.ColorIndex:=10;
j:=j+1;
end;
//--------------------------向表格中添加数据----------------------------------------//
doc.Tables.Item(1).Cell(1,1).Range.Text:='线路名称';
doc.Tables.Item(1).cell(1,2).Range.text:='人数';
doc.Tables.item(1).cell(1,3).Range.text:='销售额(元)';
doc.Tables.item(1).cell(1,4).Range.text:='毛利润';
doc.Tables.Item(1).cell(1,5).Range.text:='毛利润率';
while not ADOQuery1.Eof do begin
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('Unable to Execute Macro');
DDEClient.CloseLink;{断开连接}
end;
(三) 宏命令的执行
宏(Macro)是客户程序要服务器完成的一些操作指令,对与特定的Microsoft Word
而言无非是些打开文件、插入分割符、复制粘贴字符等一些字处理方面的宏命令,这些宏命令完成的功能大多在Word的菜单下都能找到与之相匹配的菜单。如"关闭文件"菜单完成的功能就可以通过宏[FileClose]来完成。可以向窗口添加一个按钮或是菜单然后在其处理函数中添加执行宏的代码如下:
procedure TForm1.N2Click(Sender: TObject);
begin
RunMacro('[FileNew]');{让Word创建一个新文件,宏[FileNew]由函数RunMacro通知Word}
end;
1\参考以下代码:
procedure PrintReport4(DSR, AJXZ, CFSJ, JBAQ: PChar); stdcall;
var
Word, Doc, Fields:OleVariant;
begin
Word:=CreateOleObject('Word.Application');