Calc aplikazioan ertzei formatua ematea makroen bidez

Basic edo Python programazio-lengoaien bidez, Calc aplikazioko gelaxka-barrutiei formatua aplikatzeko erabili daitezkeen makroak idatzi daitezke.

Ertzei formatua ematea gelaxka-barrutietan

Beheko kode-zatiak FormatCellBorder izeneko Sub bat sortzen du, uneko Calc orriko barruti-helbide bati ertz-formatu berria aplikatzeko.


    Sub FormatCellBorder(cellAddress as String, newStyle as Byte, newWidth as Long, Optional newColor as Long)
        ' Lerro berriaren formatua biltegiratuko duen UNO struct bat sortzen du
        Dim lineFormat as New com.sun.star.table.BorderLine2
        lineFormat.LineStyle = newStyle
        lineFormat.LineWidth = newWidth
        If Not IsMissing(newColor) Then lineFormat.Color = newColor
        ' Helburuko gelaxka eskuratzen du
        Dim oCell as Object
        Set oCell = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName(cellAddress)
        ' Formatu berria ertz guztiei aplikatzen die
        oCell.TopBorder = lineFormat
        oCell.RightBorder = lineFormat
        oCell.LeftBorder = lineFormat
        oCell.BottomBorder = lineFormat
    End Sub
  

Goian deskribatutako Sub elementuak lau argumentu ditu:

FormatCellBorder funtzioari deitzeko, sortu beste makro bat eta pasatu beharrezkoak diren argumentuan, behean erakusten den moduan:


    Sub MyMacro
        ' Marra-estiloaren konstanteak atzitzea ahalbidetzen du
        Dim cStyle as Object
        Set cStyle = com.sun.star.table.BorderLineStyle
        ' Ertz urdin solidoak ematen dizkio "B5" gelaxkari
        FormatCellBorder("B5", cStyle.SOLID, 20, RGB(0, 0, 255))
        ' Ertz gorri puntukatua ematen die "D2:F6" barrutiko ertz guztiei
        FormatCellBorder("D2:F6", cStyle.DOTTED, 20, RGB(255, 0, 0))
    End Sub
  

Funtzionaltasun bera Python lengoaian ere inplementatu daiteke:


    from uno import createUnoStruct
    from scriptforge import CreateScriptService
    
    def formatCellBorder(cellAddress, newStyle, newWidth, newColor=0):
        # Lerro berriaren formatua definitzen du
        line_format = createUnoStruct("com.sun.star.table.BorderLine2")
        line_format.LineStyle = newStyle
        line_format.LineWidth = newWidth
        line_format.Color = newColor
        # Gelaxka-barruti guztiak atzitzeko Scriptforge zerbitzua
        doc = CreateScriptService("Calc")
        cell = doc.XCellRange(cellAddress)
        cell.TopBorder = line_format
        cell.RightBorder = line_format
        cell.LeftBorder = line_format
        cell.BottomBorder = line_format
  

Beheko kode-zatiakformatCellBorder funtzioari deitzen dion myMacro makroa inplementatzen du:


    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

Goiko Python kodeak LibreOffice 7.2 bertsiotik erabilgarri dagoen ScriptForge liburutegia darabil.


Marra-estiloak

Marra-estiloak konstante oso gisa definitzen dira. Beheko taulan, Formatua - Gelaxkak - Ertzak atalean erabilgarri dauden marra-estiloetako konstanteak zerrendatzen dira:

Konstante-izena

Balio osoa

Marra-estiloaren izena

SOLID

0

Solidoa

DOTTED

1

Puntukatua

DASHED

2

Marratua

FINE_DASHED

14

Marratu mehea

DOUBLE_THIN

15

Mehe bikoitza

DASH_DOT

16

Marra puntua

DASH_DOT_DOT

17

Marra puntua puntua


tip

Begiratu BorderLineStyle konstantearen erreferentzia LibreOffice APIaren dokumentazioan marra-estiloen konstanteei buruz gehiago jakiteko.


Ertzei formatua ematea TableBorder2 bidez

Barruti-objektuek TableBorder2 izeneko propietate bat dute. Barrutiaren ertzei formatua emateko erabili daiteke propietate hori, Formatua - Gelaxkak - Ertzak elkarrizketa-koadroko Lerro-antolamendua sekzioan egiten den moduan.

Goiko, beheko, ezkerreko eta eskuineko ertzez gain, TableBorder2 propietateak ertz bertikal eta horizontalak ere definitzen ditu. Beheko makroak goiko eta beheko ertzak aplikatzen dizkio "B2:E5" barrutiari.


    Sub TableBorder2Example
        Dim cStyle as Object
        Set cStyle = com.sun.star.table.BorderLineStyle
        ' Lerro berriaren formatua definitzen du
        Dim lineFormat as New com.sun.star.table.BorderLine2
        lineFormat.LineStyle = cStyle.SOLID
        lineFormat.LineWidth = 15
        lineFormat.Color = RGB(0, 0, 0)
        ' TableBorder2 definizio berria biltegiratzen duen struct-a
        Dim tableFormat as New com.sun.star.table.TableBorder2
        tableFormat.TopLine = lineFormat
        tableFormat.BottomLine = lineFormat
        tableFormat.IsTopLineValid = True
        tableFormat.IsBottomLineValid = True
        ' Taula-formatua aplikatzen du "B2:E5" barrutian
        Dim oCell as Object
        oCell = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("B2:E5")
        oCell.TableBorder2 = tableFormat
    End Sub
  

Makroa Python lengoaian inplementatu daiteke honela:


    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

Begiratu TableBorder2 Struct erreferentzia LibreOffice APIaren dokumentazioan bere atributuei buruzko informazio gehiago jasotzeko.


Emaguzu laguntza!