VC设置页眉页脚









_Application app;
app.CreateDispatch(_T("Word.Application"));
app.SetVisible(TRUE);


//通过WORD宏可以知道,由于要使用Documents,于是我们定义一个并从app中取得


Documents docs=app.GetDocuments();
//准备调用Documents::Add函数了,需要定义4个参数。
//从WORD宏可以看出来3个参数的类型为:
//Template字符,NewTemplate布尔,DocumentType数值
//但Add函数还需要一个参数是Visible,傻子也能看出来这个值表示是否显示出新文档
//并且可以给默认值(VT_EMPTY)
CComVariant Template(_T("")); //为了简单,没有使用WORD的文档模板
CComVariant NewTemplate(false),DocumentType(0),Visible;
docs.Add(&Template,&NewTemplate,&DocumentType,&Visible);
//通过WORD宏可以知道,由于要使用Selection,于是我们定义一个并从app中取得
//Selection表示输入点,即光标闪烁的那个地方


Selection sel=app.GetSelection();
//调用函数Selection::TypeText 向WORD发送字符
_Font font(sel.GetFont());


/*页眉页脚*/
Window   mWindowActive;   //定义活动窗口对象
View   mViewActive;   //定义活动视图对象
Pane   mPane;   //定义当前窗格对象
Paragraph para;
Fields fields;
mWindowActive=app.GetActiveWindow(); //获得当前窗口 
mPane=mWindowActive.GetActivePane();   //获得当前窗格
mViewActive=mPane.GetView();   //获得当前视图
mViewActive.SetSeekView(9);   //设置页眉视图
font.SetSize(15);
font.SetColor(RGB(0,0,0));
sel.TypeText("设置页眉视图,,,,,,,,,,,,,"); 
para.SetAlignment(1);   //居中
sel.TypeParagraph();
font.SetSize(9);
sel.TypeText("设置页眉视图。。。。。。。。。。。");
para.SetAlignment(1);   //居中
font.SetSize(7);
mViewActive.SetSeekView(10);   //设置页脚视图
sel.TypeText("- ");
fields.Add(sel.GetRange(),COleVariant(short(33)),COleVariant("PAGE  "),COleVariant(short(1))); //增加页码域
sel.TypeText(" -");
font.SetSize(6);
font.SetColor(RGB(80,80,80));
para.SetAlignment(1);   //居中
sel.TypeText("设置页脚视图"); 
para.SetAlignment(1);   //居中


mViewActive.SetSeekView(0); //回到正文视图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值