使用RangePtr读取excel时抛出异常
ret = pRange->GetValue();
//Create the SAFEARRAY from the VARIANT ret.
//if(!(ret.vt & VT_ARRAY))
//return FALSE;
//COleSafeArray sa(ret);
//Determine the array's dimensions.
long lNumRows;
long lNumCols;
//sa.GetUBound(1, &lNumRows);
//sa.GetUBound(2, &lNumCols);
//lNumRows = pRange->GetRow();
lNumCols = pRange->GetCount()/10;
//lNumRows = pRange->GetColumn();
lNumRows = 10;
//Display the elements in the SAFEARRAY.
long index[2];
VARIANT val;
int r, c;
TRACE("Contents of SafeArray\n");
TRACE("=====================\n\t");
for(c=0;c<lNumCols;c++)
{
TRACE("\t\tCol %d", c);
}
TRACE("\n");
for(r=0;r<lNumRows;r++)
{
TRACE("Row %d", r);
for(c=0;c<lNumCols;c++)
{
//index[0]=r;
//index[1]=c;
//sa.GetElement(index, &val);
int temp = r*150+c;
val = pRange->GetItem(_variant_t(long(0)),_variant_t(long(temp)));
switch(val.vt)
{
case VT_R8:
{
TRACE("\t\t%1.2f", val.dblVal);
break;
}
case VT_BSTR:
{
TRACE("\t\t%s",(CString)val.bstrVal);
break;
}
case VT_EMPTY:
{
TRACE("\t\t<empty>");
break;
}
}
}
TRACE("\n");
}