Ask Your Question
0

How do I draw a bottom border line using macro in the header?

asked 2019-02-19 16:22:57 +0200

Craig22 gravatar image

Hello,

I have the intention to me a GUI programming, with which I am comfortable several new page templates can create.

If a page template with the same name exists, it will be deleted from the program. Then a new page template with the same name, created on the basis of the specified properties.

This can be done only partially. My problem is that I am not in the header, nor in the footer can draw a border line.

Using MRI are the correct struct properties are displayed:

REM Borderline Struct
REM Header = BottomBorder
REM Footer = TopBorder
Dim aLine as New com.sun.star.table.BorderLine
    aLine.OuterLineWidth = 35
    aLine.InnerLineWidth=10
    aLine.LineDistance = 10
    aLine.Color=RGB(255,0,0)
mri aLine

Now I tried in a simple way that struct the page template to assign:

oPageStyle.HeaderBottomBorder=aLine

This does not work.

Here is the entire code:

REM  *****  BASIC  *****

REM ╔═══════════════════════════════════════════════════════════════════════╗
REM ║                                                                       ║
REM ║   This macro creates a new page style with the defined properties.    ║
REM ║   If a page style with the same name exists,                          ║
REM ║   then the old style will be deleted                                  ║
REM ║                                                                       ║
REM ╚═══════════════════════════════════════════════════════════════════════╝

Dim oPageStyle as Object

Sub NewLeftPageStyle()
Dim oDoc As Object
'Dim oPageStyle as Object

Dim nCnt as Integer
Dim sStyle as String

oDoc=ThisComponent

REM Example:
REM sStyle= "My_Pagestyle Left Page"
sStyle= InputBox ("Please insert the new PageStyle Name: ","New PageStyle")

REM PageStyle-Objekt
oPageStyle = oDoc.createInstance( "com.sun.star.style.PageStyle" )

'mri oDoc.StyleFamilies.getByName("PageStyles")

REM PageStyle Counter for all existing Pagestyles
nCnt=oDoc.StyleFamilies.getByName("PageStyles").Count

    for i = 0 to nCnt-1
        ' If new PageStyle-Name = old PageStyle-Name, then delete old Pagestyle
        If sStyle=odoc.StyleFamilies.getByName("PageStyles").getByIndex(i).Name then
            ' delete
            odoc.StyleFamilies.getByName("PageStyles").removeByName(sStyle)
                exit for
        End if
    next i

REM Borderline Struct
REM Header = BottomBorder
REM Footer = TopBorder
Dim aLine as New com.sun.star.table.BorderLine
    aLine.OuterLineWidth = 35
    aLine.InnerLineWidth=10
    aLine.LineDistance = 10
    aLine.Color=RGB(255,0,0)

' mri aLine 
' mri oPageSTyle

    REM New PageStyle-Properties
    With oPageStyle
        ' Name
        .Name=sStyle
'       .BorderDistance
'       .BottomBorder=aLine
'       .BottomBorderDistance
        .BottomMargin=1000
        .FooterBodyDistance=1
        .FooterBorderDistance=10
'       .FooterBottomBorder=aLine
        .FooterBottomBorderDistance=12
        .FooterDynamicSpacing=100
        .FooterHeight=100
        .FooterIsDynamicHeight=true
        .FooterIsOn=True
        .FooterIsShared=False
        .FooterLeftMargin=100
        .FooterRightMargin=100
        .FooterTopBorderDistance=10
        .FootnoteHeight=100
        .HeaderIsOn=True
        .HeaderBackColor=RGB(255,0,0)
        .HeaderBodyDistance=100
        .HeaderBorderDistance=150
REM --> don't works 
REM there is no line in Header visible
        .HeaderBottomBorder=aLine
        .HeaderBottomBorderDistance=100
        .HeaderDynamicSpacing=100
        .HeaderHeight=1000
        .HeaderIsDynamicHeight=True
        .HeaderIsShared=False
        .HeaderLeftMargin=100
        .HeaderRightMargin=100
        .Height=21000
        .IsLandscape=False
        .LeftMargin=1000
        .RightMargin=1000
        .TopMargin=1000
        .Width=15000

    End With

    ' Create new PageStyle with the Properties above
    oDoc.StyleFamilies.getByName( "PageStyles" ).insertByName(sStyle,oPageStyle )
End Sub

Which Code statement is correct to draw a thin line under the header.

Cheers

Craig

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2019-03-25 21:41:43 +0200

Craig22 gravatar image

Hello Gord,

Thank you very much for your feedback.

However, your macro does not put a line under a header, but draws a line below a paragraph in the body text.

In the meantime, I have found a solution. It was my fault.

In the code I gave the instruction to delete an existing page style. Thereafter, logically, a new page style must be generated again. This I have missed and that's why the header statements were ignored.

Here is my Testdocument and a description...

Best Regards

Craig

edit flag offensive delete link more
0

answered 2019-03-25 19:17:25 +0200

G o r d gravatar image

I too struggled with this until I finally and got it to work. Here is the key point:

  • Sometimes the 'Record Macro' doesn't work for clicking on toolbar shortcuts and you have to record going through the menus.

Example: What follows is an example to get a thick bottom border

sub BottomLineHeavy

rem ---- This macro was recorded using:
rem -- "Format (Alt+'0'), Cells (Alt+'l'+'Enter'), User-defined (Alt+'u' then use cursor keys
rem -- to navigate and spacebar to select sides - also note that the left side may be
rem -- selected by default - pressing the spacebar three times cycles through your
rem -- choices), Tab to Style (cursor up and down to select) then tab to Width to set
rem -- line thickness."

rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------

dim args1(7) as new com.sun.star.beans.PropertyValue
args1(0).Name = "BorderOuter.LeftBorder"
args1(0).Value = Array(0,0,0,0,0,0)
args1(1).Name = "BorderOuter.LeftDistance"
args1(1).Value = 0
args1(2).Name = "BorderOuter.RightBorder"
args1(2).Value = Array(0,0,0,0,0,0)
args1(3).Name = "BorderOuter.RightDistance"
args1(3).Value = 0
args1(4).Name = "BorderOuter.TopBorder"
args1(4).Value = Array(0,0,0,0,0,0)
args1(5).Name = "BorderOuter.TopDistance"
args1(5).Value = 0
args1(6).Name = "BorderOuter.BottomBorder"
args1(6).Value = Array(0,0,44,0,0,44)
args1(7).Name = "BorderOuter.BottomDistance"
args1(7).Value = 0

dispatcher.executeDispatch(document, ".uno:BorderOuter", "", 0, args1())

end sub
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-02-19 16:22:57 +0200

Seen: 124 times

Last updated: Mar 25