Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Word find and replace with bold

by Selvakumar (Scribe)
on Jul 23, 2009 at 10:25 UTC ( [id://782621]=perlquestion: print w/replies, xml ) Need Help??

Selvakumar has asked for the wisdom of the Perl Monks concerning the following question:

I want to find a text in word document and replace the same with bold option. For example find "Sample" but this should search only seperate word not in between like "dfgjsfdSample" etc., and the same word can appear at the front and end of the paragraph also.

Replies are listed 'Best First'.
Re: Word find and replace with bold
by marto (Cardinal) on Jul 23, 2009 at 11:02 UTC
Re: Word find and replace with bold
by davorg (Chancellor) on Jul 23, 2009 at 10:31 UTC

    The \b sequence is used in regular expressions to find the boundary between "word characters" and "non-word characters". That's often useful to mark the beginning and end of a word.

    if (/\b$some_regex\b) { ... }

    But Word documents aren't plain text files. So I don't know how well plain text regexes will work.

    --

    See the Copyright notice on my home node.

    Perl training courses

      This is my below code and i need to apply the word boundary in find statement or any other method to search the text with regular expressions.
      use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $word = Win32::OLE->new('Word.Application'); $word->{Visible} = 1; my $document=$word->Documents->Open('c\ch01.doc'); $word->Selection->HomeKey(wdStory); $word->Selection->Find->{'Text'}=$text; $word->Selection->Find->Replacement->{'Text'}=$text; $word->Selection->Find->Replacement->Font->{'Bold'}=1; $word->Selection->Find->Execute({Replace=>wdReplaceAll}); } $word-> ActiveDocument->SaveAs('c:\ch01_updated.doc'); $document-> Close(); $word-> Quit();

        Your program contains syntax errors and can't run in the state you posted it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://782621]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-24 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found