_variant_t varLinkToFile=VARIANT_FALSE;
_variant_t varSaveWithDoc=VARIANT_TRUE;
try
{Word::InlineShapePtr lpILShate=pSel->InlineShapes->AddPicture(_bstr_t(sValue),&varLinkToFile,&varSaveWithDoc);
if(pObj->m_nCtrlType-100!=7)
{
Word::ShapePtr lpShape=NULL;
if(lpILShate!=NULL)
lpShape=lpILShate->ConvertToShape();
if(lpShape!=NULL)
{
lpShape->WrapFormat->AllowOverlap=1;
lpShape->WrapFormat->put_Type(Word::WdWrapType(pObj->m_nCtrlType-100));
}
}
}
catch(com_error e){}
不知什么原因,ConvertToShape老报异常,返回E_FAIL
解决办法:使用Shapes的AddPicture,但要通过find方法定位插入点
_variant_t FindText=(LPCTSTR)sField;
_variant_t ReplaceWith=vtMissing ;
_variant_t Forward=VARIANT_TRUE;
_variant_t Wrap=(_variant_t)(Word::wdFindContinue);
_variant_t Format=VARIANT_FALSE;
_variant_t MatchCase=VARIANT_FALSE;
_variant_t MatchWholeWord=VARIANT_FALSE;
_variant_t MatchWildcards=VARIANT_FALSE;
_variant_t MatchSoundsLike=VARIANT_FALSE;
_variant_t MatchAllWordForms=VARIANT_FALSE;
CString sNull(_T(""));
ReplaceWith = (LPCTSTR)sNull;
CString sValue = _T("the pos you wanted");
pSel->Find->Execute(
&FindText, &MatchCase, &MatchWholeWord, &MatchWildcards, &MatchSoundsLike,
&MatchAllWordForms, &Forward, &Wrap, &Format, &ReplaceWith,&vtMissing);
Word::RangePtr lpRange=pSel->Range;
_variant_t vtAnchor(lpRange,true);
Word::ShapesPtr shapes = m_lpWord->GetShapes();
Word::ShapePtr shape = shapes->AddPicture(_bstr_t(sValue), &varLinkToFile, &varSaveWithDoc, &vtMissing, &vtMissing, &vtMissing, &vtMissing,&vtAnchor);
还望与大家多多讨论