首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

excel2007插件中安插ocx空间

2013-08-13 
excel2007插件中插入ocx空间本帖最后由 qq99570949 于 2013-08-07 09:57:38 编辑小弟按照网上的教程使用C+

excel2007插件中插入ocx空间
本帖最后由 qq99570949 于 2013-08-07 09:57:38 编辑 小弟按照网上的教程使用C++做了一个excel2007的插件,现在想在此基础上导入一个ocx控件,请问怎么导入啊,参照了一些word导入ocx控件的代码。如下

    CComQIPtr <Word::Shape> my_seal;
    CComQIPtr <Word::InlineShapes> spInS;  
    CComQIPtr <Word::InlineShape> mpic;
    CComQIPtr <Word::Shapes> spShapes;
    CComPtr<Word::OLEFormat> spOLEFormat;
    IDispatch *pObject;
    HRESULT hr;
    CComVariant vtClassType;  
    CComBSTR bsClassType("WTSEAL.WTSealCtrl.1");  
    vtClassType=bsClassType;  
    
//spInS=m_sel->GetInlineShapes(); 
m_sel->get_InlineShapes(&spInS); 
MessageBoxA(NULL,"准备加载控件了....","Nisec电子签章",MB_OK);
    mpic=spInS->AddOLEControl(&vtClassType,&varRange);

//spInS->AddOLEControl(&vtClassType,&varRange,&mpic);
//    mpic->PictureFormat->put_TransparencyColor(RGB(255,255,255));
//mpic->PictureFormat->put_TransparentBackground(msoTrue);
my_seal=mpic->ConvertToShape(); 
  
my_seal->get_OLEFormat(&spOLEFormat);
BSTR bstr_name;
my_seal->get_Name(&bstr_name);//图片是picture,控件是control
CString str_name = (CString)bstr_name;
if(_tcsstr(str_name,_T("Control")))
{
//BSTR bstr;
//spOLEFormat->get_ProgID(&bstr);//控?件t可é以?得?到?,?但?是?图?片?报馈?错洙?
hr = spOLEFormat->get_Object(&pObject);
if(FAILED(hr))
{
m_usbKey.PrintLog("获取添加印章控件对象败\n");
MessageBoxA(NULL,"获取控件对象失败!","Nisec电子签章",MB_ICONERROR);
usbKeyDisconnect(port-1);
//pObject->Release();
spOLEFormat.Release();
my_seal.Release();
mpic.Release();spRange.Release();
spInS.Release();spDoc.Release();
m_sel.Release();spDocs.Release(); 
spApp.Release();
spBtn1.Release();
CoUninitialize();
return;

}
        }
   主要是不太了解这些    CComQIPtr <Word::InlineShapes> spInS;  
    CComQIPtr <Word::InlineShape> mpic;
    CComQIPtr <Word::Shapes> spShapes;
    CComPtr<Word::OLEFormat> spOLEFormat; 如果对应excel2007应该使用什么呢?主要导入什么呢?请高手指点。

excel2007插件插入ocx控件 ocx Excel
[解决办法]
对应excel2007也是使用这些,贴一段自己写的代码给你参考一下:
COleVariant vShape(_T("Forms.Image.1")),vRange;
COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR), vFalse((short)false);
vRange.vt = VT_DISPATCH;
vRange.pdispVal = m_Selection.get_Range();
//m_Range.Expand(&vRange);
m_nlineShapes.AttachDispatch(m_Selection.get_InlineShapes());
//m_nlineShape = m_nlineShapes.AddOLEControl(vShape, vRange);
m_nlineShape = m_nlineShapes.AddOLEObject(vShape, vOpt, vFalse, vFalse,vOpt, vOpt, vOpt, vRange);
//IDispatchPtr spDispOLEFormat;
Word::OLEFormatPtr spDispOLEFormat;
spDispOLEFormat = m_nlineShape.get_OLEFormat();

热点排行