OO SDK

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

OO SDK

k.misha
Hi!

 

How I can insert Image to a calc document using oo sdk 3.4.1?

 

Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: OO SDK

Ariel Constenla-Haile-2
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

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: OO SDK

k.misha
Thanks a lot!<неиDo you have any examples in VS
C++?<неи<неи<неи-----Original Message-----<неиFrom: Ariel Constenla-Haile
[mailto:[hidden email]] <неиSent: Wednesday, May 08, 2013 6:58 PM<неиTo:
[hidden email]<неиSubject: Re: OO SDK<неи<неи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/Sp
readsheet.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<неи


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]