CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

关于用vc++生成word自动化文档的一些问题

楼主songyangliang(song)2004-05-03 20:24:48 在 VC/MFC / 基础类 提问

我需要用vc++将程序运行的结果保存到word的表格中,另外,我还需加入页眉(包括汉字和一个小图标)和页脚(包括文档的总页数和当前页码)请问该如何实现这个功能?如有知道者请速告之,邮箱:tinai@163.com   谢谢! 问题点数:0、回复次数:1Top

1 楼Onega(www.fruitfruit.com)回复于 2004-05-03 21:58:29 得分 0

http://support.microsoft.com/?scid=kb;EN-US;Q293861  
  HOWTO:   Use   Word   Automation   to   Count   the   Number   of   Pages   in   Each   Section   of   a   Document  
  Follow   steps   1   through   12   in   the   following   article   in   the   Microsoft   Knowledge   Base   to   create   a   sample   project   that   uses   the   IDispatch   interfaces   and   member   functions   that   are   defined   in   the   MSWord9.olb   type   library:  
  178749   HOWTO:   Create   an   Automation   Project   Using   MFC   and   a   Type   Library    
   
  At   the   top   of   AutoProjectDlg.cpp,   add   the   following   line:#include   "MSWord9.h"  
  Add   the   following   code   to   CAutoProjectDlg::OnRun()   in   AutoProjectDlg.cpp:COleVariant   vOpt((long)DISP_E_PARAMNOTFOUND,   VT_ERROR);  
     
  //Start   Word.  
  _Application   oWord;  
  oWord.CreateDispatch("Word.Application");  
  oWord.SetScreenUpdating(FALSE);  
   
  //Open   the   document.  
  Documents   oDocs   =   oWord.GetDocuments();  
  _Document   oDoc   =   oDocs.Open(COleVariant("c:\\mydoc.doc"),  
            vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,   vOpt,   vOpt);  
   
  //Repaginate   the   document.  
  oDoc.Repaginate();  
   
  //Iterate   the   collection   of   sections   in   the   document   to   retrieve   the   page    
  //count   for   each   section.  
  Sections   oSecs   =   oDoc.GetSections();  
  long   NumSections   =   oSecs.GetCount();  
  long   i;  
  long   StartPage=1;   //section   start   page.  
  long   EndPage=0;     //section   end   page.  
  long   NumPages=0;     //number   of   pages   in   the   section.  
  for(i=1;i<=NumSections;i++)  
  {  
  Section   oSec   =   oSecs.Item(i);  
  Range   oSecRange   =   oSec.GetRange();  
  VARIANT   vInfo   =   oSecRange.GetInformation(3L);//wdActiveEndPageNumber=3  
  //If   oSec.Index   =   NumSections   Then   nEndPg   =   nEndPg   +   1  
  if(oSec.GetIndex()==   NumSections)   {EndPage++;}  
  EndPage   =   vInfo.lVal-1;  
  if(i==NumSections)   {EndPage++;}     //Account   for   the   last   section.  
  NumPages   =   EndPage   -   StartPage   +1;  
  char   buf[5];  
  sprintf(buf,"%d",   NumPages);  
  TRACE1("Section   %d\n",   oSec.GetIndex());  
  TRACE3("       StartPage:   %d     EndPage:   %d       TotalPages:   %d\n",  
        StartPage,   EndPage,   NumPages);  
  StartPage   =   EndPage   +   1;  
  }  
   
  //Close   the   document   without   saving   changes   and   quit   Word.  
  oDoc.Close(COleVariant((short)false),   vOpt,   vOpt);  
  oWord.Quit(COleVariant((short)false),   vOpt,   vOpt);  
   
  Compile   and   run   the   project.  
  When   the   dialog   box   appears,   click   Run.   The   count   results   are   displayed   in   the   Debug   window.  
  Top

相关问题

  • 自动化的java代码生成器
  • 请问如何用VC++生成word文档,不胜感激
  • 求教!如何用VC在生成带表格的Word文档?
  • 生成word文档
  • 高分求教,一个关于vc生成word文档的问题。
  • linux下如何用emacs在源程序中生成自动化时间标志
  • 如何生成word文档?
  • 请教:生成xml文档
  • 生成文档的问题
  • 在线生成Word文档

关键词

  • vc++
  • word
  • document
  • vopt
  • oword
  • odoc
  • section
  • long
  • pages

得分解答快速导航

  • 帖主:songyangliang

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo