Word Automation-SaveAs Parameters Error
Collapse
X
-
Tags: None
-
-
Hi..Originally posted by weaknessforcatsWhat does your call look like?
Here is the function call..
oActiveDoc.Save As(COleVariant( "e:\\priyanka\\ testdoc2.doc"),
COleVariant((sh ort)0),
vFalse, COleVariant("") , vTrue, COleVariant("") ,
vFalse, vFalse, vFalse, vFalse,vFalse);
Its for word 2003 like i mentioned earlier.. Any idea how many params it takes??Comment
-
What is the function prototype of oActiveDoc.Save As()???Originally posted by priyankalakheoActiveDoc.Save As(COleVariant( "e:\\priyanka\\ testdoc2.doc"),
The only SaveAS I found was one in C# that takes 16 arguments.Comment
-
Hi,
I'll try to find out more about the oActiveDoc.Save As 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 FillSafeArrayOf String(OLECHAR FAR* sz,int iRow,int iCol,COleSafeAr ray* 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(ind ex, v.bstrVal);
SysFreeString(v .bstrVal);
VariantClear(&v );
}
void FillSafeArrayOf Double(double dval,int iRow,int iCol,COleSafeAr ray* 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(ind ex,&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);
FillSafeArrayOf String(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.
FillSafeArrayOf String(L"", 1, 0,&saRet);
range = sheet.GetRange( COleVariant("C2 "), COleVariant("C3 "));
range.SetValue2 (COleVariant(sa Ret));
saRet.Detach();
Similarly for numbers : i want to insert the value dval1 into the cell F10.
COleSafeArray saRet;
double dval1;
dval1=m_dNumber OfRotatableBond s;
dval1=23.23;
DWORD numElements[]={1,1}; //dimensions
saRet.Create(VT _R8, 2, numElements);
FillSafeArrayOf Double(dval1,0, 0,&saRet);
range = sheet.GetRange( COleVariant("F1 0"), COleVariant("F1 0"));
range.SetValue2 (COleVariant(sa Ret));
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..
PriyankaComment
-
This code:
looks fishy.Originally posted by priyankalakhev.bstrVal = SysAllocString( sz);
sa->PutElement(ind ex, v.bstrVal);
SysFreeString(v .bstrVal);
First, you allocate a BSTR
Second, you call PutElement with the BSTR.
Third, you delete the BSTR.
I believe that you have just deleted the BSTR you allocated. PutElement() just passes the BTSR along as a pointer.
I do not believe you can delete this BSTR until there are no copies of the pointer to that BSTR left in your program.
I recommend using a smart pointer here. Check this article on Handle Classes.Comment
-
Originally posted by weaknessforcatsThis code:
looks fishy.
First, you allocate a BSTR
Second, you call PutElement with the BSTR.
Third, you delete the BSTR.
I believe that you have just deleted the BSTR you allocated. PutElement() just passes the BTSR along as a pointer.
I do not believe you can delete this BSTR until there are no copies of the pointer to that BSTR left in your program.
I recommend using a smart pointer here. Check this article on Handle Classes.
Thanks.. I got rid of those two functions and tried a simpler one using Setvalue2(). It worked!Comment
-
HI,
u were specifying abt automation. I have get data and write to a file say excel, in real time will this automation wil be useful. i am using TCp/IP socket for client server connection. Plz do reply.Comment
-
Hi,Originally posted by gnanapoongothaiHI,
u were specifying abt automation. I have get data and write to a file say excel, in real time will this automation wil be useful. i am using TCp/IP socket for client server connection. Plz do reply.
I really have no idea.. U should try asking around someone else in the forum.I'm a newbie too.
PriyankaComment
Comment