Hi Matheus, On Thu, Feb 16, 2012 at 01:43:58PM -0200, Matheus Garcia wrote: > Hi, > > I need to programmatically convert some documents which contains some > table with absolute width to relative sizes. The purpose of that change > is that when converted to HTML the width of that absolute table is also > fixed, and that leads to scrollbars appearing when document is viewed in > small screen devices. > > I don't know a better way to do that, so I thought on creating an event > handler to do these changes during the onSave and onSaveAs event. The > event is being caught, but I'm in doubt on how to get the necessary info > to do these changes. > > More specifically, I've create a procedure to loop into all tables, and > test if it is relative width or not. If its has absolute width, I want > to change sizes. There are a lot of details involved, but in the > simplest case, I just need to get the fraction of page width that the > table occupies. > > So that's my situation: if have a XTextTable, how can I get the page > width that contains that table? I tried to call getAnchor() without > success, as its said the TextTable docs that "(...) the anchor of the > actual implementation for text tables does not have a position in the > text. Thus that anchor can not be used for some operation like > XTextContent::attach or XText::insertTextContent or other function that > require the object to have a position in the text. (...)" > > Does any of you can help me in solving that? Or is there another way to > do these transformations?
The easiest way will be to play with the HoriOrient property of the
table:
Sub TablesWidth_PageSizeAuto
Dim oDoc
oDoc = ThisComponent
Dim oTables
oTables = oDoc.getTextTables()
Dim sName$, oTable
For Each sName in
oTables.getElementNames()
oTable = oTables.getByName(sName)
With oTable
.HoriOrient = com.sun.star.text.HoriOrientation.NONE
.LeftMargin = 0
.RightMargin = 0
End With
Next
End Sub
Width this code, tables will fit in the page text area.
Something more complex, is calculating the table width (and its margins)
according to the page width:
Const RELATIVEWIDTH = 75
Sub TablesWidth_RelWidth
Dim oDoc
oDoc = ThisComponent
Dim oTables
oTables = oDoc.getTextTables()
Dim sName$, oTable, oCell, oCursor, sStyleName$, oStyle
Dim iTextAreaWidth as Long, iTableWidth as Long
For Each sName in oTables.getElementNames()
oTable = oTables.getByName(sName)
oCell = oTable.getCellByName("A1")
oCursor = oCell.getText().createTextCursor()
sStyleName = oCursor.PageStyleName
oStyle =
oDoc.getStyleFamilies().getByName("PageStyles").getByName(sStyleName)
With oStyle
iTextAreaWidth = .Width - .LeftMargin - .RightMargin -
.LeftBorderDistance - .RightBorderDistance
End With
iTableWidth = (iTextAreaWidth * RELATIVEWIDTH) / 100
iMargins = (iTextAreaWidth - iTableWidth) / 2
With oTable
.HoriOrient = com.sun.star.text.HoriOrientation.NONE
.LeftMargin = iMargins
.RightMargin = iMargins
.Width = iTableWidth
End With
Next
End Sub
With this code tables will be centered, with a 75% width relative to
the page with.
Regards
--
Ariel Constenla-Haile
La Plata, Argentina
pgpAW6Vj3sJqR.pgp
Description: PGP signature
