Steffen,
please find the basic code who inserts graphics in Tablecells using the
cell dimensions to dimensioning the grapgics.
Finding the dimensions off a cell can be tricky when cells are merged
ect.. therefore i use the "dificult to read" :-)firts part of the code
hope it helps
Fernand
oText = oDocument.text
RasterofCursor = True
oViewCursor = oDocument.getCurrentController().getViewCursor()
' xray oviewcursor
If Not isEmpty(oViewCursor.TextTable) then ' Cursor is in een Tabel
' sFrameofTabel = "TABEL"
' inFRameofTabel = true
' RasterofCursor = False
Twidth = oViewCursor.TextTable.width
TTotalpercent = oViewCursor.TextTable.TableColumnRelativeSum
startcell = oViewCursor.cell.cellname
Kindex = asc(left(oViewCursor.cell.cellname,1))-65
Rindex = int(mid(oViewCursor.cell.cellname,2,2))-1
CurRow = oViewCursor.texttable.rows.getbyindex(Rindex)
if CurRow.IsAutoHeight = True then
msgbox "De ROWhooghte moet FIXED zijn !!!!!" & chr(13) & "Eerst
aanpassen, dan pas kan je verder"
exit sub
end if
if
oViewCursor.cell.compareRegionStarts(oViewCursor.cell.getstart,oViewCursor.cell.getend)
<> 0 or oViewCursor.cell.string <>"" then
msgbox "er mag in de cell enkel één" & chr(13) & "RETURN staan" &
chr(13) & "Eerst aanpassen, dan pas kan je verder"
exit sub
endif
if oViewCursor.paraStylename <> "Standard" then
msgbox "de ParaGraphStyle in de Tabelcell staat niet op default" &
chr(13) & "wordt nu automatisch aangepast !!"
oViewCursor.ParaStyleName = "Standard"
end if
if oViewCursor.CharStylename <> "" then
msgbox "de CharacterStyle in de Tabelcell staat niet op default" &
chr(13) & "wordt nu automatisch aangepast !!"
oViewCursor.setPropertyToDefault("CharStyleName")
end if
if oViewCursor.texttable.Horiorient = 6 then
msgbox " De Table mag niet AUTOMATISCH gealigneerd zijn" & chr(13) &
"wordt nu automatisch aangepast naar ""center"" !!"
oViewCursor.texttable.Horiorient = 2
end if
' welke cell ??
startcellname = oViewCursor.cell.cellname
startrow = int(mid(startcellname,2,2))
if oViewCursor.cell.VertOrient <> 2 then
msgbox "Cursor staat niet in de HOOGTE gecentreerd" & chr(13) &
"wordt nu automatisch aangepast !!"
oViewCursor.cell.VertOrient = 2
end if
if oViewCursor.cell.createEnumeration.nextelement.paraAdjust <> 3 then
msgbox "Tabelcell-Cursor is Niet in de BREEDTE gecentreerd" &
chr(13) & "wordt nu automatisch aangepast !!"
oViewCursor.cell.createEnumeration.nextelement.paraAdjust = 3
end if
oViewcursor.goDOWN(1,false) ' de tabel MOET in een FRame
zitten anders problemen bij de onderste rij !!!!!
if isEmpty(oViewCursor.TextTable) then
startcellpos = "ONDER"
oViewcursor.goUP(1,false)
end if
if startcellpos = "ONDER" then
'eerst terug naar startcell
otext = oviewcursor.texttable.getcellbyname(startcellname,true).text
otabelCursor = oText.createTextCursor()
oViewcursor.gotorange(otabelCursor,false)
' xray oViewcursor
If otext.supportsService("com.sun.star.text.Paragraph") then
print "is paragraaf"
exit sub
end if
laatsterow = oViewCursor.TextTable.rows.count
if laatsterow = int(mid(oViewCursor.cell.cellname,2,2)) then ' cell
is één row hoog
iFotH = oViewCursor.texttable.rows.getbyindex(Rindex).height
else
for i= 0 to laatsterow - int(mid(oViewCursor.cell.cellname,2,2))
iFotH = iFotH + oViewCursor.texttable.rows.getbyindex(Rindex+ i
).height
next i
end if
else 'cell boven of midden
' eerst terug naar de startcell
otext = oviewcursor.texttable.getcellbyname(startcellname,true).text
otabelCursor = oText.createTextCursor()
oViewcursor.gotorange(otabelCursor,false)
startrow = int(mid(oViewCursor.cell.cellname,2,2))
oViewcursor.goDOWN(1,false)
volgenderow = int(mid(oViewCursor.cell.cellname,2,2))
if isEmpty(oViewCursor.TextTable) then 'terug naar binnen de tabel
oViewcursor.goUP(1,false)
end if
' terug naar de startcell
otext = oviewcursor.texttable.getcellbyname(startcellname,true).text
otabelCursor = oText.createTextCursor()
oViewcursor.gotorange(otabelCursor,false)
for i= 1 to volgenderow - startrow
iFotH = iFotH + oViewCursor.texttable.rows.getbyindex(Rindex + i-1
).height
next i
endif
' iFotH = CurRow.height
tabstops = CurRow.TableColumnSeparators()
if uBound(tabstops)< 0 then
iFotW = tWidth
else
if kindex = 0 then
iFotW = (twidth * tabstops(Kindex).position/TTotalpercent)
elseif kindex -1 = ubound(tabstops) then
iFotW = twidth - (twidth *
tabstops(Kindex-1).position/TTotalpercent)
else
iFotW = (twidth * tabstops(Kindex).position/TTotalpercent) -
(twidth * tabstops(Kindex-1).position/TTotalpercent)
endif
end if
otext = oViewCursor.text
lAnchor = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
'AT_PARAGRAPH '
oShape =
oDocument.createInstance("com.sun.star.drawing.GraphicObjectShape") '
shape is leeg
oGraphic = oDocument.createInstance("com.sun.star.text.GraphicObject")
oDocument.getDrawPage().add(oShape)
oOriginalGraph = getGraphFromUrl(sGraphicURL)
oShape.Graphic = oOriginalGraph
oGraphic.GraphicUrl = oShape.GraphicUrl
oGraphic.AnchorType = lAnchor
oCell = oViewCursor.cell
oText = oCell.getText()
iFOTh = iFOTH - oCell.BottomBorderDistance - oCell.TopBorderDistance
iFOTw = iFOTw - oCell.LeftBorderDistance - oCell.RightBorderDistance
oCursor = oText.createTextCursor()
oText.insertTextContent( oCursor, oGraphic, False )
' We no longer require the shape object.
oDocument.getDrawPage().reMove(oShape)
oShape = nothing
oGraphic.HoriOrientPosition = 0
oGraphic.VertOrientPosition = 0
oGraphic.SetPropertyValue("GraphicCrop" , aCrop)
oGraphic.SetPropertyValue("HyperLinkName" , sGraphicURL)
oGraphic.PositionProtected = False
oGraphic.SizeProtected = False
oGraphic.ContentProtected = True
oGraphic.width = iFotW
oGraphic.height = iFotH
oGraphic.HoriOrient = NONE
oGraphic.VertOrient = NONE
> Hi,
>
> i'm currently trying to solve my problem with tablecells.
> I managed to get my GraphicObjects into my oWriter files with help of
> snippets, mainly with
>
>
http://codesnippets.services.openoffice.org/Writer/Writer.EmbedAGraphicIntoATextdocument.snip
>
>
> To determine the position where to anchor the image, I'm using
> placeholders as normal strings within my oWriter file.
> A XTextCursor is placed onto that placeholder and ist used for
>
> text.insertTextContent(cursor, xTextContent, true);
>
> Runs smoothly except for the fact, that if my placeholder is within a
> table I'm getting a RuntimeException with no further details.
> After some research online I've found several approaches to that
> problem. One which suggests using the method
>
> getCellParagraph($cell)
>
> to get an anchor to that specific cell. Problem is, there is no
> getCellParagraph() method in the API of OOo.
> Maybe it was an older approach.
> The second approach I found suggests using Shapes to add them to
> DrawPages. I couldn't figure out to make that one work, maybe because
> it was suggested for oCalc instead of oWriter. But I don't know if it
> should work in oWriter the same way and I'm just too dumb to use it.
> That one was discussed here:
>
>
http://api.openoffice.org/servlets/ReadMsg?listName=dev&msgNo=2618>
> So my questions are:
> (1) Is it possible to use insertTextContent with images in tablecells
> when I'm in oWriter? And what do I have to change to make it work?
> When not, why isn't it possible?
> (2) Is using Shapes also the way to go for oWriter if I'm trying to
> get images into tablecells?
> (3) What mehtod is used if I manually insert images into cells with
> the oWriter GUI?
>
> Thanks in advance.
>
> Steffen Boersig
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
dev-unsubscribe@...
> For additional commands, e-mail:
dev-help@...
---------------------------------------------------------------------
To unsubscribe, e-mail:
dev-unsubscribe@...
For additional commands, e-mail:
dev-help@...