Seaching and replacing in MS Word with regex

Welcome Forums General PowerShell Q&A Seaching and replacing in MS Word with regex

Viewing 1 reply thread
  • Author
    Posts
    • #273957
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      Hi folks,

      I’m new to this forum and to powershell.

      I have a Word document that needs to be transformed with pandoc to an asciidoc document. However, the cross references are not set. The word document somewhat looks like:

      1.2.3.4  Chaptername
      …..
      1.3   Chaptername

      What I would like to do is to find each chapter numbering via regex and replace or add something to make it look like this:

      1.2.3.4  Chaptername [[Chaptername_1.2.3.4]]
      …..
      1.3   Chaptername [[Chaptername_1.3]]

      I was able to get the things correctly, however, I cannot replace it within the existing word document. Here is a code snippet:

      Obviously, the way I run through the document does not allow to use Set-Content and Find.Execute () function does not seem to be appropriate for what I want to do. How can I replace the lines in the document.

      Any hint/help would be appreciated.

      Thanks in advance,
      Wulf

      • This topic was modified 1 month, 3 weeks ago by kvprasoon. Reason: Code formatting
    • #274008
      Senior Moderator
      Topics: 9
      Replies: 1449
      Points: 5,428
      Helping Hand
      Rank: Community MVP

      I never used this module, but you can give PSWriteWord PowerShell module ashot.
      https://evotec.xyz/hub/scripts/pswriteword-powershell-module/

      • This reply was modified 1 month, 3 weeks ago by kvprasoon.
Viewing 1 reply thread
  • You must be logged in to reply to this topic.