[Libreoffice-ux-advise] [Bug 151889] CLEAR FORMATTING: Give option to clear every formatting in a single step

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Wed Nov 16 14:25:47 UTC 2022


https://bugs.documentfoundation.org/show_bug.cgi?id=151889

--- Comment #16 from Rafael Lima <rafael.palma.lima at gmail.com> ---
Hi Orwell, can you please test if this macro does what you need?

Sub ClearEverything
    ' Get the current selection
    Dim oSel as Object
    oSel = ThisComponent.CurrentSelection

    ' Dispatch helper to use the CDF command
    Dim oProvider as Object
    Dim oDispHelper as Object
    oProvider = ThisComponent.CurrentController.Frame
    oDispHelper = CreateUnoService("com.sun.star.frame.DispatchHelper")

    ' First of all apply the CDF command to the entire selection
    oDispHelper.executeDispatch(oProvider, ".uno:ResetAttributes", "", ,
Array())

    ' Traverse all text ranges
    Dim rangeCount as Integer, i as Integer
    Dim oEnum as object, oElement as Object
    rangeCount = oSel.getCount()
    For i = 0 To rangeCount - 1
        ' Traverse all text elements
        oTextRange = oSel.getByIndex(i)
        oEnum = oTextRange.createEnumeration()
        Do While oEnum.hasMoreElements()
            oElement = oEnum.nextElement()
            With oElement
                ' Clear paragraph style
                .ParaStyleName = "Default Paragraph Style"
                ' Cleat character style
                .CharFontStyleName = ""
                .CharFontStyleNameAsian = ""
                .CharFontStyleNameComplex = ""
                .CharStyleName = "No Character Style"
                ' Clear list format
                .ListId = ""
                .NumberingIsNumber = False
                .NumberingStyleName = ""
            End With
        Loop
    Next i
End Sub

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Libreoffice-ux-advise mailing list