Highlight Words

Home Forums Open-Xml-PowerTools Highlight Words

This topic contains 3 replies, has 4 voices, and was last updated by  Myname 4 years, 11 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #5356

    qu1ckdry
    Participant

    I’m using OpenXml and OpenXmlPowerTools to try and highlight words in a word file. I can find them ok but I can for the life of me work out how to highlight the text once I’ve found it!

    Here’s my code:

    
    Public Sub Highlight()
        Dim docFilePath As String = "test.docx"
    
        Using wDoc As WordprocessingDocument = WordprocessingDocument.Open(docFilePath, True)
            Dim xDoc As XDocument = wDoc.MainDocumentPart.GetXDocument()
    
            Dim count As Integer = OpenXmlRegex.Match(xDoc.Descendants(W.p), New Regex("Test"),
                                                      Function(element, match)
                                                          Dim runProperties As RunProperties = New RunProperties(New Highlight() With {.Val = HighlightColorValues.Yellow})
                                                          'Dim r As Run = element '<-- I need to to something else here as this obviously fails
                                                          r.PrependChild(Of RunProperties)(runProperties)
                                                          Return True
                                                      End Function)
            wDoc.MainDocumentPart.PutXDocument()
        End Using
        Process.Start(docFilePath)
    End Sub
    

    So my question is how do I apply run properties to an XElement? Or alternatively is there a better approach?

    Thanks for any help!

    #7035

    BrettSmith
    Participant

    Thanks mate for sharing this. I inserted this block of code in my site EssayWritingLibrary and got perfect results.

    #7150

    russellrexroad321
    Participant

    I’m utilizing C# and the OpenXml DLL to change a current MS Word report. … I’m effectively ready to supplant a few labels in the report and afterward spare the adjustment, however, I’m not yet ready to erase a bit of content. …. Interop.Word) to Online Essay Help Uk side, yet every time I endeavor to open in customer side utilizing IE9, it says that it can’t open it.

    #7892

    Myname
    Participant

    Hey, guys! you need to check this blog first!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.