How to Modify Table Cell Border (Line and Style)

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
JeanJouX
Posts: 1
Joined: Sun Oct 01, 2017 1:57 am

How to Modify Table Cell Border (Line and Style)

Post 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

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/re ... Line2.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.
LibreOffice 5.2.7.2 on Linux Debian 9
FJCC
Moderator
Posts: 9270
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

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

Post by FJCC »

This code modifies the TopBorder of cell A1.

Code: Select all

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.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

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

Post 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
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
Post Reply