Ramiki w Calc z makrami formatěrować

Z pomocu programowanskich rěčow Basic abo Python dadźa so makra pisać, kotrež formaty na celowe wobłuki w Calc nałožuja.

Ramiki w celowych wobłukach formatěrować

Slědowacy kodowy wotrězk Sub z mjenom FormatCellBorder wutwori, kotryž nowe ramikowe formaty na datu wobłukowu adresu w aktualnej tabeli Calc nałožuje.


    Sub FormatCellBorder(cellAddress as String, newStyle as Byte, newWidth as Long, Optional newColor as Long)
        ' Wutwori UNO-strukturu, kotraž nowy linkowy format składuje
        Dim lineFormat as New com.sun.star.table.BorderLine2
        lineFormat.LineStyle = newStyle
        lineFormat.LineWidth = newWidth
        If Not IsMissing(newColor) Then lineFormat.Color = newColor
        ' Wuwołuje cilowu celu
        Dim oCell as Object
        Set oCell = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName(cellAddress)
        ' Nałožuje nowy format na wšě ramiki
        oCell.TopBorder = lineFormat
        oCell.RightBorder = lineFormat
        oCell.LeftBorder = lineFormat
        oCell.BottomBorder = lineFormat
    End Sub
  

Horjeka wopisany Sub štyri argumenty přijima:

Zo byšće FormatCellBorder wuwołał, wutworće nowe makro a přepodajće požadane argumenty, kaž so deleka pokazuje:


    Sub MyMacro
        ' Zmóžnja přistup ke konstantam linijoweho stila
        Dim cStyle as Object
        Set cStyle = com.sun.star.table.BorderLineStyle
        ' Formatěruje "B5" z přećehnjenymi módrymi ramikami
        FormatCellBorder("B5", cStyle.SOLID, 20, RGB(0, 0, 255))
        ' Formatěruje wšě ramiki we wobłuku "D2:F6" z čerwjenymi dypkowanymi ramikami
        FormatCellBorder("D2:F6", cStyle.DOTTED, 20, RGB(255, 0, 0))
    End Sub
  

Je móžno, samsnu funkcionalnosć w Python implementować:


    from uno import createUnoStruct
    from scriptforge import CreateScriptService
    
    def formatCellBorder(cellAddress, newStyle, newWidth, newColor=0):
        # Definuje nowy linijowy format
        line_format = createUnoStruct("com.sun.star.table.BorderLine2")
        line_format.LineStyle = newStyle
        line_format.LineWidth = newWidth
        line_format.Color = newColor
        # Słužba Scriptforge za přistup k celowym wobłukam
        doc = CreateScriptService("Calc")
        cell = doc.XCellRange(cellAddress)
        cell.TopBorder = line_format
        cell.RightBorder = line_format
        cell.LeftBorder = line_format
        cell.BottomBorder = line_format
  

Slědowacy kodowy wurězk makro z mjenom myMacro implementuje, kotrež formatCellBorder wuwołuje:


    from com.sun.star.table import BorderLineStyle as cStyle
    
    def myMacro():
        bas = CreateScriptService("Basic")
        formatCellBorder("B5", cStyle.SOLID, 20, bas.RGB(0, 0, 255))
        formatCellBorder("D2:F6", cStyle.DOTTED, 20, bas.RGB(255, 0, 0))
  
note

Horjeka předstajeny kod Python biblioteku ScriptForge wužiwa, kotraž je wot wersije LibreOffice 7.2 k dispoziciji.


Linijowe stile

Linijowe stile su jako cyłoličbne konstanty definowane. Slědowaca tabela konstanty za linijowe stile nalistuje, kotrež su w Format – Cele – Rajtark: Ramiki k dispoziciji:

Mjeno konstanty

Cyłoličbna hódnota

Mjeno linijoweho stila

SOLID

0

Přezcyłny

DOTTED

1

Dypkowany

DASHED

2

Smužkowany

FINE_DASHED

14

Drobnje smužkowany

DOUBLE_THIN

15

Dwójny ćeńki

DASH_DOT

16

Smužkowy dypk

DASH_DOT_DOT

17

Smužkowy dypkowy dypk


tip

Čitajće BorderLineStyle Constant Reference (jendźelsce) w dokumentaciji API LibreOffice, zo byšće wjace wo konstantach linijoweho stila zhonił.


Z TableBorder2 ramiki formatěrować

Wobłukowe objekty maja kajkosć z mjenom TableBorder2, kotruž móžeće wužiwać, zo byšće wobłukowe ramiki formatěrował, runje tak kaž w dialogu Format – Cele… – Ramiki we wotrězku Linijowy porjad.

Nimo hornich, delnich, lěwych a prawych ramikow TableBorder2 tež wertikalne a horicontalne ramiki definuje. Slědowace makro jenož horni a delni ramik na wobłuk "B2:E5" nałožuje.


    Sub TableBorder2Example
        Dim cStyle as Object
        Set cStyle = com.sun.star.table.BorderLineStyle
        ' Definuje nowy linijowy format
        Dim lineFormat as New com.sun.star.table.BorderLine2
        lineFormat.LineStyle = cStyle.SOLID
        lineFormat.LineWidth = 15
        lineFormat.Color = RGB(0, 0, 0)
        ' Struktura, kotraž nowu definiciju TableBorder2 składuje
        Dim tableFormat as New com.sun.star.table.TableBorder2
        tableFormat.TopLine = lineFormat
        tableFormat.BottomLine = lineFormat
        tableFormat.IsTopLineValid = True
        tableFormat.IsBottomLineValid = True
        ' Nałožuje tabelowy format na wobłuk "B2:E5"
        Dim oCell as Object
        oCell = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("B2:E5")
        oCell.TableBorder2 = tableFormat
    End Sub
  

Makro da so w Python takle implementować:


    from com.sun.star.table import BorderLineStyle as cStyle
    from scriptforge import CreateScriptService
    
    def tableBorder2Example():
        bas = CreateScriptService("Basic")
        line_format = createUnoStruct("com.sun.star.table.BorderLine2")
        line_format.LineStyle = cStyle.SOLID
        line_format.LineWidth = 18
        line_format.Color = bas.RGB(0, 0, 0)
        table_format = createUnoStruct("com.sun.star.table.TableBorder2")
        table_format.TopLine = line_format
        table_format.BottomLine = line_format
        table_format.IsTopLineValid = True
        table_format.IsBottomLineValid = True
        doc = CreateScriptService("Calc")
        cell = doc.XCellRange("B2:E5")
        cell.TableBorder2 = table_format
  
tip

Čitajće TableBorder2 Struct Reference (jendźelsce) w dokumentaciji API LibreOffice, zo byšće wjace wo jeho atributach zhonił.


Prošu podpěrajće nas!