Discussion:
Prolem of reading range in excel 2007
(too old to reply)
sunil adhyaru
2009-11-09 10:00:39 UTC
Permalink
Hi ,

I am reading range from excel in one of my function . The code I have
written is working in excel 2003 and version below it . But the same
code is not working excel 2007 . It is giving me value "0.000" in all
the cells of the range selected.

I am using excel sdk

following is the code I have written.

LPXLOPER __stdcall setOrcInstrument(int field1,LPSTR field2, LPSTR
field2, LPSTR field3, LPSTR field5, LPXLOPER fieldNameRange)
{
CArray<char* , char*> fieldNameArray;
if(fieldNameRange->xltype == xltypeMulti )
{

int nCellCountName = fieldNameRange->val.array.rows *
fieldNameRange->val.array.columns;
char* pTemp = new char[255];
sprintf(pTemp,"cell count name %d",nCellCountName);
//objLog->Log(pTemp);
AfxMessageBox(pTemp);

if(fieldNameRange->val.array.columns > 1 && fieldNameRange-
val.array.rows > 1) // check for exactly 4 columns
{

return NULL;
}

for (int i=1;i<=nCellCountName;i++)
{
if(fieldNameRange[i].xltype == xltypeStr)
{
char *cellValue = new char[255];
int len = fieldNameRange[i].val.str[0];


cellValue[0] = '|';
for(int k = 1; k<=len; k++)
{
cellValue[k] = fieldNameRange[i].val.str[k];
}
cellValue[len+1] = '\0';
//objLog->Log(cellValue);
fieldNameArray.Add(cellValue);
//AfxMessageBox(ansiValue[0]);
//free(ansiValue);

}
else if(fieldNameRange[i].xltype == xltypeNum)
{
char *pTemp = new char[255];
sprintf(pTemp,"|%f\0",fieldNameRange[i].val.num);
//objLog->Log(pTemp);
fieldNameArray.Add(pTemp);
}
else if(fieldNameRange[i].xltype == xltypeNil)
{
fieldNameArray.Add("| ");

}

}
}

}

with registration using
{" setOrcInstrument", " RICCCCP#", " setOrcInstrument", "
field1,field2, field3, field4, field5, FieldNameRange, " 1", " TI_OQL
Functions", " ", " TI_OQL.HLP!1017", " This function Inserts/Modifies
an instrument in ORC and returns its Tag."," "},
lab27
2009-11-11 08:03:47 UTC
Permalink
Post by sunil adhyaru
Hi ,
I am reading range from excel in one of my function . The code I have
written is working in excel 2003 and version below it . But the same
code is not working excel 2007 . It is giving me value "0.000" in all
the cells of the range selected.
                        if(fieldNameRange->xltype == xltypeMulti )
                                {
                                        int nCellCountName  = fieldNameRange->val.array.rows *
<snip>
Post by sunil adhyaru
                                        for (int i=1;i<=nCellCountName;i++)
                                        {
                                                if(fieldNameRange[i].xltype == xltypeStr)
                                                {
                                                        char *cellValue = new char[255];
                                                        int len = fieldNameRange[i].val.str[0];
Is it valid to assume that the array pointed to by fieldNameRange-
Post by sunil adhyaru
val.array.lparray is located immediately after fieldNameRange? I've
not seen anything to say this assumption is true. (though it may
luckily be in excel < 2k7??)

Instead of fieldNameRange[1-10] , you should be using fieldNameRange-
Post by sunil adhyaru
val.array.lparray[0-9].
Rgds,

Lee.

Loading...