How to Modify Table Cell Border (Line and Style)

Creating a macro - Writing a Script - Using the API

How to Modify Table Cell Border (Line and Style)

Postby JeanJouX » Sun Oct 01, 2017 2:20 am


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 ("")
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 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.
LibreOffice on Linux Debian 9
Posts: 1
Joined: Sun Oct 01, 2017 1:57 am

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

Postby FJCC » Sun Oct 01, 2017 6:48 am

This code modifies the TopBorder of cell A1.
Code: Select all   Expand viewCollapse view
Dim Bline as New
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.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Posts: 7652
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

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

Postby JohnSUN-Pensioner » Sun Oct 01, 2017 6:58 am

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
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
User avatar
Posts: 823
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests