We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

C++ Read value from cell

I follow the tutorial present here (http://www.aspose.com/docs/pages/viewpage.action?pageId=15565334) all it is fine.

Now when I retrieve a Cells I want to read the value inside the cells. In this case in C# I have used the Cells Type and then read the appropriate field. In which way I can do the same in C++?

The second question is in whch way I can read the license from C++ code?


Thanks in advance

Solved the reading of the cell content!


Added this method to your sample:

HRESULT ResolveVariant(VARIANT* pVarIn, VARIANT* pVarOut)
{
VARIANT* tmpVarIn = pVarIn;
ULONG ByRef = 0;

while(tmpVarIn->vt == (VT_BYREF | VT_VARIANT) )
tmpVarIn = tmpVarIn->pvarVal;

if(tmpVarIn->vt & VT_BYREF)
ByRef = VT_BYREF;


switch(tmpVarIn->vt)
{
case (VT_I2): case (VT_BYREF|VT_I2):
if(ByRef)
{
if(!tmpVarIn->piVal) return E_POINTER;
pVarOut->iVal = *(tmpVarIn->piVal);
}
break;

case (VT_I4): case (VT_BYREF|VT_I4):
if(ByRef)
{
if(!tmpVarIn->plVal) return E_POINTER;
pVarOut->lVal = (tmpVarIn->plVal);
}
break;

case (VT_BSTR): case (VT_BYREF|VT_BSTR):
if(ByRef)
{
if(!tmpVarIn->pbstrVal) return E_POINTER;
if(!(tmpVarIn->pbstrVal) ) return E_POINTER;
pVarOut->bstrVal = (tmpVarIn->pbstrVal);
}
break;

case (VT_DISPATCH): case (VT_BYREF|VT_DISPATCH):
if(ByRef)
{
if(!tmpVarIn->ppdispVal) return E_POINTER;
if(!(tmpVarIn->ppdispVal) ) return E_POINTER;
pVarOut->pdispVal = *(tmpVarIn->ppdispVal);
}
break;


default:
return DISP_E_TYPEMISMATCH;
}

if(ByRef)
pVarOut->vt = (tmpVarIn->vt - ByRef);
else
*pVarOut = *tmpVarIn;


if (pVarOut->vt == VT_DISPATCH)
{
VARIANT varResolved;
DISPPARAMS dispParamsNoArgs = {NULL, NULL, 0, 0};

VariantInit(&varResolved);

if (SUCCEEDED (
pVarOut->pdispVal->Invoke(DISPID_VALUE, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYGET | DISPATCH_METHOD,
&dispParamsNoArgs, &varResolved, NULL, NULL) ) )
{
ResolveVariant(&varResolved, pVarOut);
}
else
return E_FAIL;

VariantClear(&varResolved);
return S_OK;
}
else
{
HRESULT hr;
VARIANT retVar;
VariantInit(&retVar);
hr = VariantCopy(&retVar, pVarOut);
*pVarOut = retVar;
return hr;
}
}

Then as soon as I have the cell Variant object I call in this way the method:

if (cell.vt & VT_DISPATCH)
{
VARIANT *out = new VARIANT;
ResolveVariant(&cell, out);
}

into the out object is possible to read the bstr property that contains the string.

I suggest to add this part to your example to make it complete.

On the other hand I always need to read the license by C++, the question is still pending.

Hi Roberto,

Thanks for your posting and using Aspose.Cells.

Are you using C++/CLI? You can try the following code to set the license with file path.

You first need to create Aspose.Cells.License object and then set the license using its SetLicense() method.

C++/CLI



Aspose::Cells::License^ lExcelLicense = gcnew Aspose::Cells::License();


lExcelLicense->SetLicense(“Aspose.Total.lic”);