Page 1 of 1

How to Modify Table Cell Border (Line and Style)

PostPosted: Sun Oct 01, 2017 2:20 am
by JeanJouX
Hello

I'm trying to make a basic macro to create a table in a Writer document and I would like my table to have a it's cell to have a precise background color and border line (width and style).
I managed to create the table and set the background color with :

Code: Select all   Expand viewCollapse view
vCursor = ThisComponent.CurrentController.getViewCursor ()
oTable = ThisComponent.createInstance ("com.sun.star.text.TextTable")
oTable.initialize (10, 5)
...
oTable.getCellByPosition(1,cpt).BackColor = RGB(51,204,102)


Now I would like to modify the border line, both the line width and the style (dashed, double, ...) but I didn't find how to to do. I found in the api site https://api.libreoffice.org/docs/idl/ref/structcom_1_1sun_1_1star_1_1table_1_1BorderLine2.html the struct BorderLine2 which seam to contain the relevant properties but there is no method in the Cell class which use it.

What is the right way to modify the line width and style of borders in tables ? If it's possible.

Re: How to Modify Table Cell Border (Line and Style)

PostPosted: Sun Oct 01, 2017 6:48 am
by FJCC
This code modifies the TopBorder of cell A1.
Code: Select all   Expand viewCollapse view
Dim Bline as New com.sun.star.table.BorderLine
Bline.Color = RGB(255,0,0)
Bline.OuterLineWidth = 30
Bline.LineDistance = 50
Bline.InnerLineWidth = 30

oTables = ThisComponent.TextTables
oTbl = oTables.getByIndex(0)
oCell = oTbl.getCellByName("A1")
oCell.TopBorder = Bline

I don't think dashed lines are available but you can change the thickness and color and make the line double or single. The OuterLineWidth controls single lines. In addition to a TopBorder, a cell also as a LeftBorder, RightBorder and BottomBorder.

Re: How to Modify Table Cell Border (Line and Style)

PostPosted: Sun Oct 01, 2017 6:58 am
by JohnSUN-Pensioner
In addition to the answer of the respected FJCC. If it seems to you that after the code execution nothing happened, add the lines to changing the border of the adjacent cell. For example, after applying .TopBorder = Bline to cell B2 you not see result, so add .BottomBorder = Bline to cell A2