MFC操作word获取当前页的页码
COleVariant covZero((short)0),covTrue((short)TRUE);
wd.m_wdView.SetSeekView(10); // wdSeekCurrentPageFooter=10
wd.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(" ")));
}
else if (pFrame->m_dlgPrintSet.m_printInfo.m_PagenumType == 1)
{
wd.m_wdSel.TypeText(LPCTSTR(_T("..")));
}
else if (pFrame->m_dlgPrintSet.m_printInfo.m_PagenumType == 2)
{
wd.m_wdSel.TypeText(LPCTSTR(_T("--")));
}
else if (pFrame->m_dlgPrintSet.m_printInfo.m_PagenumType == 3)
{
wd.m_wdSel.TypeText(LPCTSTR(_T("第页")));
}
else if (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 );
}
else if (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();
// 增加页码域,当前页码
int i = 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,回到主控文档
wd.m_wdView.SetSeekView(10); // wdSeekCurrentPageFooter=10
wd.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(" ")));
}
else if (pFrame->m_dlgPrintSet.m_printInfo.m_PagenumType == 1)
{
wd.m_wdSel.TypeText(LPCTSTR(_T("..")));
}
else if (pFrame->m_dlgPrintSet.m_printInfo.m_PagenumType == 2)
{
wd.m_wdSel.TypeText(LPCTSTR(_T("--")));
}
else if (pFrame->m_dlgPrintSet.m_printInfo.m_PagenumType == 3)
{
wd.m_wdSel.TypeText(LPCTSTR(_T("第页")));
}
else if (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 );
}
else if (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();
// 增加页码域,当前页码
int i = 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,回到主控文档
...全文
相关推荐
mfc对office中的word进行操作
mfc对office中的word进行操作
VC++2010基于MFC实现Word2010文档自动化操作
以下示例演示如何从指定路径加载企业级报告模板:上述代码中,我们显式传递了四个参数:vtTemplate:指向.dotx模板文件;vtFalse:表示非模板编辑模式;(long)0:文档类型为常规文档;vtTrue:使新文档可见。这种方式特别适用于需要保持统一排版风格的企业级文档生成场景。graph TD该流程图清晰展示了从调用Add方法到最终获得可操作文档对象的完整路径。每一步都可通过异常捕获确保健壮性。每个Range。
MFC有关word所有操作
MFC有关word的所有详细操作,有源代码,详细注释
MFC操作word
这是mfc操作word的代码,word开发大家常常用到,我在此为大家准备一个我辛苦做的代码,希望能帮到大家
VC++2010操作Word2010
结合网上的资源,在vc2010下mfc操作word2010/2013的例程。包含了简单的文本内容,表格,页面设置,页眉页脚页码,图片插入,公式插入


