Hi k. misha, On Wed, May 08, 2013 at 02:56:31PM +0300, k.misha wrote: > Hi! > > > > How I can insert Image to a calc document using oo sdk 3.4.1?
(Side note: please use descriptive subjects in the mails, something like "Inserting image in Calc") Each spreadsheet is described here: http://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/Spreadsheet.html As you can see, it supports ::com::sun::star::drawing::XDrawPageSupplier Then: - access a spreadsheet - get the draw page for this spreadsheet - create a com.sun.star.drawing.GraphicObjectShape at the document factory, set its size, position and graphic URL/css.graphic.XGraphic - add the shape to the draw page. Sample code in Basic: REM ***** BASIC ***** Sub Main Dim oDoc as Object oDoc = StarDesktop.loadComponentFromURL(_ "private:factory/scalc",_ "_default",_ 0,_ Array()) Dim oGraphic as Object Dim oGraphicProvider as Object oGraphicProvider = CreateUnoService(_ "com.sun.star.graphic.GraphicProvider") Dim aArgs(0) as new com.sun.star.beans.PropertyValue aArgs(0).Name = "URL" aArgs(0).Value = "private:graphicrepository/framework/res/backing.png" oGraphic = oGraphicProvider.queryGraphic(aArgs) If IsNull(oGraphic) OR oGraphic.getType() = com.sun.star.graphic.GraphicType.EMPTY Then Exit Sub End If Dim oSize100thMM as Object oSize100thMM = oGraphic.Size100thMM If oSize100thMM.Width = 0 OR oSize100thMM.Height = 0 Then Dim oSizePixel as Object oSizePixel = oGraphic.SizePixel If oSizePixel.Width = 0 OR oSizePixel.Height = 0 Then Exit Sub End If Dim oUnitConversion as Object oUnitConversion = oDoc.getCurrentController().getFrame().getContainerWindow() oSize100thMM = oUnitConversion.convertSizeToLogic(oSizePixel,com.sun.star.util.MeasureUnit.MM_100TH) End If Dim oSheets as Object Dim oSheet as Object oSheets = oDoc.getSheets() If NOT oSheets.hasElements() Then 'ToDo insert one Exit Sub End If oSheet = oSheets.getByIndex(0) Dim oDrawPage as Object oDrawPage = oSheet.getDrawPage() Dim oGraphicShape as Object oGraphicShape = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape") Dim oPoint as new com.sun.star.awt.Point oPoint.X = 5000 oPoint.Y = 200 With oGraphicShape .setPosition(oPoint) .setSize(oSize100thMM) .Graphic = oGraphic End With oDrawPage.add(oGraphicShape) End Sub Regards -- Ariel Constenla-Haile La Plata, Argentina
pgpgSsRF3rcmC.pgp
Description: PGP signature