insert image into calc document

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

insert image into calc document

k.misha
Hi!

Regina, I have understood how to do it.

It's a sample of code:

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

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

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

      Reference< XShapes > xShapes(xDrawPage, UNO_QUERY);

 

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

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

 

      imgSize.Height = h*10;

      imgSize.Width = w*10;

    imgPoint.X = x*10;

    imgPoint.Y = y*10;

      ////////the size in 10/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<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));

 

      xShape->setPosition(imgPoint);

      xShape->setSize(imgSize);

      xDrawPage->add(xShape);

}