none
inspector document fail by com interface in excel RRS feed

  • Question

  •  I want to inspector document by com interface in excel

    but I call  hr=spInspector->Inspect(&status, &result) interface. 

    the status value  is  msoDocInspectorStatusError at some times.

    thanks any help.

    the code is

    Excel::_excelApplication* GetExcelAppInstance()

    {

     HRESULT         hr= S_OK;


     hr = CoCreateInstance(Excel::CLSID_excelApplication, NULL, CLSCTX_LOCAL_SERVER, Excel::IID__excelApplication, (void**)&m_pExcelApp);


     return m_pExcelApp;

    };


    bool GetWorkBook(void)

    {

     if (m_pExcelApp == NULL)

     {

      m_pExcelApp = GetExcelAppInstance();

      if (m_pExcelApp == NULL)

      {

       return FALSE;

      }

     }

     if(m_pWorkbook != NULL) return true;

     CComVariant varWorkBooks;

     HRESULT hr = AutoWrap(DISPATCH_PROPERTYGET,&varWorkBooks,m_pExcelApp,L"Workbooks",0);

     if(FAILED(hr)||varWorkBooks.pdispVal==NULL) 

     {

      m_pExcelApp=NULL;

      return false;

     }

     CComPtr<IDispatch> spDispatch = varWorkBooks.pdispVal;

     CComVariant FileName;

     FileName.vt = VT_BSTR;

     FileName.bstrVal = _bstr_t(m_strTempFileName.c_str());

     CComVariant varZero((int)0);

     CComVariant varTrue((short)TRUE);

     CComVariant varFalse((short)FALSE);

     CComVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

     CComVariant varResult;


     hr = AutoWrap(DISPATCH_METHOD,&varResult,spDispatch,L"Open",15,

      covOptional,    // CorruptLoad

      covOptional,    // Local

      covOptional,    // AddToMru

      covOptional,    // Converter

      varFalse,    // Notify

      covOptional,    // Editable

      covOptional,    // Delimiter

      covOptional,    // Origin

      varTrue,    // IgnoreReadOnlyRecommended

      covOptional,    // WriteResPassword

      covOptional,    // Password

      covOptional,    // Format

      varFalse,    // ReadOnly

      varZero,    // UpdateLinks

      FileName

      );

     m_pWorkbook = varResult.pdispVal;

     if(FAILED(hr)||m_pWorkbook==NULL)

     {

      m_pExcelApp=NULL;

      return false;

     }

     CComVariant varVisible(VARIANT_FALSE);

     CComVariant varNumb((int)0);

     varResult.Clear();
     hr = AutoWrap(DISPATCH_PROPERTYGET,&varResult,m_pWorkbook,L"MultiUserEditing",0);

     if(SUCCEEDED(hr))

      m_bShared=varResult.boolVal;

     hr = AutoWrap(DISPATCH_PROPERTYPUT,&varResult,m_pWorkbook,L"CheckCompatibility",1,varFalse);

     hr = AutoWrap(DISPATCH_PROPERTYPUT,&varResult,m_pWorkbook,L"DoNotPromptForConvert",1,varFalse);

     hr = AutoWrap(DISPATCH_PROPERTYPUT,&varResult,m_pExcelApp,L"Visible",1,varVisible);

     hr = AutoWrap(DISPATCH_PROPERTYPUT,&varResult,m_pExcelApp,L"ShowWindowsInTaskbar",1,varVisible);

     varResult.Clear();
     hr = AutoWrap(DISPATCH_PROPERTYGET,&varResult,m_pWorkbook,L"ReadOnly",0);

     if(varResult.vt & VT_BOOL && varResult.boolVal)

     {
      m_bReadonly = TRUE;  

     }

     return true;

    }

    void test()

    {

    CComPtr<Excel::_Workbook> pWorkbook=NULL;

    hr=m_pWorkbook->QueryInterface(__uuidof(_Workbook),(void**)&pWorkbook);

    CComPtr<Office::DocumentInspectors> spInspectors=NULL;

    hr = pWorkbook->get_DocumentInspectors(&spInspectors);


    int nInspCount = 0;

    hr = spInspectors->get_Count(&nInspCount);

    for (int i = 0; i < nInspCount; i++)
    {
     CComPtr<Office::DocumentInspector> spInspector=NULL;

     hr = spInspectors->get_Item(i, &spInspector);

     CComBSTR              name;

     CComBSTR              result;

     MsoDocInspectorStatus status;

     hr = spInspector->get_Name(&name);


     hr=spInspector->Inspect(&status, &result);

     
    }

    }

    Monday, July 18, 2016 8:30 AM

All replies

  • Hi chaddcao,

    in which project type are you developing?

    Addin or workbook?

    did you try to check the error?

    Regards

    Deepak

    ,

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, July 19, 2016 9:31 AM
    Moderator
  • my project is outlook addin.

    I want to inspect the  outlook attachment.

    so I try to open the attachment by CoCreateInstance function

    when I get the excel object. I can get the inspector object.

    when the excel process had existed in my computer.I run the code. the bug is easy to reproduce.

     hr=spInspector->Inspect(&status, &result) interface. 

    the status value  is  msoDocInspectorStatusError at some times.

    Wednesday, July 20, 2016 3:03 AM
  • Hi chaddcao,

    from your code it looks like you are developing using c++.

    generally we provide suggestions for vb and c#.

    so I am going to involve some senior engineers to look in to this issue.

    now they will contact you and provide suggestion to you regarding this issue.

    please have patience till they contact you because it may take some time.

    thanks for your understanding.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, July 20, 2016 6:59 AM
    Moderator