openoffice-api mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "K.Misha" <mi...@4k.com.ua>
Subject insert image into calc document
Date Mon, 05 Aug 2013 16:21:28 GMT
 

From: K.Misha [mailto:misha@4k.com.ua] 
Sent: Monday, August 05, 2013 7:21 PM
To: 'ooapi@openoffice.com'
Subject: insert image into calc document

 

Hello! 

 

I have a problem with inserting image into calc document!

I'm doing it this way:

 

void insertImage( imgPosition iPos, imgSize iSize, char * imgUrl )

{

Reference< com::sun::star::drawing::XDrawPagesSupplier >
xDrawPagesSupplier(xCalcComponent, UNO_QUERY);

      Reference< XDrawPages > xDrawPages(
xDrawPagesSupplier->getDrawPages(), UNO_QUERY );

      Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex(irSheet),
UNO_QUERY );

      Reference< XShapes > xShapes(xDrawPage, UNO_QUERY);

 

      com::sun::star::awt::Point imgPoint;

      com::sun::star::awt::Size imgSize;

 

      imgSize.Height = iSize.h;

      imgSize.Width = iSize.w;

    imgPoint.X = iPos.x;

    imgPoint.Y = iPos.y;

      ////////the size in 100/th mm

 

      Reference<XSpreadsheetDocument> xSheetDocument
(xCalcComponent,UNO_QUERY);

    Reference< XModel > aDrawDoc (xSheetDocument, UNO_QUERY);

      Reference<XMultiServiceFactory> aFact(aDrawDoc,UNO_QUERY);

      Reference< XShape > xShape(
aFact->createInstance(OUString::createFromAscii("com.sun.star.drawing.Graphi
cObjectShape")), UNO_QUERY);

      //Reference< XShape > xShape( xShapes->getByIndex(0), UNO_QUERY);

 

      Reference<XPropertySet> rColProps(xShape, UNO_QUERY);

 

      char * img = imgUrl;//"file:///D:/getImage3.jpeg";

      int nLenOfWideCharStr
=MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,img,-1,NULL,0);

      wchar_t *cImg = (PWSTR)HeapAlloc(GetProcessHeap(), 0,
nLenOfWideCharStr * sizeof(WCHAR));

 
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,img,-1,cImg,nLenOfWideCharStr);

 

      OUString sstring = cImg;

 

 
rColProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL
")), makeAny(sstring));

 
//rColProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Name")),
makeAny(sstring));

 

      xShape->setPosition(imgPoint);

      xShape->setSize(imgSize);

      xDrawPage->add(xShape);

}

 

//////////////////////////////////////

But every time when i open this calc document, image must be in this path -
imgUrl. How can i insert image into file body of calc document?

 

Thanks!


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message