Hi,
I'll try to find out more about the oActiveDoc.SaveAs method prototype. Meanwhile i started trying my hand on excel automation and i'm trying to insert data into the excel sheet. For data that is static i don't have a problem but for data that i want to insert at run time,the function that i lifted off msdn does not quite work.
I'm trying to insert strings and numbers of type double at runtime from a source. The function looks like :
void FillSafeArrayOfString(OLECHAR FAR* sz,int iRow,int iCol,COleSafeArray* sa)
{
VARIANT v;
long index[2];
index[0] = iRow;
index[1] = iCol;
VariantInit(&v); //DOUBLE dblVal; // VT_R8.
v.vt = VT_BSTR; //BSTR bstrVal; // VT_BSTR.
v.bstrVal = SysAllocString(sz);
sa->PutElement(index, v.bstrVal);
SysFreeString(v.bstrVal);
VariantClear(&v);
}
void FillSafeArrayOfDouble(double dval,int iRow,int iCol,COleSafeArray* sa)
{
VARIANT v;
long index[2];
index[0] = iRow;
index[1] = iCol;
VariantInit(&v); //DOUBLE dblVal; // VT_R8.
v.vt = VT_R8; //BSTR bstrVal; // VT_BSTR.
v.dblVal =dval;
sa->PutElement(index,&v);
VariantClear(&v);
}
The first function fills a string and the second a double in the specified cell. The function call looks like :
COleSafeArray saRet;
DWORD numElements[]={2,1}; //dimensions
saRet.Create(VT_BSTR, 2, numElements);
FillSafeArrayOfString(L"", 0, 0,&saRet); // in the "" would be the string i // want to place at runtime. I can't get rid of the 'L' and dyanamically placing it.
FillSafeArrayOfString(L"", 1, 0,&saRet);
range = sheet.GetRange(COleVariant("C2"), COleVariant("C3"));
range.SetValue2(COleVariant(saRet));
saRet.Detach();
Similarly for numbers : i want to insert the value dval1 into the cell F10.
COleSafeArray saRet;
double dval1;
dval1=m_dNumberOfRotatableBonds;
dval1=23.23;
DWORD numElements[]={1,1}; //dimensions
saRet.Create(VT_R8, 2, numElements);
FillSafeArrayOfDouble(dval1,0,0,&saRet);
range = sheet.GetRange(COleVariant("F10"), COleVariant("F10"));
range.SetValue2(COleVariant(saRet));
saRet.Detach();
This is not working. Could anyone please point out where i'm going wrong? Or else give me a reference to some code or another way of doing it?
Thanks a lot in advance for the efforts..
Priyanka