用vc怎么设置word的页眉页脚。
我查了查,在本论坛也有人这样问,但是没有得到解决,我希望各位高手帮忙解决一下,我没有连网,过几天来结贴。
我希望得到一个连接地址,或者直接有代码(这样是最好的事了),我相信有很多人和我一样遇到这个问题。谢谢了!!!!

解决方案 »

  1.   

    录制宏,然后看生成的VBA代码,转换成C++的不就行了么
      

  2.   

    _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); //回到正文视图
      

  3.   

    http://download.csdn.net/source/2620568
    我做一个demo,今上传,vc6.0测试通过。下载即可。vc 操作word,包括新建文档,保存文档,写入文字,新建表格,更改表格格式,合并单元格,填写页眉页脚等等。
      

  4.   

    其实学会录制宏,加上word typelib的宏定义,手动能够操作的我word技术,就能够转化成vc代码。