Page 1 of 1

[Solved] How to add a gallery image into a Writer table Cell

PostPosted: Fri Dec 16, 2011 5:32 pm
by brunnerdan
I have the following code snippet :
Code: Select all   Expand viewCollapse view
Sub Main
  Dim momDocument, maTable As Object
  Dim cursCell as Object
  monDocument = ThisComponent
 
  maTable = monDocument.TextTables.getByName( "Tableau1" )
  cursCell = maTable.createCursorByCellName( "A1" )

  oGTP = CreateUnoService("com.sun.star.gallery.GalleryThemeProvider")
  sName = "ACVF-A..D"

  If oGTP.hasByName(sName) Then
    oTheme = oGTP.getByName(sName)
    nCount = oTheme.getCount()
    oItem = oTheme.getByIndex(nCount -1)


    // how to add the gallery image to the cell pointed by cursCell ?


  End If
End Sub

Having the reference
Code: Select all   Expand viewCollapse view
cursCell
to the TableCellCursor of a Writer document , how can I add the gallery image
Code: Select all   Expand viewCollapse view
oItem
to that position ? Is there any method that helps me to get a gallery item by name ?

Re: Howto add a gallery image into a Writer table Cell ?

PostPosted: Mon Dec 19, 2011 6:59 pm
by hanya
Insert image with oItem.URL of the image URL by general way which is known and can be found in this forum through the API.
Is there any method that helps me to get a gallery item by name ?
I have not seen it.

Re: Howto add a gallery image into a Writer table Cell ?

PostPosted: Wed Dec 21, 2011 2:35 pm
by brunnerdan
Thanks to all that helped my to finally reach my goal. Here is the solution :

Code: Select all   Expand viewCollapse view
sub instertItemToCell( sItem as String, sTable as String, sCell as String )
       
   C_TotalPageWidth = 18800
   oTextGraphicObject = ThisComponent.createInstance("com.sun.star.text.TextGraphicObject")

   oItem = getItemFromGallery(sItem)
   
   if not IsNull( oItem ) then
      oGraphic = oItem.Graphic
      oSize = oGraphic.Size
   
      oTable = ThisComponent.TextTables.getByName(sTable)
      oCursCell = oTable.getCellByName(sCell)
      
        oColumns = oTable.getPropertyValue( "TableColumnSeparators" )
      iColSeparator = oColumns(0).Position REM position of the first column separator
      iTotalColumns = oTable.TableColumnRelativeSum
   
        rWidthRatio = iColSeparator/iTotalColumns
      iGraphicWidth = C_TotalPageWidth*rWidthRatio
      rGraphicAmplify = iGraphicWidth/oSize.Width
      iGraphicHeight = oSize.Height*rGraphicAmplify
   
      oSize.Width = iGraphicWidth
      oSize.Height = iGraphicHeight
      
      oTextGraphicObject.Graphic = oGraphic
      oTextGraphicObject.setSize(oSize)

   
       oCursText = oCursCell.Text
         oTextCellCurs = oCursText.createTextCursor
         
       oCursText.insertTextContent( oTextCellCurs, oTextGraphicObject, true)   
    end if
end sub

Re: [Solved] How to add a gallery image into a Writer table

PostPosted: Fri Oct 16, 2020 12:30 pm
by Ms Ruth
brunnerdan wrote:Is there any method that helps me to get a gallery item by name ?


Presuming by name, you meant title. The item's name (in a document) is not necessarily the same as the item's title (in the gallery). I used this code to get a gallery item by title.

Code: Select all   Expand viewCollapse view
   Cache = CreateUnoService("com.sun.star.gallery.GalleryThemeProvider")
   Theme = Cache.getByName("MyShapes")
   For Nth = 0 To Theme.Count - 1
      Shp = Theme(Nth)
      If Shp.Title = "‹ShapeTitle›" Then Exit For
   Next