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

The Application Programming Interface and the OASIS Open Document Format
Post Reply
brunnerdan
Posts: 43
Joined: Tue Nov 29, 2011 12:41 am

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

Post by brunnerdan »

I have the following code snippet :

Code: Select all

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

cursCell
to the TableCellCursor of a Writer document , how can I add the gallery image

Code: Select all

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
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 ?

Post 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.
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
brunnerdan
Posts: 43
Joined: Tue Nov 29, 2011 12:41 am

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

Post by brunnerdan »

Thanks to all that helped my to finally reach my goal. Here is the solution :

Code: Select all

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
User avatar
Ms Ruth
Posts: 3
Joined: Thu Mar 19, 2020 9:00 pm

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

Post 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

   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.11
LibreOffice 7.1.8 (x64)
Windows 10
Post Reply