威尼斯www.9778.com-威尼斯正版官方网站

MFC操作word获取当前页的页码

日期:2019-12-25编辑作者:编程人生

COleVariantcovZero((short)0),covTrue((short)TRUE);wd.m_wdView.SetSeekView(10);//wdSeekCurrentPageFooter=10wd.m_wdParagraphFormat=wd.m_wdSel.GetParagraphFormat();wd.m_wdParagraphFormat.SetAlignment(pFrame-m_dlgPrintSet.m_printInfo.m_PagenumPosition);//添加页码if(pFrame-m_dlgPrintSet.m_printInfo.m_PagenumType==0){wd.m_wdSel.TypeText(LPCTSTR(_T("")));}elseif(pFrame-m_dlgPrintSet.m_printInfo.m_PagenumType==1){wd.m_wdSel.TypeText(LPCTSTR(_T("..")));}elseif(pFrame-m_dlgPrintSet.m_printInfo.m_PagenumType==2){wd.m_wdSel.TypeText(LPCTSTR(_T("--")));}elseif(pFrame-m_dlgPrintSet.m_printInfo.m_PagenumType==3){wd.m_wdSel.TypeText(LPCTSTR(_T("第页")));}elseif(pFrame-m_dlgPrintSet.m_printInfo.m_PagenumType==4){wd.m_wdSel.TypeText(LPCTSTR(_T("第页共页")));}if(pFrame-m_dlgPrintSet.m_printInfo.m_PagenumType!=4){wd.m_wdSel.MoveLeft(COleVariant((short)1),COleVariant((short)1),covZero);}elseif(pFrame-m_dlgPrintSet.m_printInfo.m_PagenumType==4){wd.m_wdSel.MoveLeft(COleVariant((short)1),COleVariant((short)4),covZero);}wd.m_wdFields=wd.m_wdSel.GetFields();//增加页码域,当前页码inti=wd.m_wdFields.GetCount();wd.m_wdFields.Add(wd.m_wdSel.GetRange(),COleVariant((short)33),COleVariant(_T("PAGE")),covTrue);if(pFrame-m_dlgPrintSet.m_printInfo.m_PagenumType==4){wd.m_wdSel.MoveRight(COleVariant((short)1),COleVariant((short)3),covZero);//增加页码域,总页数wd.m_wdFields.Add(wd.m_wdSel.GetRange(),COleVariant((short)26),COleVariant(_T("NUMPAGES")),covTrue);//增加页码域,总页数}wd.m_wdView.SetSeekView(0);//关闭页眉页脚,wdSeekMainDocument=0,回到主控文档

现在基本功能都实现了,就差把word表格居中了,有会的朋友请不吝赐教,谢谢,注意是把表格居中,不是把文字居中。部分代码贴在下面,若还需要别的信息,请联系!手机,微信13522968283,可有偿!voidCWordtestDlg::OnNewDoc(){COleVariantvTrue((short)TRUE);COleVariantvFalse((short)FALSE);COleVariantvOpt((long)DISP_E_PARAMNOTFOUND,VT_ERROR);////////////////////////////////////////////////////////////////////////////开始一个新的MicrosoftWord实例_ApplicationoWordApp;if(!oWordApp.CreateDispatch("Word.Application",NULL)){AfxMessageBox("CreateDispatchfailed.",MB_OK|MB_SETFOREGROUND);return;}oWordApp.SetVisible(TRUE);////////////////////////////////////////////////////////////////////////////创建一个新的word文档DocumentsoDocs=oWordApp.GetDocuments();_DocumentoDoc=oDocs.Add(vOpt,vOpt,vOpt,vOpt);//把文本添加到word文档SelectionoSel=oWordApp.GetSelection();_Fontf=oSel.GetFont();Paragraphformat=oSel.GetParagraphFormat();//设置格式format.SetAlignment(1);//居中format.SetLineSpacingRule(4);format.SetLineSpacing(13);f.SetSize(12);f.SetBold(1);oSel.TypeParagraph();oSel.TypeText("西欧8国15天行程");oSel.TypeParagraph();f.SetSize(9);f.SetBold(0);oSel.TypeParagraph();oSel.WholeStory();//设置字体——老的/*_Fontfont(oSel.GetFont());//font.SetColor(RGB(255,0,0));font.SetColor(RGB(0,0,0));font.SetSize(14.f);font.SetBold(1);oSel.SetFont(font);*////表格1oSel.EndKey(COleVariant((short)wdStory),COleVariant((short)wdMove));RangeRng=oSel.GetRange();TablesTbls=oDoc.GetTables();TableTb0=Tbls.Add(Rng,16,5,vOpt,vOpt);Bordersbords0=Tb0.GetBorders();bords0.SetOutsideLineStyle(wdLineStyleSingle);//设置边框属性bords0.SetOutsideColorIndex(wdBlack);//边框颜色bords0.SetOutsideLineWidth(wdLineWidth150pt);//边框宽度bords0.SetInsideLineStyle(wdLineStyleSingle);//内框属性bords0.SetInsideColorIndex(wdBlack);//内框颜色f.SetBold(1);Columnsc=oSel.GetColumns();c.SetWidth(40);oSel.TypeText(_T("第X天"));oSel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));f.SetBold(1);c.SetWidth(50);oSel.TypeText(_T("日期"));oSel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));f.SetBold(1);c.SetWidth(260);oSel.TypeText(_T("行程安排"));oSel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));f.SetBold(1);c.SetWidth(40);oSel.TypeText(_T("住宿"));oSel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));f.SetBold(1);//c.SetWidth(30);c.SetWidth(100);oSel.TypeText(_T("用餐"));oSel.MoveDown(COleVariant((short)4),COleVariant((short)1),COleVariant((short)0));

本文由威尼斯www.9778.com发布于编程人生,转载请注明出处:MFC操作word获取当前页的页码

关键词:

怎么使用com的回调

有2个类,CCDMAX和CCDMAXEvents。 classCCDMAX:publicCOleDispatchDriver{public:CCDMAX(){}//调用COleDispatchDriver默认构造函数CCDMAX(LPDISPAT...

详细>>

vc2005编译ffmpeg以及ffplay

typedefstructAVOption{constchar*name;constchar*help;intoffset;enumAVOptionTypetype;union{int64_ti64;doubledbl;constchar*str;/*TODOthoseareunusednow*/AV...

详细>>

求助 cannot convert parameter 4 from 'char [260]' to &#x2

CDatabasedb;charDB[MAX_PATH];sprintf(DB,"ODBC;DSN=User_odbc;UID="",PWD=""");//LPCTSTRch=(LPCTSTR)DB[MAX_PATH];//db.Open(NULL,FALSE,FALSE,ch);db.Open(NU...

详细>>

ActiveX控件的基本操作方法以及如何在VS2010下使用控件

vc做了个工程,加了一个ActiveX的控件,添加成功,控件也出来了,然后我想修改一些属性需要关联控件,然后我在d...

详细>>