-
November 18th, 2009, 03:53 PM
#76
Re: Open Excel in VC++ and write data
Code:
IDispatch *pXlRange2;
{
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET, &result, pXlSheet, L"UsedRange", 0);
pXlRange2 = result.pdispVal;
AutoWrap(DISPATCH_METHOD,&result,pXlRange2,L"PrintOut",0);
}
Verere testudinem! (Fear the turtle)
Once you can accept the universe as matter expanding into nothing that is something, wearing stripes with plaid comes easy. -Albert Einstein
Robots are trying to steal my luggage.
-
November 20th, 2009, 01:53 AM
#77
Re: Open Excel in VC++ and write data
Hi Tom i m inserting the Image at the range specified by the user
void InsertImage(CString strImagePath, CString strRange)//Image will set within the Range given
{
VARIANT result;
VariantInit(&result);
VARIANT range;
range.vt = VT_BSTR;
range.bstrVal = ::SysAllocString(strRange);
AutoWrap(DISPATCH_PROPERTYGET, &result, pXlSheet, L"Range", 1, range);
pXlRange = result.pdispVal;
//Calculating the top, left, height & width of the Range
unsigned short vals;
vals=(unsigned short)0x0000007e;
double dTop,dLeft,dWidth,dHeight;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET,&result,pXlRange,L"Top",0);
dTop = result.dblVal;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET,&result,pXlRange,L"Left",0);
dLeft = result.dblVal;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET,&result,pXlRange,L"Width",0);
dWidth = result.dblVal;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET,&result,pXlRange,L"Height",0);
dHeight = result.dblVal;
IDispatch *pXlShapes;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET, &result, pXlSheet, L"Shapes", 0);
pXlShapes = result.pdispVal;
IDispatch *pXlShape;
VARIANT fname;
fname.vt = VT_BSTR;
fname.bstrVal=::SysAllocString(strImagePath);
VARIANT xpropf;
xpropf.vt=VT_BOOL;
xpropf.boolVal=FALSE;
VARIANT xpropt;
xpropt.vt=VT_BOOL;
xpropt.boolVal=TRUE;
VARIANT xtop;
xtop.vt=VT_R8;
xtop.dblVal= dTop;
VARIANT xleft;
xleft.vt=VT_R8;
xleft.dblVal=dLeft;
VARIANT xwidth;
xwidth.vt=VT_R8;
xwidth.dblVal=dWidth;
VARIANT xheight;
xheight.vt=VT_R8;
xheight.dblVal=dHeight;
AutoWrap(DISPATCH_METHOD, &result, pXlShapes, L"AddPicture", 7,xheight,xwidth,xleft,xtop,xpropt,xpropf,fname);
pXlShape = result.pdispVal;
}
using the code given by you
the image is inserted but not at the exact location of the range given
so please let me know where i m wrong?
one more thing i want to ask that
i want to insert the image at Begining cell given(like L"B2")
with exact image size means(picture left, top, width & height) whatever it may be.
Thanks in advance
-
November 20th, 2009, 09:36 AM
#78
Re: Open Excel in VC++ and write data
The arguments xleft and xtop are in the wrong positions: A typo in my code.
Replace this
Code:
AutoWrap(DISPATCH_METHOD, &result, pXlShapes, L"AddPicture", 7,xheight,xwidth,xleft,xtop,xpropt,xpropf,fname);
with this
Code:
AutoWrap(DISPATCH_METHOD, &result, pXlShapes, L"AddPicture", 7,xheight,xwidth,xtop,xleft,xpropt,xpropf,fname);
You can substitute the actual size of the image for xheight and xwidth if you don't want to force the image to be a certain size.
Or you can rescale the picture to the original size without knowing the original size using:
Code:
{
VARIANT xprop;
xprop.vt=VT_BOOL;
xprop.boolVal=TRUE;
VARIANT sratio;
sratio.vt=VT_R8;
sratio.dblVal=1.0;
AutoWrap(DISPATCH_METHOD, &result, pXlShape, L"ScaleWidth", 2,xprop,sratio);
AutoWrap(DISPATCH_METHOD, &result, pXlShape, L"ScaleHeight", 2,xprop,sratio);
}
Last edited by Tom Frohman; November 20th, 2009 at 10:04 AM.
Verere testudinem! (Fear the turtle)
Once you can accept the universe as matter expanding into nothing that is something, wearing stripes with plaid comes easy. -Albert Einstein
Robots are trying to steal my luggage.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|