VC ++ MSWORD CPages :: Item"集合中请求的成员不存在“ [英] VC++ MSWORD CPages::Item "The requested member of the collection does not exist"
本文介绍了VC ++ MSWORD CPages :: Item"集合中请求的成员不存在“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CString in_path;
GetDlgItem(IDC_EDIT1) - > GetWindowTextW(in_path);
if (in_path.IsEmpty())
{
MessageBox(_T() 请选择文件));
return ;
}
CApplication wordApp;
COleVariant vTrue(( short )TRUE),vFalse(( short )FALSE),vOpt (( long )DISP_E_PARAMNOTFOUND,VT_ERROR);
CDocuments docxs;
CDocument0 docx;
CRange aRange;
CString out_path = _T( C:\\Users \\Administrator \\ Desktop\\test\\跨度>);
docxs.ReleaseDispatch();
try
{
CoInitialize(NULL);
if (!wordApp.CreateDispatch(_T( Word.Application),NULL))
{
AfxMessageBox(_T(无法运行 )
return;
}
}
catch(...)
{
return;
}
docxs = wordApp.get_Documents();
COleVariant vFileName(in_path);
docx = docxs.Open
(vFileName,vFalse,vTrue,vFalse,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt);
CWindows win = docx.get_Windows();
CWindow0 window = wordApp.get_ActiveWindow();
CPane0 pane = window.get_ActivePane();
CPages pages = pane.get_Pages();
long index = pages.get_Count();
for(long i = 1; i< = index; i ++)
{
CPage page = pages.Item(index);(这里有一个错误)当docx的页面大于2时,集合中请求的成员执行不存在
)
.. ....
}
请帮助我,提前谢谢VS2010,OFFICE WORD 2010,C ++
解决方案
Quote:
for(long i = 1; i< = index; i ++)
{
CPage page = pages.Item(index);可能是你的意思< pre lang =c ++> for ( long i = 1 ; i< index; i ++)
{
CPage page = pages.Item(i);
,因为index
是项目的数量, 0-based (0,1,... ,index-1
)
CString in_path;
GetDlgItem(IDC_EDIT1)->GetWindowTextW(in_path);
if(in_path.IsEmpty())
{
MessageBox(_T("please choose the file"));
return ;
}
CApplication wordApp;
COleVariant vTrue((short)TRUE), vFalse((short)FALSE), vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
CDocuments docxs;
CDocument0 docx;
CRange aRange;
CString out_path=_T("C:\\Users\\Administrator\\Desktop\\test\\");
docxs.ReleaseDispatch();
try
{
CoInitialize(NULL);
if(!wordApp.CreateDispatch(_T("Word.Application"),NULL))
{
AfxMessageBox(_T(it cant run")
return ;
}
}
catch(...)
{
return ;
}
docxs=wordApp.get_Documents();
COleVariant vFileName(in_path);
docx=docxs.Open
(vFileName,vFalse,vTrue,vFalse,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt);
CWindows win=docx.get_Windows();
CWindow0 window = wordApp.get_ActiveWindow();
CPane0 pane = window.get_ActivePane();
CPages pages = pane.get_Pages();
long index=pages.get_Count();
for(long i=1;i<=index;i++)
{
CPage page=pages.Item(index);(there is a error here when pages of docx is greater than 2,"The requested member of the collection does not exist"
)
......
}
please help me ,thanks in advance VS2010, OFFICE WORD 2010, C++
解决方案
Quote:
for(long i=1;i<=index;i++)
{
CPage page=pages.Item(index);Possibly you meant
for(long i=1;i<index;i++) { CPage page=pages.Item(i);
becauseindex
is the count of items, that are 0-based (0,1,.., index-1
)
这篇关于VC ++ MSWORD CPages :: Item"集合中请求的成员不存在“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文