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

The Application Programming Interface and the OASIS Open Document Format

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

Postby brunnerdan » Fri Dec 16, 2011 5:32 pm

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 ?
Last edited by brunnerdan on Wed Dec 21, 2011 2:35 pm, edited 1 time in total.
OOO 3.3 on Solaris/Windows
brunnerdan
 
Posts: 43
Joined: Tue Nov 29, 2011 12:41 am

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

Postby hanya » Mon Dec 19, 2011 6:59 pm

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.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

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

Postby brunnerdan » Wed Dec 21, 2011 2:35 pm

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
OOO 3.3 on Solaris/Windows
brunnerdan
 
Posts: 43
Joined: Tue Nov 29, 2011 12:41 am

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

Postby Ms Ruth » Fri Oct 16, 2020 12:30 pm

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
Apache OpenOffice 4.1.7
LibreOffice 6.4.6.2 (x64)
Windows 10
Ms Ruth
 
Posts: 2
Joined: Thu Mar 19, 2020 9:00 pm


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 3 guests