Hi All
I am trying to add paragraphs in between of the MS word document, have used search and replace method(means if a string is found then add paragraphs in place of that sring)
Below is the working copy of my code. Code is able to find the text on MS word document and then replace with the data to be inserted. But as the data to be inserted increases (means add 27.1.8 ERR_u8GetAllBothDtcCount1 one more line to data to be inserted) it doesnt add data to the MS word documentand replace string with '1'.
If I add the same data irrespective of its length at end or starting of the MS word document it adds correctly but in between of the document it is not able to add correctly.
Not able to know what problem is there. Please guide me.
use strict;
use Win32::OLE;
use Win32::OLE::Enum;
use Win32::OLE qw(in);
use Win32::OLE::Const 'Microsoft Word';
my $docfile = "D:/Perl_programs/error_notification.docx";
my $Word = Win32::OLE->GetActiveObject('Word.Application');
unless ($Word) { $Word = Win32::OLE->new('Word.Application', sub {$_[0]->Quit;}) or die "oops\n"; }
$Word->{visible} = 1;
my $File = $Word->Documents->Open($docfile);
my $data_to_be_inserted = '27.1.1 ERR_bDisableModeDetecting
27.1.2 ERR_bIsErrorActive
27.1.3 ERR_ClearAllErrorCodes
27.1.4 ERR_ClearPublicErrorCodes
27.1.5 ERR_InitializeRAMBuffer
27.1.6 ERR_ManageEepromWriting
27.1.7 ERR_u8GetAllBothDtcCount
';
my $search = $File-> Content->Find;
my $replace = $search-> Replacement;
my $oldtext = "Insert component document link “Modl_Str_Diagram[File]” from the GAIO’s index.docx file. Ignore if not available";
my $newtext = $data_to_be_inserted;
$search-> {Text} = $oldtext;
$replace-> {Text} = $newtext;
$search-> Execute({Replace => wdReplaceAll});
Thanks
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.